QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
148  signals:
149 
154  void foundResult( const QgsLocatorResult &result );
155 
160  void finished();
161 
162  private slots:
163 
164  void filterSentResult( QgsLocatorResult result );
165 
166  private:
167 
168  QgsFeedback *mFeedback = nullptr;
169  std::unique_ptr< QgsFeedback > mOwnedFeedback;
170 
171  QList< QgsLocatorFilter * > mFilters;
172  QList< QThread * > mActiveThreads;
173 
174  void cancelRunningQuery();
175 
176 };
177 
178 #endif // QGSLOCATOR_H
179 
180 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Encapsulates the properties relating to the context of a locator search.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Abstract base class for filters which collect locator results.
Handles the management of QgsLocatorFilter objects and async collection of search results from them...
Definition: qgslocator.h:57
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters)
Definition: qgslocator.h:64