QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgssettingsentryimpl.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
157  static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "enabled_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, true, QObject::tr( "Locator filter enabled" ) );
160  static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "default_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, false, QObject::tr( "Locator filter default value" ) );
162  static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "prefix_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, QString(), QObject::tr( "Locator filter prefix" ) );
163 #endif
164 
165  signals:
166 
171  void foundResult( const QgsLocatorResult &result );
172 
178  void searchPrepared();
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 
QgsLocatorFilter
Abstract base class for filters which collect locator results.
Definition: qgslocatorfilter.h:152
QgsLocator::CORE_FILTERS
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters)
Definition: qgslocator.h:65
qgslocatorcontext.h
QgsLocator
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:58
QgsSettingsEntryString
A string settings entry.
Definition: qgssettingsentryimpl.h:87
QgsLocatorResult
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Definition: qgslocatorfilter.h:38
QgsLocatorContext
Encapsulates the properties relating to the context of a locator search.
Definition: qgslocatorcontext.h:32
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
qgssettingsentryimpl.h
QgsSettings::Prefix::GUI_LOCATORFILTERS
static const char * GUI_LOCATORFILTERS
Definition: qgssettings.h:95
QgsLocator::completionList
QStringList completionList() const
Returns the list for auto completion This list is updated when preparing the search.
Definition: qgslocator.h:154
qgsfeedback.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgslocatorfilter.h
QgsSettingsEntryBool
A boolean settings entry.
Definition: qgssettingsentryimpl.h:241