QGIS API Documentation  3.0.2-Girona (307d082)
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 
85 };
86 
93 class CORE_EXPORT QgsLocatorFilter : public QObject
94 {
95  Q_OBJECT
96 
97  public:
98 
100  enum Priority
101  {
105  Low,
106  Lowest
107  };
108 
110  enum Flag
111  {
112  FlagFast = 1 << 1,
113  };
114  Q_DECLARE_FLAGS( Flags, Flag )
115 
116 
119  QgsLocatorFilter( QObject *parent = nullptr );
120 
125  virtual QgsLocatorFilter *clone() const = 0 SIP_FACTORY;
126 
131  virtual QString name() const = 0;
132 
137  virtual QString displayName() const = 0;
138 
142  virtual QgsLocatorFilter::Flags flags() const;
143 
148  virtual Priority priority() const { return Medium; }
149 
159  virtual QString prefix() const { return QString(); }
160 
167  virtual void prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ); Q_UNUSED( context ); }
168 
184  virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
185 
194  virtual void triggerResult( const QgsLocatorResult &result ) = 0;
195 
201  bool useWithoutPrefix() const;
202 
208  void setUseWithoutPrefix( bool useWithoutPrefix );
209 
216  static bool stringMatches( const QString &candidate, const QString &search );
217 
222  bool enabled() const;
223 
228  void setEnabled( bool enabled );
229 
234  virtual bool hasConfigWidget() const;
235 
242  virtual void openConfigWidget( QWidget *parent = nullptr );
243 
244  signals:
245 
249  void finished();
250 
255  void resultFetched( const QgsLocatorResult &result );
256 
257  private:
258 
259  bool mEnabled = true;
260  bool mUseWithoutPrefix = true;
261 
262 };
263 
265 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLocatorFilter::Flags )
266 
267 
268 #endif // QGSLOCATORFILTER_H
269 
270 
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.
Q_DECLARE_METATYPE(QModelIndex)
Flag
Flags for locator behavior.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
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 Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator...
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.