Debian Codegraph @

lib/Filter.h

raw symbols SCIP
1 /*
2 Copyright 2007-2008 by Robert Knight <[email protected]>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
18 */
19
20 #ifndef FILTER_H
21 #define FILTER_Hcxx . . $ `lib/Filter.h:21:9`!
22
23 // Qt
24 #include <QAction>
25 #include <QList>
26 #include <QObject>
27 #include <QStringList>
28 #include <QHash>
29 #include <QRegExp>
30
31 namespace Konsolecxx . . $ Konsole/
32 {
33
34 typedef unsigned char LinePropertycxx . . $ Konsole/LineProperty#;
35 class Charactercxx . . $ Konsole/Character#;
36
37 /**
38 * A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list)
39 * and marks the areas which match the filter's patterns as 'hotspots'.
40 *
41 * Each hotspot has a type identifier associated with it ( such as a link or a highlighted section ),
42 * and an action. When the user performs some activity such as a mouse-click in a hotspot area ( the exact
43 * action will depend on what is displaying the block of text which the filter is processing ), the hotspot's
44 * activate() method should be called. Depending on the type of hotspot this will trigger a suitable response.
45 *
46 * For example, if a hotspot represents a URL then a suitable action would be opening that URL in a web browser.
47 * Hotspots may have more than one action, in which case the list of actions can be obtained using the
48 * actions() method.
49 *
50 * Different subclasses of filter will return different types of hotspot.
51 * Subclasses must reimplement the process() method to examine a block of text and identify sections of interest.
52 * When processing the text they should create instances of Filter::HotSpot subclasses for sections of interest
53 * and add them to the filter's list of hotspots using addHotSpot()
54 */
55 class Filtercxx . . $ Konsole/Filter# : public QObjectcxx . . $ QObject#
56 {
57 public:
58 /**
59 * Represents an area of text which matched the pattern a particular filter has been looking for.
60 *
61 * Each hotspot has a type identifier associated with it ( such as a link or a highlighted section ),
62 * and an action. When the user performs some activity such as a mouse-click in a hotspot area ( the exact
63 * action will depend on what is displaying the block of text which the filter is processing ), the hotspot's
64 * activate() method should be called. Depending on the type of hotspot this will trigger a suitable response.
65 *
66 * For example, if a hotspot represents a URL then a suitable action would be opening that URL in a web browser.
67 * Hotspots may have more than one action, in which case the list of actions can be obtained using the
68 * actions() method. These actions may then be displayed in a popup menu or toolbar for example.
69 */
70 class HotSpotcxx . . $ Konsole/Filter#HotSpot#
71 {
72 public:
73 /**
74 * Constructs a new hotspot which covers the area from (@p startLine,@p startColumn) to (@p endLine,@p endColumn)
75 * in a block of text.
76 */
77 HotSpotcxx . . $ Konsole/Filter#HotSpot#HotSpot(748afa4755bc9595).(int startLine , int startColumn , int endLine , int endColumn);
78 virtual ~cxx . . $ Konsole/Filter#HotSpot#`~HotSpot`(ced63f7c635d850d).HotSpotcxx . . $ Konsole/Filter#HotSpot#();
79
80 enum Typecxx . . $ Konsole/Filter#HotSpot#Type#
81 {
82 // the type of the hotspot is not specified
83 NotSpecifiedcxx . . $ Konsole/Filter#HotSpot#NotSpecified.,
84 // this hotspot represents a clickable link
85 Linkcxx . . $ Konsole/Filter#HotSpot#Link.,
86 // this hotspot represents a marker
87 Markercxx . . $ Konsole/Filter#HotSpot#Marker.
88 };
89
90 /** Returns the line when the hotspot area starts */
91 int startLinecxx . . $ Konsole/Filter#HotSpot#startLine(455f465bc33b4cdf).() const;
92 /** Returns the line where the hotspot area ends */
93 int endLinecxx . . $ Konsole/Filter#HotSpot#endLine(455f465bc33b4cdf).() const;
94 /** Returns the column on startLine() where the hotspot area starts */
95 int startColumncxx . . $ Konsole/Filter#HotSpot#startColumn(455f465bc33b4cdf).() const;
96 /** Returns the column on endLine() where the hotspot area ends */
97 int endColumncxx . . $ Konsole/Filter#HotSpot#endColumn(455f465bc33b4cdf).() const;
98 /**
99 * Returns the type of the hotspot. This is usually used as a hint for views on how to represent
100 * the hotspot graphically. eg. Link hotspots are typically underlined when the user mouses over them
101 */
102 Typecxx . . $ Konsole/Filter#HotSpot#Type# typecxx . . $ Konsole/Filter#HotSpot#type(d53492adece367cf).() const;
103 /**
104 * Causes the an action associated with a hotspot to be triggered.
105 *
106 * @param action The action to trigger. This is
107 * typically empty ( in which case the default action should be performed ) or
108 * one of the object names from the actions() list. In which case the associated
109 * action should be performed.
110 */
111 virtual void activatecxx . . $ Konsole/Filter#HotSpot#activate(3520e46b33348bf6).(const QStringcxx . . $ QString#& action = QStringcxx . . $ QString#QString(ced63f7c635d850d).()) = 0;
112 /**
113 * Returns a list of actions associated with the hotspot which can be used in a
114 * menu or toolbar
115 */
116 virtual QListcxx . . $ QList#<QActioncxx . . $ QAction#*> actionscxx . . $ Konsole/Filter#HotSpot#actions(c4b3bc0793dee689).();
117
118 protected:
119 /** Sets the type of a hotspot. This should only be set once */
120 void setTypecxx . . $ Konsole/Filter#HotSpot#setType(8b418483fa682651).(Typecxx . . $ Konsole/Filter#HotSpot#Type# type);
121
122 private:
123 int _startLinecxx . . $ Konsole/Filter#HotSpot#_startLine.;
124 int _startColumncxx . . $ Konsole/Filter#HotSpot#_startColumn.;
125 int _endLinecxx . . $ Konsole/Filter#HotSpot#_endLine.;
126 int _endColumncxx . . $ Konsole/Filter#HotSpot#_endColumn.;
127 Typecxx . . $ Konsole/Filter#HotSpot#Type# _typecxx . . $ Konsole/Filter#HotSpot#_type.;
128
129 };
130
131 /** Constructs a new filter. */
132 Filtercxx . . $ Konsole/Filter#Filter(49f6e7a06ebc5aa8).();
133 ~cxx . . $ Konsole/Filter#`~Filter`(ced63f7c635d850d).Filtercxx . . $ Konsole/Filter#() override;
134
135 /** Causes the filter to process the block of text currently in its internal buffer */
136 virtual void processcxx . . $ Konsole/Filter#process(49f6e7a06ebc5aa8).() = 0;
137
138 /**
139 * Empties the filters internal buffer and resets the line count back to 0.
140 * All hotspots are deleted.
141 */
142 void resetcxx . . $ Konsole/Filter#reset(49f6e7a06ebc5aa8).();
143
144 /** Adds a new line of text to the filter and increments the line count */
145 //void addLine(const QString& string);
146
147 /** Returns the hotspot which covers the given @p line and @p column, or 0 if no hotspot covers that area */
148 HotSpotcxx . . $ Konsole/Filter#HotSpot#* hotSpotAtcxx . . $ Konsole/Filter#hotSpotAt(a340944fd47eb4c3).(int line , int column) const;
149
150 /** Returns the list of hotspots identified by the filter */
151 QListcxx . . $ QList#<HotSpotcxx . . $ Konsole/Filter#HotSpot#*> hotSpotscxx . . $ Konsole/Filter#hotSpots(927ee1eeecce351e).() const;
152
153 /** Returns the list of hotspots identified by the filter which occur on a given line */
154 QListcxx . . $ QList#<HotSpotcxx . . $ Konsole/Filter#HotSpot#*> hotSpotsAtLinecxx . . $ Konsole/Filter#hotSpotsAtLine(92574a9f3890659d).(int line) const;
155
156 /**
157 * TODO: Document me
158 */
159 void setBuffercxx . . $ Konsole/Filter#setBuffer(ab9b33b00d7218ba).(const QStringcxx . . $ QString#* buffer , const QListcxx . . $ QList#<int>* linePositions);
160
161 protected:
162 /** Adds a new hotspot to the list */
163 void addHotSpotcxx . . $ Konsole/Filter#addHotSpot(35f9ac5aa6207bb5).(HotSpotcxx . . $ Konsole/Filter#HotSpot#*);
164 /** Returns the internal buffer */
165 const QStringcxx . . $ QString#* buffercxx . . $ Konsole/Filter#buffer(efb0f8380b491c12).();
166 /** Converts a character position within buffer() to a line and column */
167 void getLineColumncxx . . $ Konsole/Filter#getLineColumn(4b55c833e9dbf0bc).(int position , int& startLine , int& startColumn);
168
169 private:
170 QMultiHashcxx . . $ QMultiHash#<int,HotSpotcxx . . $ Konsole/Filter#HotSpot#*> _hotspotscxx . . $ Konsole/Filter#_hotspots.;
171 QListcxx . . $ QList#<HotSpotcxx . . $ Konsole/Filter#HotSpot#*> _hotspotListcxx . . $ Konsole/Filter#_hotspotList.;
172
173 const QListcxx . . $ QList#<int>* _linePositionscxx . . $ Konsole/Filter#_linePositions.;
174 const QStringcxx . . $ QString#* _buffercxx . . $ Konsole/Filter#_buffer.;
175 };
176
177 /**
178 * A filter which searches for sections of text matching a regular expression and creates a new RegExpFilter::HotSpot
179 * instance for them.
180 *
181 * Subclasses can reimplement newHotSpot() to return custom hotspot types when matches for the regular expression
182 * are found.
183 */
184 class RegExpFiltercxx . . $ Konsole/RegExpFilter# : public Filtercxx . . $ Konsole/Filter#
185 {
186 public:
187 /**
188 * Type of hotspot created by RegExpFilter. The capturedTexts() method can be used to find the text
189 * matched by the filter's regular expression.
190 */
191 class HotSpotcxx . . $ Konsole/RegExpFilter#HotSpot# : public Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#
192 {
193 public:
194 HotSpotcxx . . $ Konsole/RegExpFilter#HotSpot#HotSpot(748afa4755bc9595).(int startLine, int startColumn, int endLine , int endColumn);
195 void activatecxx . . $ Konsole/RegExpFilter#HotSpot#activate(3520e46b33348bf6).(const QStringcxx . . $ QString#& action = QStringcxx . . $ QString#QString(ced63f7c635d850d).()) override;
196
197 /** Sets the captured texts associated with this hotspot */
198 void setCapturedTextscxx . . $ Konsole/RegExpFilter#HotSpot#setCapturedTexts(631c0101495f0328).(const QStringListcxx . . $ QStringList#& texts);
199 /** Returns the texts found by the filter when matching the filter's regular expression */
200 QStringListcxx . . $ QStringList# capturedTextscxx . . $ Konsole/RegExpFilter#HotSpot#capturedTexts(e1dbd5c4feadc8f5).() const;
201 private:
202 QStringListcxx . . $ QStringList# _capturedTextscxx . . $ Konsole/RegExpFilter#HotSpot#_capturedTexts.;
203 };
204
205 /** Constructs a new regular expression filter */
206 RegExpFiltercxx . . $ Konsole/RegExpFilter#RegExpFilter(49f6e7a06ebc5aa8).();
207
208 /**
209 * Sets the regular expression which the filter searches for in blocks of text.
210 *
211 * Regular expressions which match the empty string are treated as not matching
212 * anything.
213 */
214 void setRegExpcxx . . $ Konsole/RegExpFilter#setRegExp(ff80efdedf7b2ca0).(const QRegExpcxx . . $ QRegExp#& text);
215 /** Returns the regular expression which the filter searches for in blocks of text */
216 QRegExpcxx . . $ QRegExp# regExpcxx . . $ Konsole/RegExpFilter#regExp(f0d4f2c2a59d2909).() const;
217
218 /**
219 * Reimplemented to search the filter's text buffer for text matching regExp()
220 *
221 * If regexp matches the empty string, then process() will return immediately
222 * without finding results.
223 */
224 void processcxx . . $ Konsole/RegExpFilter#process(49f6e7a06ebc5aa8).() override;
225
226 protected:
227 /**
228 * Called when a match for the regular expression is encountered. Subclasses should reimplement this
229 * to return custom hotspot types
230 */
231 virtual RegExpFiltercxx . . $ Konsole/RegExpFilter#::HotSpotcxx . . $ Konsole/RegExpFilter#HotSpot#* newHotSpotcxx . . $ Konsole/RegExpFilter#newHotSpot(2cdf0c2b9256cc1f).(int startLine,int startColumn,
232 int endLine,int endColumn);
233
234 private:
235 QRegExpcxx . . $ QRegExp# _searchTextcxx . . $ Konsole/RegExpFilter#_searchText.;
236 };
237
238 class FilterObjectcxx . . $ Konsole/FilterObject#;
239
240 /** A filter which matches URLs in blocks of text */
241 class UrlFiltercxx . . $ Konsole/UrlFilter# : public RegExpFiltercxx . . $ Konsole/RegExpFilter#
242 {
243 Q_OBJECTcxx . . $ Konsole/UrlFilter#trUtf8(75d9f1c324b4579d).
244 public:
245 /**
246 * Hotspot type created by UrlFilter instances. The activate() method opens a web browser
247 * at the given URL when called.
248 */
249 class HotSpotcxx . . $ Konsole/UrlFilter#HotSpot# : public RegExpFiltercxx . . $ Konsole/RegExpFilter#::HotSpotcxx . . $ Konsole/RegExpFilter#HotSpot#
250 {
251 public:
252 HotSpotcxx . . $ Konsole/UrlFilter#HotSpot#HotSpot(748afa4755bc9595).(int startLine,int startColumn,int endLine,int endColumn);
253 ~cxx . . $ Konsole/UrlFilter#HotSpot#`~HotSpot`(ced63f7c635d850d).HotSpotcxx . . $ Konsole/UrlFilter#HotSpot#() override;
254
255 FilterObjectcxx . . $ Konsole/FilterObject#* getUrlObjectcxx . . $ Konsole/UrlFilter#HotSpot#getUrlObject(c884d601a81ad382).() const;
256
257 QListcxx . . $ QList#<QActioncxx . . $ QAction#*> actionscxx . . $ Konsole/UrlFilter#HotSpot#actions(c4b3bc0793dee689).() override;
258
259 /**
260 * Open a web browser at the current URL. The url itself can be determined using
261 * the capturedTexts() method.
262 */
263 void activatecxx . . $ Konsole/UrlFilter#HotSpot#activate(3520e46b33348bf6).(const QStringcxx . . $ QString#& action = QStringcxx . . $ QString#QString(ced63f7c635d850d).()) override;
264
265 private:
266 enum UrlTypecxx . . $ Konsole/UrlFilter#HotSpot#UrlType#
267 {
268 StandardUrlcxx . . $ Konsole/UrlFilter#HotSpot#StandardUrl.,
269 Emailcxx . . $ Konsole/UrlFilter#HotSpot#Email.,
270 Unknowncxx . . $ Konsole/UrlFilter#HotSpot#Unknown.
271 };
272 UrlTypecxx . . $ Konsole/UrlFilter#HotSpot#UrlType# urlTypecxx . . $ Konsole/UrlFilter#HotSpot#urlType(a7c2e5f86cfd3bf1).() const;
273
274 FilterObjectcxx . . $ Konsole/FilterObject#* _urlObjectcxx . . $ Konsole/UrlFilter#HotSpot#_urlObject.;
275 };
276
277 UrlFiltercxx . . $ Konsole/UrlFilter#UrlFilter(49f6e7a06ebc5aa8).();
278
279 protected:
280 RegExpFiltercxx . . $ Konsole/RegExpFilter#::HotSpotcxx . . $ Konsole/RegExpFilter#HotSpot#* newHotSpotcxx . . $ Konsole/UrlFilter#newHotSpot(2cdf0c2b9256cc1f).(int,int,int,int) override;
281
282 private:
283
284 static const QRegExpcxx . . $ QRegExp# FullUrlRegExpcxx . . $ Konsole/UrlFilter#FullUrlRegExp.;
285 static const QRegExpcxx . . $ QRegExp# EmailAddressRegExpcxx . . $ Konsole/UrlFilter#EmailAddressRegExp.;
286
287 // combined OR of FullUrlRegExp and EmailAddressRegExp
288 static const QRegExpcxx . . $ QRegExp# CompleteUrlRegExpcxx . . $ Konsole/UrlFilter#CompleteUrlRegExp.;
289 signalscxx . . $ `<external>/1208926524888476972/qobjectdefs.h:89:14`!:
290 void activatedcxx . . $ Konsole/UrlFilter#activated(61e5b15e0cd21ddb).(const QUrlcxx . . $ QUrl#& url, bool fromContextMenu);
291 };
292
293 class FilterObjectcxx . . $ Konsole/FilterObject# : public QObjectcxx . . $ QObject#
294 {
295 Q_OBJECTcxx . . $ QMetaObject#Call#
296 public:
297 FilterObjectcxx . . $ Konsole/FilterObject#FilterObject(35f9ac5aa6207bb5).(Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#* filter) : _filtercxx . . $ Konsole/FilterObject#_filter.(filter) {}
298
299 void emitActivatedcxx . . $ Konsole/FilterObject#emitActivated(61e5b15e0cd21ddb).(const QUrlcxx . . $ QUrl#& url, bool fromContextMenu);
300 public slotscxx . . $ `<external>/1208926524888476972/qobjectdefs.h:88:14`!:
301 void activatecxx . . $ Konsole/FilterObject#activate(49f6e7a06ebc5aa8).();
302 private:
303 Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#* _filtercxx . . $ Konsole/FilterObject#_filter.;
304 signalscxx . . $ `<external>/1208926524888476972/qobjectdefs.h:89:14`!:
305 void activatedcxx . . $ Konsole/FilterObject#activated(61e5b15e0cd21ddb).(const QUrlcxx . . $ QUrl#& url, bool fromContextMenu);
306 };
307
308 /**
309 * A chain which allows a group of filters to be processed as one.
310 * The chain owns the filters added to it and deletes them when the chain itself is destroyed.
311 *
312 * Use addFilter() to add a new filter to the chain.
313 * When new text to be filtered arrives, use addLine() to add each additional
314 * line of text which needs to be processed and then after adding the last line, use
315 * process() to cause each filter in the chain to process the text.
316 *
317 * After processing a block of text, the reset() method can be used to set the filter chain's
318 * internal cursor back to the first line.
319 *
320 * The hotSpotAt() method will return the first hotspot which covers a given position.
321 *
322 * The hotSpots() and hotSpotsAtLine() method return all of the hotspots in the text and on
323 * a given line respectively.
324 */
325 class FilterChaincxx . . $ Konsole/FilterChain# : protected QListcxx . . $ QList#<Filtercxx . . $ Konsole/Filter#*>
326 {
327 public:
328 virtual ~cxx . . $ Konsole/FilterChain#`~FilterChain`(ced63f7c635d850d).FilterChaincxx . . $ Konsole/FilterChain#();
329
330 /** Adds a new filter to the chain. The chain will delete this filter when it is destroyed */
331 void addFiltercxx . . $ Konsole/FilterChain#addFilter(12cefbd1512c714c).(Filtercxx . . $ Konsole/Filter#* filter);
332 /** Removes a filter from the chain. The chain will no longer delete the filter when destroyed */
333 void removeFiltercxx . . $ Konsole/FilterChain#removeFilter(12cefbd1512c714c).(Filtercxx . . $ Konsole/Filter#* filter);
334 /** Returns true if the chain contains @p filter */
335 bool containsFiltercxx . . $ Konsole/FilterChain#containsFilter(af69c5efc6225ee1).(Filtercxx . . $ Konsole/Filter#* filter);
336 /** Removes all filters from the chain */
337 void clearcxx . . $ Konsole/FilterChain#clear(49f6e7a06ebc5aa8).();
338
339 /** Resets each filter in the chain */
340 void resetcxx . . $ Konsole/FilterChain#reset(49f6e7a06ebc5aa8).();
341 /**
342 * Processes each filter in the chain
343 */
344 void processcxx . . $ Konsole/FilterChain#process(49f6e7a06ebc5aa8).();
345
346 /** Sets the buffer for each filter in the chain to process. */
347 void setBuffercxx . . $ Konsole/FilterChain#setBuffer(ab9b33b00d7218ba).(const QStringcxx . . $ QString#* buffer , const QListcxx . . $ QList#<int>* linePositions);
348
349 /** Returns the first hotspot which occurs at @p line, @p column or 0 if no hotspot was found */
350 Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#* hotSpotAtcxx . . $ Konsole/FilterChain#hotSpotAt(a340944fd47eb4c3).(int line , int column) const;
351 /** Returns a list of all the hotspots in all the chain's filters */
352 QListcxx . . $ QList#<Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#*> hotSpotscxx . . $ Konsole/FilterChain#hotSpots(927ee1eeecce351e).() const;
353 /** Returns a list of all hotspots at the given line in all the chain's filters */
354 QListcxx . . $ QList#<Filtercxx . . $ Konsole/Filter#::HotSpotcxx . . $ Konsole/Filter#HotSpot#> hotSpotsAtLinecxx . . $ Konsole/FilterChain#hotSpotsAtLine(fd69582068290985).(int line) const;
355
356 };
357
358 /** A filter chain which processes character images from terminal displays */
359 class TerminalImageFilterChaincxx . . $ Konsole/TerminalImageFilterChain# : public FilterChaincxx . . $ Konsole/FilterChain#
360 {
361 public:
362 TerminalImageFilterChaincxx . . $ Konsole/TerminalImageFilterChain#TerminalImageFilterChain(49f6e7a06ebc5aa8).();
363 ~cxx . . $ Konsole/TerminalImageFilterChain#`~TerminalImageFilterChain`(ced63f7c635d850d).TerminalImageFilterChaincxx . . $ Konsole/TerminalImageFilterChain#() override;
364
365 /**
366 * Set the current terminal image to @p image.
367 *
368 * @param image The terminal image
369 * @param lines The number of lines in the terminal image
370 * @param columns The number of columns in the terminal image
371 * @param lineProperties The line properties to set for image
372 */
373 void setImagecxx . . $ Konsole/TerminalImageFilterChain#setImage(ebf247e562f15df0).(const Charactercxx . . $ Konsole/Character#* const image , int lines , int columns,
374 const QVectorcxx . . $ QVector#<LinePropertycxx . . $ Konsole/LineProperty#>& lineProperties);
375
376 private:
377 QStringcxx . . $ QString#* _buffercxx . . $ Konsole/TerminalImageFilterChain#_buffer.;
378 QListcxx . . $ QList#<int>* _linePositionscxx . . $ Konsole/TerminalImageFilterChain#_linePositions.;
379 };
380
381 }
382
383 typedef Konsolecxx . . $ Konsole/::Filtercxx . . $ Konsole/Filter# Filtercxx . . $ Filter#;
384
385 #endif //FILTER_H