QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
33 
57 class CORE_EXPORT QgsLocator : public QObject
58 {
59  Q_OBJECT
60 
61  public:
62 
64  static const QList<QString> CORE_FILTERS;
65 
69  QgsLocator( QObject *parent SIP_TRANSFERTHIS = nullptr );
70 
74  ~QgsLocator() override;
75 
83  void registerFilter( QgsLocatorFilter *filter SIP_TRANSFER );
84 
94  void deregisterFilter( QgsLocatorFilter *filter );
95 
101  QList< QgsLocatorFilter *> filters( const QString &prefix = QString() );
102 
109  Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter *> prefixedFilters() const;
110 
121  void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = nullptr );
122 
128  void cancel();
129 
135  void cancelWithoutBlocking();
136 
140  bool isRunning() const;
141 
146  void clearPreviousResults();
147 
153  QStringList completionList() const {return mAutocompletionList;}
154 
155  signals:
156 
161  void foundResult( const QgsLocatorResult &result );
162 
169 
174  void finished();
175 
176  private slots:
177 
178  void filterSentResult( QgsLocatorResult result );
179 
180  private:
181 
182  QgsFeedback *mFeedback = nullptr;
183  std::unique_ptr< QgsFeedback > mOwnedFeedback;
184 
185  QList< QgsLocatorFilter * > mFilters;
186  QList< QThread * > mActiveThreads;
187 
188  QStringList mAutocompletionList;
189 
190  void cancelRunningQuery();
191 
192 };
193 
194 #endif // QGSLOCATOR_H
195 
196 
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:58
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters)
Definition: qgslocator.h:64
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:153
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36