QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
37
38
61class CORE_EXPORT QgsLocator : public QObject
62{
63 Q_OBJECT
64
65 public:
66
68 static const QList<QString> CORE_FILTERS;
69
73 QgsLocator( QObject *parent SIP_TRANSFERTHIS = nullptr );
74
78 ~QgsLocator() override;
79
88
98 void deregisterFilter( QgsLocatorFilter *filter );
99
105 QList< QgsLocatorFilter *> filters( const QString &prefix = QString() );
106
113 Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter *> prefixedFilters() const;
114
125 void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = nullptr );
126
132 void cancel();
133
140
144 bool isRunning() const;
145
151
157 QStringList completionList() const {return mAutocompletionList;}
158
159#ifndef SIP_RUN
160 static inline QgsSettingsTreeNamedListNode *sTreeLocatorFilters = QgsSettingsTree::treeRoot()->createNamedListNode( QStringLiteral( "locator-filters" ) );
161
168#endif
169
170 signals:
171
176 void foundResult( const QgsLocatorResult &result );
177
184
189 void finished();
190
191 private slots:
192
193 void filterSentResult( QgsLocatorResult result );
194
195 private:
196
197 QgsFeedback *mFeedback = nullptr;
198 std::unique_ptr< QgsFeedback > mOwnedFeedback;
199
200 QList< QgsLocatorFilter * > mFilters;
201 QList< QThread * > mActiveThreads;
202
203 QStringList mAutocompletionList;
204
205 void cancelRunningQuery();
206
207};
208
209#endif // QGSLOCATOR_H
210
211
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:160
static const QList< QString > CORE_FILTERS
List of core filters (i.e. not plugin filters).
Definition qgslocator.h:68
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:165
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:163
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:167
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:157
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