QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
313  static double fuzzyScore( const QString &candidate, const QString &search );
314 
319  bool enabled() const;
320 
325  void setEnabled( bool enabled );
326 
331  virtual bool hasConfigWidget() const;
332 
339  virtual void openConfigWidget( QWidget *parent = nullptr );
340 
347  void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
348 
349 
350  signals:
351 
355  void finished();
356 
361  void resultFetched( const QgsLocatorResult &result );
362 
363  private:
364 
365  bool mEnabled = true;
366  bool mUseWithoutPrefix = true;
367  QString mActivePrefifx = QString();
368 
369 };
370 
372 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLocatorFilter::Flags )
373 
374 
375 #endif // QGSLOCATORFILTER_H
376 
377 
QgsLocatorFilter
Definition: qgslocatorfilter.h:145
QgsLocatorFilter::Highest
@ Highest
Highest priority.
Definition: qgslocatorfilter.h:154
QgsLocatorFilter::Medium
@ Medium
Medium priority.
Definition: qgslocatorfilter.h:156
QgsLocatorFilter::prefix
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
Definition: qgslocatorfilter.h:215
QgsLocatorResult::displayString
QString displayString
String displayed for result.
Definition: qgslocatorfilter.h:65
qgslocatorcontext.h
QgsLocatorFilter::priority
virtual Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator.
Definition: qgslocatorfilter.h:202
QgsLocatorResult::actions
QList< QgsLocatorResult::ResultAction > actions
Additional actions to be used in a locator widget for the given result.
Definition: qgslocatorfilter.h:130
QgsLocatorResult::ResultAction::ResultAction
ResultAction(int id, QString text, QString iconPath=QString())
Constructor for ResultAction The id used to recognized the action when the result is triggered.
Definition: qgslocatorfilter.h:114
QgsLocatorResult
Definition: qgslocatorfilter.h:39
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLocatorFilter::clearPreviousResults
virtual void clearPreviousResults()
This method will be called on main thread on the original filter (not a clone) before fetching result...
Definition: qgslocatorfilter.h:268
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
QgsLocatorResult::ResultAction::text
QString text
Definition: qgslocatorfilter.h:120
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLocatorContext
Definition: qgslocatorcontext.h:31
Qgis::Info
@ Info
Definition: qgis.h:103
QgsFeedback
Definition: qgsfeedback.h:43
QgsLocatorFilter::prepare
virtual void prepare(const QString &string, const QgsLocatorContext &context)
Prepares the filter instance for an upcoming search for the specified string.
Definition: qgslocatorfilter.h:223
QgsLocatorResult::QgsLocatorResult
QgsLocatorResult(QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData=QVariant())
Constructor for QgsLocatorResult.
Definition: qgslocatorfilter.h:51
QgsLocatorFilter::Priority
Priority
Filter priority. Controls the order of results in the locator.
Definition: qgslocatorfilter.h:152
QgsLocatorResult::ResultAction
The ResultAction stores basic information for additional actions to be used in a locator widget for t...
Definition: qgslocatorfilter.h:102
QgsLocatorResult::icon
QIcon icon
Icon for result.
Definition: qgslocatorfilter.h:80
QgsLocatorFilter::Flag
Flag
Flags for locator behavior.
Definition: qgslocatorfilter.h:163
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:101
QgsLocatorFilter::Low
@ Low
Low priority.
Definition: qgslocatorfilter.h:157
QgsLocatorResult::ResultAction::iconPath
QString iconPath
Definition: qgslocatorfilter.h:121
QgsLocatorFilter::High
@ High
High priority.
Definition: qgslocatorfilter.h:155
qgslogger.h
QgsLocatorResult::description
QString description
Descriptive text for result.
Definition: qgslocatorfilter.h:70
QgsLocatorResult::userData
QVariant userData
Custom reference or other data set by the filter.
Definition: qgslocatorfilter.h:75