QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
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 <memory>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25#include "qgsfeedback.h"
26#include "qgslocatorcontext.h"
27#include "qgslocatorfilter.h"
28#include "qgssettingstree.h"
29
30#include <QFuture>
31#include <QFutureWatcher>
32#include <QMap>
33#include <QObject>
34#include <QString>
35
36using namespace Qt::StringLiterals;
37
40
41
64class CORE_EXPORT QgsLocator : public QObject
65{
66 Q_OBJECT
67
68 public:
69
71 static const QList<QString> CORE_FILTERS;
72
76 QgsLocator( QObject *parent SIP_TRANSFERTHIS = nullptr );
77
81 ~QgsLocator() override;
82
91
101 void deregisterFilter( QgsLocatorFilter *filter );
102
108 QList< QgsLocatorFilter *> filters( const QString &prefix = QString() );
109
116 Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter *> prefixedFilters() const;
117
128 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = nullptr );
129
135 void cancel();
136
143
147 bool isRunning() const;
148
154
160 QStringList completionList() const {return mAutocompletionList;}
161
162#ifndef SIP_RUN
164
171#endif
172
173 signals:
174
179 void foundResult( const QgsLocatorResult &result );
180
187
192 void finished();
193
194 private slots:
195
196 void filterSentResult( QgsLocatorResult result );
197
198 private:
199
200 QgsFeedback *mFeedback = nullptr;
201 std::unique_ptr< QgsFeedback > mOwnedFeedback;
202
203 QList< QgsLocatorFilter * > mFilters;
204 QList< QThread * > mActiveThreads;
205
206 QStringList mAutocompletionList;
207
208 void cancelRunningQuery();
209
210};
211
212#endif // QGSLOCATOR_H
213
214
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
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.
static QgsSettingsTreeNamedListNode * sTreeLocatorFilters
Definition qgslocator.h:163
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters).
Definition qgslocator.h:71
void searchPrepared()
Emitted when locator has prepared the search (.
void cancel()
Cancels any current running query, and blocks until query is completely canceled by all filters.
QgsLocator(QObject *parent=nullptr)
Constructor for QgsLocator.
static const QgsSettingsEntryBool * settingsLocatorFilterDefault
Settings entry locator filter default value.
Definition qgslocator.h:168
void registerFilter(QgsLocatorFilter *filter)
Registers a filter within the locator.
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.
void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback=nullptr)
Triggers the background fetching of filter results for a specified search string.
void clearPreviousResults()
Will call clearPreviousResults on all filters.
static const QgsSettingsEntryBool * settingsLocatorFilterEnabled
Settings entry locator filter enabled.
Definition qgslocator.h:166
Q_DECL_DEPRECATED QMap< QString, QgsLocatorFilter * > prefixedFilters() const
Returns a map of prefix to filter, for all registered filters with valid prefixes.
bool isRunning() const
Returns true if a query is currently being executed by the locator.
static const QgsSettingsEntryString * settingsLocatorFilterPrefix
Settings entry locator filter prefix.
Definition qgslocator.h:170
void cancelWithoutBlocking()
Triggers cancellation of any current running query without blocking.
QList< QgsLocatorFilter * > filters(const QString &prefix=QString())
Returns the list of filters registered in the locator.
void deregisterFilter(QgsLocatorFilter *filter)
Deregisters a filter from the locator and deletes it.
QStringList completionList() const
Returns the list for auto completion This list is updated when preparing the search.
Definition qgslocator.h:160
A boolean settings entry.
A string settings entry.
A named list tree node for the settings tree to help organizing and introspecting the tree.
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
static QgsSettingsTreeNode * treeRoot()
Returns the tree root node for the settings tree.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36