QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
38class CORE_EXPORT QgsLocatorResult
39{
40 public:
41
45 QgsLocatorResult() = default;
46
50 QgsLocatorResult( QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData = QVariant() )
51 : filter( filter )
52 , displayString( displayString )
53 , mUserData( userData )
54 {}
55
61 QVariant getUserData() const;
62
68 void setUserData( QVariant userData );
69
73 QgsLocatorFilter *filter = nullptr;
74
79
83 QString description;
84
88 QIcon icon;
89
93 double score = 0.5;
94
102 QString group;
103
110 struct CORE_EXPORT ResultAction
111 {
112 public:
114 ResultAction() = default;
115
122 ResultAction( int id, QString text, QString iconPath = QString() )
123 : id( id )
124 , text( text )
125 , iconPath( iconPath )
126 {}
127 int id = -1;
128 QString text;
129 QString iconPath;
130 };
131
138 QList<QgsLocatorResult::ResultAction> actions;
139
140#ifdef SIP_RUN
141 SIP_PROPERTY( name = userData, get = getUserData, set = setUserData )
142#endif
143
144 private:
145
149 QVariant mUserData;
150
151
152};
153
155
156
157
166class CORE_EXPORT QgsLocatorFilter : public QObject
167{
168 Q_OBJECT
169
170 public:
171
174 {
179 Lowest
180 };
181 Q_ENUM( Priority )
182
183
184 enum Flag
185 {
186 FlagFast = 1 << 1,
187 };
188 Q_DECLARE_FLAGS( Flags, Flag )
189 Q_FLAG( Flags )
190
191
194 QgsLocatorFilter( QObject *parent = nullptr );
195
200 virtual QgsLocatorFilter *clone() const = 0 SIP_FACTORY;
201
206 virtual QString name() const = 0;
207
212 virtual QString displayName() const = 0;
213
218 virtual QString description() const { return QString(); }
219
223 virtual QgsLocatorFilter::Flags flags() const;
224
229 virtual Priority priority() const { return Medium; }
230
242 virtual QString prefix() const { return QString(); }
243
251 virtual QStringList prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ) Q_UNUSED( context ); return QStringList();}
252
268 virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
269
278 virtual void triggerResult( const QgsLocatorResult &result ) = 0;
279
286 virtual void triggerResultFromAction( const QgsLocatorResult &result, const int actionId );
287
296 virtual void clearPreviousResults() {}
297
303 bool useWithoutPrefix() const;
304
310 void setUseWithoutPrefix( bool useWithoutPrefix );
311
318 QString activePrefix() const;
319
326 void setActivePrefix( const QString &activePrefix ) SIP_SKIP;
327
334 static bool stringMatches( const QString &candidate, const QString &search );
335
341 static double fuzzyScore( const QString &candidate, const QString &search );
342
347 bool enabled() const;
348
353 void setEnabled( bool enabled );
354
359 virtual bool hasConfigWidget() const;
360
367 virtual void openConfigWidget( QWidget *parent = nullptr );
368
375 void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
376
382 int fetchResultsDelay() const { return mFetchResultsDelay; }
383
390 void setFetchResultsDelay( int delay ) { mFetchResultsDelay = delay; }
391
392 signals:
393
397 void finished();
398
403 void resultFetched( const QgsLocatorResult &result );
404
405 private:
406
407 bool mEnabled = true;
408 bool mUseWithoutPrefix = true;
409 QString mActivePrefifx = QString();
410 int mFetchResultsDelay = 0;
411
412};
413
415Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLocatorFilter::Flags )
416
417
418#endif // QGSLOCATORFILTER_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:99
@ Info
Information message.
Definition qgis.h:100
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:45
Encapsulates the properties relating to the context of a locator search.
Abstract base class for filters which collect locator results.
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 clearPreviousResults()
This method will be called on main thread on the original filter (not a clone) before fetching result...
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.
QString description
Descriptive text for result.
QgsLocatorResult()=default
Constructor for QgsLocatorResult.
QString displayString
String displayed for result.
QString group
Group the results by categories If left as empty string, this means that results are all shown withou...
QIcon icon
Icon for result.
QgsLocatorResult(QgsLocatorFilter *filter, const QString &displayString, const QVariant &userData=QVariant())
Constructor for QgsLocatorResult.
#define SIP_PROPERTY(name, getter, setter)
Definition qgis_sip.h:273
#define SIP_SKIP
Definition qgis_sip.h:126
#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.
ResultAction()=default
Constructor for ResultAction.