Class: QgsLocator¶
Handles the management of QgsLocatorFilter objects and async
collection of search results from them.
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.fetchResults() for all registered
filters. As individual filters find matching results, the
foundResult() signal will be triggered for each result.
Callers should connect this signal to an appropriate slot designed to
collect and handle these results. Since foundResult() is
triggered whenever a filter encounters an individual result, it will
usually be triggered many times for a single call to
fetchResults().
Class Hierarchy¶
Base classes¶
- class qgis.core.QgsLocator[source]¶
Bases:
QObject- __init__(parent: QObject | None = None)
Constructor for QgsLocator.
- Parameters:
parent (Optional[QObject] = None)
- CORE_FILTERS: List[str] = ['actions', 'processing_alg', 'layertree', 'layouts', 'features', 'allfeatures', 'calculator', 'bookmarks', 'optionpages', 'edit_features', 'goto', 'nominatimgeocoder']¶
- cancel(self)[source]¶
Cancels any current running query, and blocks until query is completely canceled by all filters.
See also
- cancelWithoutBlocking(self)[source]¶
Triggers cancellation of any current running query without blocking. The query may take some time to cancel after calling this.
See also
- clearPreviousResults(self)[source]¶
Will call clearPreviousResults on all filters
Added in version 3.2.
- completionList(self) List[str][source]¶
Returns the list for auto completion This list is updated when preparing the search
Added in version 3.16.
- Return type:
List[str]
- deregisterFilter(self, filter: QgsLocatorFilter | None)[source]¶
Deregisters a
filterfrom 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.See also
- Parameters:
filter (Optional[QgsLocatorFilter])
- fetchResults(self, string: str | None, context: QgsLocatorContext, feedback: QgsFeedback | None = None)[source]¶
Triggers the background fetching of filter results for a specified search
string. Thecontextargument encapsulates the context relating to the search (such as a map extent to prioritize).If specified, the
feedbackobject must exist for the lifetime of this query.The
foundResult()signal will be emitted for each individual result encountered by the registered filters.- Parameters:
string (Optional[str])
context (QgsLocatorContext)
feedback (Optional[QgsFeedback] = None)
- filters(self, prefix: str | None = '') List[QgsLocatorFilter]¶
Returns the list of filters registered in the locator.
- Parameters:
prefix (Optional[str] = '') – If prefix is not empty, the list returned corresponds to the filter with the given active prefix
See also
- Return type:
- signal finished[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- signal foundResult[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- isRunning(self) bool[source]¶
Returns
Trueif a query is currently being executed by the locator.- Return type:
bool
- prefixedFilters(self) Any¶
Returns a map of prefix to filter, for all registered filters with valid prefixes.
See also
Deprecated since version 3.2: Use
filters()instead.- Return type:
- registerFilter(self, filter: QgsLocatorFilter | None)[source]¶
Registers a
filterwithin the locator. Ownership of the filter is transferred to the locator.Warning
Plugins which register filters to the locator must take care to correctly call
deregisterFilter()and deregister their filters upon plugin unload to avoid crashes.See also
- Parameters:
filter (Optional[QgsLocatorFilter])
- signal searchPrepared[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.