QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgslocator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslocator.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 QGSLOCATOR_H
19 #define QGSLOCATOR_H
20 
21 #include <QObject>
22 #include <QFuture>
23 #include <QFutureWatcher>
24 #include <QMap>
25 #include <memory>
26 
27 #include "qgis_core.h"
28 #include "qgis_sip.h"
29 #include "qgslocatorfilter.h"
30 #include "qgsfeedback.h"
31 #include "qgslocatorcontext.h"
32 #include "qgssettingsentry.h"
33 
34 
58 class CORE_EXPORT QgsLocator : public QObject
59 {
60  Q_OBJECT
61 
62  public:
63 
65  static const QList<QString> CORE_FILTERS;
66 
70  QgsLocator( QObject *parent SIP_TRANSFERTHIS = nullptr );
71 
75  ~QgsLocator() override;
76 
84  void registerFilter( QgsLocatorFilter *filter SIP_TRANSFER );
85 
95  void deregisterFilter( QgsLocatorFilter *filter );
96 
102  QList< QgsLocatorFilter *> filters( const QString &prefix = QString() );
103 
110  Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter *> prefixedFilters() const;
111 
122  void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = nullptr );
123 
129  void cancel();
130 
136  void cancelWithoutBlocking();
137 
141  bool isRunning() const;
142 
147  void clearPreviousResults();
148 
154  QStringList completionList() const {return mAutocompletionList;}
155 
156 #ifndef SIP_RUN
158  static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "locator_filters/enabled_%1" ), QgsSettings::Gui, true, QObject::tr( "Locator filter enabled" ) );
160  static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "locator_filters/default_%1" ), QgsSettings::Gui, false, QObject::tr( "Locator filter default value" ) );
162  static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "locator_filters/prefix_%1" ), QgsSettings::Gui, QString(), QObject::tr( "Locator filter prefix" ) );
163 #endif
164 
165  signals:
166 
171  void foundResult( const QgsLocatorResult &result );
172 
179 
184  void finished();
185 
186  private slots:
187 
188  void filterSentResult( QgsLocatorResult result );
189 
190  private:
191 
192  QgsFeedback *mFeedback = nullptr;
193  std::unique_ptr< QgsFeedback > mOwnedFeedback;
194 
195  QList< QgsLocatorFilter * > mFilters;
196  QList< QThread * > mActiveThreads;
197 
198  QStringList mAutocompletionList;
199 
200  void cancelRunningQuery();
201 
202 };
203 
204 #endif // QGSLOCATOR_H
205 
206 
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.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:59
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters)
Definition: qgslocator.h:65
void searchPrepared()
Emitted when locator has prepared the search (.
void finished()
Emitted when locator has finished a query, either as a result of successful completion or early cance...
void foundResult(const QgsLocatorResult &result)
Emitted whenever a filter encounters a matching result after the fetchResults() method is called.
QStringList completionList() const
Returns the list for auto completion This list is updated when preparing the search.
Definition: qgslocator.h:154
A boolean settings entry.
A string settings entry.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36