QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgis_core.h"
22 #include "qgslocatorcontext.h"
23 #include "qgslogger.h"
24 #include <QString>
25 #include <QVariant>
26 #include <QIcon>
27 
28 class QgsFeedback;
29 class QgsLocatorFilter;
30 
37 class CORE_EXPORT QgsLocatorResult
38 {
39  public:
40 
44  QgsLocatorResult() = default;
45 
49  QgsLocatorResult( QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData = QVariant() )
50  : filter( filter )
51  , displayString( displayString )
52  , userData( userData )
53  {}
54 
58  QgsLocatorFilter *filter = nullptr;
59 
63  QString displayString;
64 
68  QString description;
69 
73  QVariant userData;
74 
78  QIcon icon;
79 
83  double score = 0.5;
84 
92  QString group = QString();
93 
94 };
95 
105 class CORE_EXPORT QgsLocatorFilter : public QObject
106 {
107  Q_OBJECT
108 
109  public:
110 
112  enum Priority
113  {
117  Low,
118  Lowest
119  };
120  Q_ENUM( Priority )
121 
122 
123  enum Flag
124  {
125  FlagFast = 1 << 1,
126  };
127  Q_DECLARE_FLAGS( Flags, Flag )
128  Q_FLAG( Flags )
129 
133  QgsLocatorFilter( QObject *parent = nullptr );
134 
139  virtual QgsLocatorFilter *clone() const = 0 SIP_FACTORY;
140 
145  virtual QString name() const = 0;
146 
151  virtual QString displayName() const = 0;
152 
156  virtual QgsLocatorFilter::Flags flags() const;
157 
162  virtual Priority priority() const { return Medium; }
163 
175  virtual QString prefix() const { return QString(); }
176 
183  virtual void prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ); Q_UNUSED( context ); }
184 
200  virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
201 
210  virtual void triggerResult( const QgsLocatorResult &result ) = 0;
211 
220  virtual void clearPreviousResults() {}
221 
227  bool useWithoutPrefix() const;
228 
234  void setUseWithoutPrefix( bool useWithoutPrefix );
235 
242  QString activePrefix() const;
243 
250  void setActivePrefix( const QString &activePrefix ) SIP_SKIP;
251 
258  static bool stringMatches( const QString &candidate, const QString &search );
259 
264  bool enabled() const;
265 
270  void setEnabled( bool enabled );
271 
276  virtual bool hasConfigWidget() const;
277 
284  virtual void openConfigWidget( QWidget *parent = nullptr );
285 
292  void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
293 
294 
295  signals:
296 
300  void finished();
301 
306  void resultFetched( const QgsLocatorResult &result );
307 
308  private:
309 
310  bool mEnabled = true;
311  bool mUseWithoutPrefix = true;
312  QString mActivePrefifx = QString();
313 
314 };
315 
317 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLocatorFilter::Flags )
318 
319 
320 #endif // QGSLOCATORFILTER_H
321 
322 
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:79
Q_DECLARE_METATYPE(QModelIndex)
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:119
QVariant userData
Custom reference or other data set by the filter.
QString displayString
String displayed for result.
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:69
virtual void clearPreviousResults()
This method will be called on main thread on the original filter (not a clone) before fetching result...
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
QgsLocatorResult(QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData=QVariant())
Constructor for QgsLocatorResult.