QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 <QIcon>
22#include <QString>
23#include <QVariant>
24
25#include "qgis_core.h"
26#include "qgslocatorcontext.h"
27#include "qgslogger.h"
28
29class QgsFeedback;
31
37class CORE_EXPORT QgsLocatorResult
38{
39 Q_GADGET
40
41 Q_PROPERTY( QVariant userData READ userData WRITE setUserData )
42 Q_PROPERTY( QString displayString MEMBER displayString )
43 Q_PROPERTY( QString description MEMBER description )
44 Q_PROPERTY( double score MEMBER score )
45 Q_PROPERTY( QString group MEMBER group )
46 Q_PROPERTY( double groupScore MEMBER groupScore )
47
48 public:
49
50 QgsLocatorResult() = default;
51
55 QgsLocatorResult( QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData = QVariant() )
56 : filter( filter )
57 , displayString( displayString )
58 , mUserData( userData )
59 {}
60
66 QVariant userData() const SIP_PYNAME( _userData );
67
73 void setUserData( const QVariant &userData );
74
78 QgsLocatorFilter *filter = nullptr;
79
83 QString displayString;
84
88 QString description;
89
93 QIcon icon;
94
98 double score = 0.5;
99
107 QString group;
108
116 double groupScore = 0;
117
124 struct CORE_EXPORT ResultAction
125 {
126 public:
127
128 ResultAction() = default;
129
136 ResultAction( int id, QString text, QString iconPath = QString() )
137 : id( id )
138 , text( text )
139 , iconPath( iconPath )
140 {}
141 int id = -1;
142 QString text;
143 QString iconPath;
144 };
145
152 QList<QgsLocatorResult::ResultAction> actions;
153
154 private:
155
159 QVariant mUserData;
160
161
162};
163
165
166
167
175class CORE_EXPORT QgsLocatorFilter : public QObject
176{
177 Q_OBJECT
178
179 public:
180
183 {
188 Lowest
189 };
190 Q_ENUM( Priority )
191
192
193 enum Flag SIP_ENUM_BASETYPE( IntFlag )
194 {
195 FlagFast = 1 << 1,
196 };
197 Q_DECLARE_FLAGS( Flags, Flag )
198 Q_FLAG( Flags )
199
200
203 QgsLocatorFilter( QObject *parent = nullptr );
204
209 virtual QgsLocatorFilter *clone() const = 0 SIP_FACTORY;
210
215 virtual QString name() const = 0;
216
221 virtual QString displayName() const = 0;
222
227 virtual QString description() const { return QString(); }
228
232 virtual QgsLocatorFilter::Flags flags() const;
233
238 virtual Priority priority() const { return Medium; }
239
251 virtual QString prefix() const { return QString(); }
252
260 virtual QStringList prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ) Q_UNUSED( context ); return QStringList();}
261
277 virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
278
287 virtual void triggerResult( const QgsLocatorResult &result ) = 0;
288
295 virtual void resultSelected( const QgsLocatorResult &result ) {Q_UNUSED( result )}
296
303 virtual void resultDeselected( const QgsLocatorResult &result ) {Q_UNUSED( result )}
304
311 virtual void triggerResultFromAction( const QgsLocatorResult &result, const int actionId );
312
321 virtual void clearPreviousResults() {}
322
328 bool useWithoutPrefix() const;
329
335 void setUseWithoutPrefix( bool useWithoutPrefix );
336
343 QString activePrefix() const;
344
351 void setActivePrefix( const QString &activePrefix ) SIP_SKIP;
352
359 static bool stringMatches( const QString &candidate, const QString &search );
360
366 static double fuzzyScore( const QString &candidate, const QString &search );
367
372 bool enabled() const;
373
378 void setEnabled( bool enabled );
379
384 virtual bool hasConfigWidget() const;
385
392 virtual void openConfigWidget( QWidget *parent = nullptr );
393
400 void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
401
407 int fetchResultsDelay() const { return mFetchResultsDelay; }
408
415 void setFetchResultsDelay( int delay ) { mFetchResultsDelay = delay; }
416
417 signals:
418
422 void finished();
423
428 void resultFetched( const QgsLocatorResult &result );
429
430 private:
431
432 bool mEnabled = true;
433 bool mUseWithoutPrefix = true;
434 QString mActivePrefifx = QString();
435 int mFetchResultsDelay = 0;
436
437};
438
441
442
443#endif // QGSLOCATORFILTER_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ Info
Information message.
Definition qgis.h:155
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Encapsulates the properties relating to the context of a locator search.
Abstract base class for filters which collect locator results.
QFlags< Flag > Flags
virtual QString prefix() const
Returns the search prefix character(s) for this filter.
Flag
Flags for locator behavior.
int fetchResultsDelay() const
Returns the delay (in milliseconds) for the filter to wait prior to fetching results.
Priority
Filter priority. Controls the order of results in the locator.
@ Low
Low priority.
@ Highest
Highest priority.
@ Medium
Medium priority.
@ High
High priority.
void setFetchResultsDelay(int delay)
Sets a delay (in milliseconds) for the filter to wait prior to fetching results.
virtual QString description() const
Returns a translated, description for the filter.
void finished()
Emitted when the filter finishes fetching results.
virtual QString displayName() const =0
Returns a translated, user-friendly name for the filter.
virtual Priority priority() const
Returns the priority for the filter, which controls how results are ordered in the locator.
virtual QString name() const =0
Returns the unique name for the filter.
virtual void triggerResult(const QgsLocatorResult &result)=0
Triggers a filter result from this filter.
virtual QgsLocatorFilter * clone() const =0
Creates a clone of the filter.
virtual void resultDeselected(const QgsLocatorResult &result)
This is called when a result is deselected.
virtual void clearPreviousResults()
This method will be called on main thread on the original filter (not a clone) before fetching result...
virtual void resultSelected(const QgsLocatorResult &result)
This is called when the result is selected by the user.
void resultFetched(const QgsLocatorResult &result)
Should be emitted by filters whenever they encounter a matching result during within their fetchResul...
virtual void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback)=0
Retrieves the filter results for a specified search string.
virtual QStringList prepare(const QString &string, const QgsLocatorContext &context)
Prepares the filter instance for an upcoming search for the specified string.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
QList< QgsLocatorResult::ResultAction > actions
Additional actions to be used in a locator widget for the given result.
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
The ResultAction stores basic information for additional actions to be used in a locator widget for t...
ResultAction(int id, QString text, QString iconPath=QString())
Constructor for ResultAction The id used to recognized the action when the result is triggered.