QgsLocator class
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Contents
QgsLocator acts as both a registry for QgsLocatorFilter objects and a means of firing up asynchronous queries against these filter objects.
Filters are first registered to the locator by calling registerFilter(). Registering filters transfers their ownership to the locator object. Plugins which register filters to the locator must take care to correctly call deregisterFilter() and deregister their filter upon plugin unload to avoid crashes.
In order to trigger a search across registered filters, the fetchResults() method is called. This triggers threaded calls to QgsLocatorFilter::
Public static variables
- static const QList<QString> CORE_FILTERS
- List of core filters (i.e. not plugin filters)
Constructors, destructors, conversion operators
- QgsLocator(QObject* parent = nullptr)
- Constructor for QgsLocator.
- ~QgsLocator() override
- Destructor for QgsLocator.
Public functions
- void cancel()
- Cancels any current running query, and blocks until query is completely canceled by all filters.
- void cancelWithoutBlocking()
- Triggers cancelation of any current running query without blocking.
- void clearPreviousResults()
- Will call clearPreviousResults on all filters.
- void deregisterFilter(QgsLocatorFilter* filter)
- Deregisters a filter from the locator and deletes it.
- void fetchResults(const QString& string, const QgsLocatorContext& context, QgsFeedback* feedback = nullptr)
- Triggers the background fetching of filter results for a specified search string.
- auto filters(const QString& prefix = QString()) -> QList<QgsLocatorFilter*>
- Returns the list of filters registered in the locator.
- auto isRunning() const -> bool
- Returns true if a query is currently being executed by the locator.
- auto prefixedFilters() const -> Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter*> deprecated
- Returns a map of prefix to filter, for all registered filters with valid prefixes.
- void registerFilter(QgsLocatorFilter* filter)
- Registers a filter within the locator.
Signals
- void finished()
- Emitted when locator has finished a query, either as a result of successful completion or early cancelation.
- void foundResult(const QgsLocatorResult& result)
- Emitted whenever a filter encounters a matching result after the fetchResults() method is called.
Function documentation
QgsLocator:: ~QgsLocator() override
Destructor for QgsLocator.
Destruction will block while any currently running query is terminated.
void QgsLocator:: cancel()
Cancels any current running query, and blocks until query is completely canceled by all filters.
void QgsLocator:: cancelWithoutBlocking()
Triggers cancelation of any current running query without blocking.
The query may take some time to cancel after calling this.
void QgsLocator:: clearPreviousResults()
Will call clearPreviousResults on all filters.
void QgsLocator:: deregisterFilter(QgsLocatorFilter* filter)
Deregisters a filter from the locator and deletes it.
Calling this will block whilst any currently running query is terminated.
Plugins which register filters to the locator must take care to correctly call deregisterFilter() to deregister their filters upon plugin unload to avoid crashes.
void QgsLocator:: fetchResults(const QString& string,
const QgsLocatorContext& context,
QgsFeedback* feedback = nullptr)
Triggers the background fetching of filter results for a specified search string.
The context argument encapsulates the context relating to the search (such as a map extent to prioritize).
If specified, the feedback object must exist for the lifetime of this query.
The foundResult() signal will be emitted for each individual result encountered by the registered filters.
QList<QgsLocatorFilter*> QgsLocator:: filters(const QString& prefix = QString())
Returns the list of filters registered in the locator.
| Parameters | |
|---|---|
| prefix | If prefix is not empty, the list returned corresponds to the filter with the given active prefix |
Q_DECL_DEPRECATED QMap<QString, QgsLocatorFilter*> QgsLocator:: prefixedFilters() const
Returns a map of prefix to filter, for all registered filters with valid prefixes.
void QgsLocator:: registerFilter(QgsLocatorFilter* filter)
Registers a filter within the locator.
Ownership of the filter is transferred to the locator.