• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
Filter.h
Go to the documentation of this file.
1 /*
2  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
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_H
22 
23 // Qt
24 #include <QtCore/QList>
25 #include <QtCore/QObject>
26 #include <QtCore/QStringList>
27 #include <QtCore/QRegExp>
28 #include <QtCore/QMultiHash>
29 
30 // Konsole
31 #include "Character.h"
32 
33 class QAction;
34 
35 namespace Konsole
36 {
55 class Filter
56 {
57 public:
70  class HotSpot
71  {
72  public:
77  HotSpot(int startLine , int startColumn , int endLine , int endColumn);
78  virtual ~HotSpot();
79 
80  enum Type {
81  // the type of the hotspot is not specified
82  NotSpecified,
83  // this hotspot represents a clickable link
84  Link,
85  // this hotspot represents a marker
86  Marker
87  };
88 
90  int startLine() const;
92  int endLine() const;
94  int startColumn() const;
96  int endColumn() const;
101  Type type() const;
110  virtual void activate(QObject* object = 0) = 0;
115  virtual QList<QAction*> actions();
116 
117  protected:
119  void setType(Type type);
120 
121  private:
122  int _startLine;
123  int _startColumn;
124  int _endLine;
125  int _endColumn;
126  Type _type;
127  };
128 
130  Filter();
131  virtual ~Filter();
132 
134  virtual void process() = 0;
135 
140  void reset();
141 
143  //void addLine(const QString& string);
144 
146  HotSpot* hotSpotAt(int line , int column) const;
147 
149  QList<HotSpot*> hotSpots() const;
150 
152  QList<HotSpot*> hotSpotsAtLine(int line) const;
153 
157  void setBuffer(const QString* buffer , const QList<int>* linePositions);
158 
159 protected:
161  void addHotSpot(HotSpot*);
163  const QString* buffer();
165  void getLineColumn(int position , int& startLine , int& startColumn);
166 
167 private:
168  QMultiHash<int, HotSpot*> _hotspots;
169  QList<HotSpot*> _hotspotList;
170 
171  const QList<int>* _linePositions;
172  const QString* _buffer;
173 };
174 
182 class RegExpFilter : public Filter
183 {
184 public:
189  class HotSpot : public Filter::HotSpot
190  {
191  public:
192  HotSpot(int startLine, int startColumn, int endLine , int endColumn);
193  virtual void activate(QObject* object = 0);
194 
196  void setCapturedTexts(const QStringList& texts);
198  QStringList capturedTexts() const;
199  private:
200  QStringList _capturedTexts;
201  };
202 
204  RegExpFilter();
205 
212  void setRegExp(const QRegExp& text);
214  QRegExp regExp() const;
215 
222  virtual void process();
223 
224 protected:
229  virtual RegExpFilter::HotSpot* newHotSpot(int startLine, int startColumn,
230  int endLine, int endColumn);
231 
232 private:
233  QRegExp _searchText;
234 };
235 
236 class FilterObject;
237 
239 class UrlFilter : public RegExpFilter
240 {
241 public:
246  class HotSpot : public RegExpFilter::HotSpot
247  {
248  public:
249  HotSpot(int startLine, int startColumn, int endLine, int endColumn);
250  virtual ~HotSpot();
251 
252  virtual QList<QAction*> actions();
253 
258  virtual void activate(QObject* object = 0);
259 
260  private:
261  enum UrlType {
262  StandardUrl,
263  Email,
264  Unknown
265  };
266  UrlType urlType() const;
267 
268  FilterObject* _urlObject;
269  };
270 
271  UrlFilter();
272 
273 protected:
274  virtual RegExpFilter::HotSpot* newHotSpot(int, int, int, int);
275 
276 private:
277  static const QRegExp FullUrlRegExp;
278  static const QRegExp EmailAddressRegExp;
279 
280  // combined OR of FullUrlRegExp and EmailAddressRegExp
281  static const QRegExp CompleteUrlRegExp;
282 };
283 
284 class FilterObject : public QObject
285 {
286  Q_OBJECT
287 public:
288  explicit FilterObject(Filter::HotSpot* filter) : _filter(filter) {}
289 private slots:
290  void activated();
291 private:
292  Filter::HotSpot* _filter;
293 };
294 
312 class FilterChain : protected QList<Filter*>
313 {
314 public:
315  virtual ~FilterChain();
316 
318  void addFilter(Filter* filter);
320  void removeFilter(Filter* filter);
322  void clear();
323 
325  void reset();
329  void process();
330 
332  void setBuffer(const QString* buffer , const QList<int>* linePositions);
333 
335  Filter::HotSpot* hotSpotAt(int line , int column) const;
337  QList<Filter::HotSpot*> hotSpots() const;
339  QList<Filter::HotSpot> hotSpotsAtLine(int line) const;
340 };
341 
343 class TerminalImageFilterChain : public FilterChain
344 {
345 public:
346  TerminalImageFilterChain();
347  virtual ~TerminalImageFilterChain();
348 
357  void setImage(const Character* const image , int lines , int columns,
358  const QVector<LineProperty>& lineProperties);
359 
360 private:
361  QString* _buffer;
362  QList<int>* _linePositions;
363 };
364 }
365 #endif //FILTER_H
Konsole::FilterChain::hotSpotsAtLine
QList< Filter::HotSpot > hotSpotsAtLine(int line) const
Returns a list of all hotspots at the given line in all the chain's filters.
Konsole::Filter::hotSpotAt
HotSpot * hotSpotAt(int line, int column) const
Adds a new line of text to the filter and increments the line count.
Definition: Filter.cpp:240
Konsole::FilterChain::~FilterChain
virtual ~FilterChain()
Definition: Filter.cpp:40
Konsole::Filter::HotSpot::activate
virtual void activate(QObject *object=0)=0
Causes the action associated with a hotspot to be triggered.
Konsole::Filter::HotSpot::Type
Type
Definition: Filter.h:80
Konsole::FilterChain::reset
void reset()
Resets each filter in the chain.
Definition: Filter.cpp:59
Konsole::Filter::HotSpot
Represents an area of text which matched the pattern a particular filter has been looking for...
Definition: Filter.h:70
Konsole::FilterChain::hotSpotAt
Filter::HotSpot * hotSpotAt(int line, int column) const
Returns the first hotspot which occurs at line, column or 0 if no hotspot was found.
Definition: Filter.cpp:81
Konsole::Filter::addHotSpot
void addHotSpot(HotSpot *)
Adds a new hotspot to the list.
Definition: Filter.cpp:223
Konsole::UrlFilter::newHotSpot
virtual RegExpFilter::HotSpot * newHotSpot(int, int, int, int)
Called when a match for the regular expression is encountered.
Definition: Filter.cpp:373
Konsole::RegExpFilter::HotSpot::setCapturedTexts
void setCapturedTexts(const QStringList &texts)
Sets the captured texts associated with this hotspot.
Definition: Filter.cpp:307
Konsole::UrlFilter::UrlFilter
UrlFilter()
Definition: Filter.cpp:443
Konsole::FilterChain::removeFilter
void removeFilter(Filter *filter)
Removes a filter from the chain.
Definition: Filter.cpp:55
Konsole::Filter::Filter
Filter()
Constructs a new filter.
Definition: Filter.cpp:164
Konsole::FilterObject::FilterObject
FilterObject(Filter::HotSpot *filter)
Definition: Filter.h:288
Konsole::Filter::getLineColumn
void getLineColumn(int position, int &startLine, int &startColumn)
Converts a character position within buffer() to a line and column.
Definition: Filter.cpp:189
Konsole::Filter::HotSpot::setType
void setType(Type type)
Sets the type of a hotspot.
Definition: Filter.cpp:288
Konsole::Filter::HotSpot::startLine
int startLine() const
Returns the line when the hotspot area starts.
Definition: Filter.cpp:268
Konsole::Filter::~Filter
virtual ~Filter()
Definition: Filter.cpp:170
Konsole::RegExpFilter::HotSpot::activate
virtual void activate(QObject *object=0)
Causes the action associated with a hotspot to be triggered.
Definition: Filter.cpp:303
Konsole::Filter::HotSpot::endLine
int endLine() const
Returns the line where the hotspot area ends.
Definition: Filter.cpp:272
Konsole::Filter::buffer
const QString * buffer()
Returns the internal buffer.
Definition: Filter.cpp:216
Konsole::TerminalImageFilterChain::~TerminalImageFilterChain
virtual ~TerminalImageFilterChain()
Definition: Filter.cpp:112
Konsole::Character
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:77
QRegExp
Konsole::RegExpFilter::newHotSpot
virtual RegExpFilter::HotSpot * newHotSpot(int startLine, int startColumn, int endLine, int endColumn)
Called when a match for the regular expression is encountered.
Definition: Filter.cpp:367
Konsole::Filter::HotSpot::Marker
Definition: Filter.h:86
QObject
Konsole::FilterChain::addFilter
void addFilter(Filter *filter)
Adds a new filter to the chain.
Definition: Filter.cpp:51
Konsole::RegExpFilter::process
virtual void process()
Reimplemented to search the filter's text buffer for text matching regExp()
Definition: Filter.cpp:328
Konsole::UrlFilter::HotSpot::~HotSpot
virtual ~HotSpot()
Definition: Filter.cpp:447
Konsole::FilterObject
Definition: Filter.h:284
Konsole::Filter::setBuffer
void setBuffer(const QString *buffer, const QList< int > *linePositions)
TODO: Document me.
Definition: Filter.cpp:183
Konsole::Filter::HotSpot::NotSpecified
Definition: Filter.h:82
Konsole::Filter::hotSpotsAtLine
QList< HotSpot * > hotSpotsAtLine(int line) const
Returns the list of hotspots identified by the filter which occur on a given line.
Definition: Filter.cpp:235
Konsole::TerminalImageFilterChain::TerminalImageFilterChain
TerminalImageFilterChain()
Definition: Filter.cpp:106
Konsole::UrlFilter::HotSpot
Hotspot type created by UrlFilter instances.
Definition: Filter.h:246
QString
QList
Character.h
Konsole::FilterChain::setBuffer
void setBuffer(const QString *buffer, const QList< int > *linePositions)
Sets the buffer for each filter in the chain to process.
Definition: Filter.cpp:65
QStringList
Konsole::Filter::hotSpots
QList< HotSpot * > hotSpots() const
Returns the list of hotspots identified by the filter.
Definition: Filter.cpp:231
Konsole::RegExpFilter::setRegExp
void setRegExp(const QRegExp &text)
Sets the regular expression which the filter searches for in blocks of text.
Definition: Filter.cpp:316
Konsole::RegExpFilter
A filter which searches for sections of text matching a regular expression and creates a new RegExpFi...
Definition: Filter.h:182
Konsole::Filter::process
virtual void process()=0
Causes the filter to process the block of text currently in its internal buffer.
Konsole::Filter::HotSpot::type
Type type() const
Returns the type of the hotspot.
Definition: Filter.cpp:284
Konsole::Filter::HotSpot::actions
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar...
Definition: Filter.cpp:264
Konsole::RegExpFilter::RegExpFilter
RegExpFilter()
Constructs a new regular expression filter.
Definition: Filter.cpp:293
Konsole::FilterChain::clear
void clear()
Removes all filters from the chain.
Definition: Filter.cpp:77
Konsole::Filter
A filter processes blocks of text looking for certain patterns (such as URLs or keywords from a list)...
Definition: Filter.h:55
Konsole::UrlFilter::HotSpot::activate
virtual void activate(QObject *object=0)
Open a web browser at the current URL.
Definition: Filter.cpp:398
Konsole::FilterChain
A chain which allows a group of filters to be processed as one.
Definition: Filter.h:312
QVector< LineProperty >
Konsole::UrlFilter
A filter which matches URLs in blocks of text.
Definition: Filter.h:239
Konsole::Filter::HotSpot::Link
Definition: Filter.h:84
QAction
Konsole::Filter::HotSpot::HotSpot
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
Constructs a new hotspot which covers the area from (startLine,startColumn) to (endLine,endColumn) in a block of text.
Definition: Filter.cpp:256
Konsole::TerminalImageFilterChain
A filter chain which processes character images from terminal displays.
Definition: Filter.h:343
Konsole::RegExpFilter::HotSpot::HotSpot
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
Definition: Filter.cpp:297
Konsole::RegExpFilter::regExp
QRegExp regExp() const
Returns the regular expression which the filter searches for in blocks of text.
Definition: Filter.cpp:320
Konsole::Filter::HotSpot::endColumn
int endColumn() const
Returns the column on endLine() where the hotspot area ends.
Definition: Filter.cpp:280
Konsole::TerminalImageFilterChain::setImage
void setImage(const Character *const image, int lines, int columns, const QVector< LineProperty > &lineProperties)
Set the current terminal image to image.
Definition: Filter.cpp:118
Konsole::Filter::reset
void reset()
Empties the filters internal buffer and resets the line count back to 0.
Definition: Filter.cpp:177
Konsole::RegExpFilter::HotSpot
Type of hotspot created by RegExpFilter.
Definition: Filter.h:189
Konsole::RegExpFilter::HotSpot::capturedTexts
QStringList capturedTexts() const
Returns the texts found by the filter when matching the filter's regular expression.
Definition: Filter.cpp:311
Konsole::UrlFilter::HotSpot::actions
virtual QList< QAction * > actions()
Returns a list of actions associated with the hotspot which can be used in a menu or toolbar...
Definition: Filter.cpp:455
Konsole::Filter::HotSpot::~HotSpot
virtual ~HotSpot()
Definition: Filter.cpp:220
Konsole::UrlFilter::HotSpot::HotSpot
HotSpot(int startLine, int startColumn, int endLine, int endColumn)
Definition: Filter.cpp:379
Konsole::Filter::HotSpot::startColumn
int startColumn() const
Returns the column on startLine() where the hotspot area starts.
Definition: Filter.cpp:276
Konsole::FilterChain::process
void process()
Processes each filter in the chain.
Definition: Filter.cpp:71
QMultiHash
Konsole::FilterChain::hotSpots
QList< Filter::HotSpot * > hotSpots() const
Returns a list of all the hotspots in all the chain's filters.
Definition: Filter.cpp:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal