QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgslocatorfilter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocatorfilter.h
3  ------------------
4  begin : May 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLOCATORFILTER_H
19 #define QGSLOCATORFILTER_H
20 
21 #include <QAction>
22 #include <QIcon>
23 #include <QString>
24 #include <QVariant>
25 
26 #include "qgis_core.h"
27 #include "qgslocatorcontext.h"
28 #include "qgslogger.h"
29 
30 class QgsFeedback;
31 class QgsLocatorFilter;
32 
39 class CORE_EXPORT QgsLocatorResult
40 {
41  public:
42 
46  QgsLocatorResult() = default;
47 
51  QgsLocatorResult( QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData = QVariant() )
52  : filter( filter )
53  , displayString( displayString )
54  , userData( userData )
55  {}
56 
60  QgsLocatorFilter *filter = nullptr;
61 
65  QString displayString;
66 
70  QString description;
71 
75  QVariant userData;
76 
80  QIcon icon;
81 
85  double score = 0.5;
86 
94  QString group = QString();
95 
102  struct CORE_EXPORT ResultAction
103  {
104  public:
106  ResultAction() = default;
107 
114  ResultAction( int id, QString text, QString iconPath = QString() )
115  : id( id )
116  , text( text )
117  , iconPath( iconPath )
118  {}
119  int id = -1;
120  QString text;
121  QString iconPath;
122  };
123 
130  QList<QgsLocatorResult::ResultAction> actions;
131 };
132 
134 
135 
136 
145 class CORE_EXPORT QgsLocatorFilter : public QObject
146 {
147  Q_OBJECT
148 
149  public:
150 
152  enum Priority
153  {
157  Low,
158  Lowest
159  };
160  Q_ENUM( Priority )
161 
162 
163  enum Flag
164  {
165  FlagFast = 1 << 1,
166  };
167  Q_DECLARE_FLAGS( Flags, Flag )
168  Q_FLAG( Flags )
169 
170 
173  QgsLocatorFilter( QObject *parent = nullptr );
174 
179  virtual QgsLocatorFilter *clone() const = 0 SIP_FACTORY;
180 
185  virtual QString name() const = 0;
186 
191  virtual QString displayName() const = 0;
192 
196  virtual QgsLocatorFilter::Flags flags() const;
197 
202  virtual Priority priority() const { return Medium; }
203 
215  virtual QString prefix() const { return QString(); }
216 
223  virtual void prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ) Q_UNUSED( context ); }
224 
240  virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
241 
250  virtual void triggerResult( const QgsLocatorResult &result ) = 0;
251 
258  virtual void triggerResultFromAction( const QgsLocatorResult &result, const int actionId );
259 
268  virtual void clearPreviousResults() {}
269 
275  bool useWithoutPrefix() const;
276 
282  void setUseWithoutPrefix( bool useWithoutPrefix );
283 
290  QString activePrefix() const;
291 
298  void setActivePrefix( const QString &activePrefix ) SIP_SKIP;
299 
306  static bool stringMatches( const QString &candidate, const QString &search );
307 
312  bool enabled() const;
313 
318  void setEnabled( bool enabled );
319 
324  virtual bool hasConfigWidget() const;
325 
332  virtual void openConfigWidget( QWidget *parent = nullptr );
333 
340  void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
341 
342 
343  signals:
344 
348  void finished();
349 
354  void resultFetched( const QgsLocatorResult &result );
355 
356  private:
357 
358  bool mEnabled = true;
359  bool mUseWithoutPrefix = true;
360  QString mActivePrefifx = QString();
361 
362 };
363 
365 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLocatorFilter::Flags )
366 
367 
368 #endif // QGSLOCATORFILTER_H
369 
370 
virtual void prepare(const QString &string, const QgsLocatorContext &context)
Prepares the filter instance for an upcoming search for the specified string.
QIcon icon
Icon for result.
Priority
Filter priority. Controls the order of results in the locator.
QString description
Descriptive text for result.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:67
Flag
Flags for locator behavior.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
#define SIP_SKIP
Definition: qgis_sip.h:126
QVariant userData
Custom reference or other data set by the filter.
QString displayString
String displayed for result.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
Encapsulates the properties relating to the context of a locator search.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Abstract base class for filters which collect locator results.
#define SIP_FACTORY
Definition: qgis_sip.h:76
virtual Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator...
ResultAction(int id, QString text, QString iconPath=QString())
Constructor for ResultAction The id used to recognized the action when the result is triggered...
QList< QgsLocatorResult::ResultAction > actions
Additional actions to be used in a locator widget for the given result.
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
virtual void clearPreviousResults()
This method will be called on main thread on the original filter (not a clone) before fetching result...
The ResultAction stores basic information for additional actions to be used in a locator widget for t...
QgsLocatorResult(QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData=QVariant())
Constructor for QgsLocatorResult.