Subgroup: Locator

Class: QgsLocatorFilter

class qgis.core.QgsLocatorFilter(parent: QObject = None)

Bases: PyQt5.QtCore.QObject

Constructor for QgsLocatorFilter.

Abstract base class for filters which collect locator results.

New in version 3.0: Methods

childEvent
clone Creates a clone of the filter.
connectNotify
customEvent
disconnectNotify
displayName Returns a translated, user-friendly name for the filter.
enabled Returns true if the filter is enabled.
fetchResults Retrieves the filter results for a specified search string.
flags Returns flags which specify the filter’s behavior.
hasConfigWidget Should return true if the filter has a configuration widget.
isSignalConnected
name Returns the unique name for the filter.
openConfigWidget Opens the configuration widget for the filter (if it has one), with the specified parent widget.
prefix Returns the search prefix character(s) for this filter.
prepare Prepares the filter instance for an upcoming search for the specified string.
priority Returns the priority for the filter, which controls how results are ordered in the locator.
receivers
sender
senderSignalIndex
setEnabled Sets whether the filter is enabled.
setUseWithoutPrefix Sets whether the filter should be used when no prefix is entered.
stringMatches Tests a candidate string to see if it should be considered a match for a specified search string.
timerEvent
triggerResult Triggers a filter result from this filter.
useWithoutPrefix Returns true if the filter should be used when no prefix is entered.

Signals

finished Emitted when the filter finishes fetching results.
resultFetched Should be emitted by filters whenever they encounter a matching result during within their fetchResults() implementation.

Attributes

FlagFast
High
Highest
Low
Lowest
Medium
class Flag

Bases: int

FlagFast = 2
class Flags

Bases: sip.wrapper

QgsLocatorFilter.Flags(Union[QgsLocatorFilter.Flags, QgsLocatorFilter.Flag]) QgsLocatorFilter.Flags(QgsLocatorFilter.Flags)

High = 1
Highest = 0
Low = 3
Lowest = 4
Medium = 2
class Priority

Bases: int

childEvent()
clone(self) → QgsLocatorFilter

Creates a clone of the filter. New requests are always executed in a clone of the original filter.

connectNotify()
customEvent()
disconnectNotify()
displayName(self) → str

Returns a translated, user-friendly name for the filter.

See also

name()

enabled(self) → bool

Returns true if the filter is enabled.

See also

setEnabled()

fetchResults(self, string: str, context: QgsLocatorContext, feedback: QgsFeedback)

Retrieves the filter results for a specified search string. The context argument encapsulates the context relating to the search (such as a map extent to prioritize).

Implementations of fetchResults() should emit the resultFetched() signal whenever they encounter a matching result.

Subclasses should periodically check the feedback object to determine whether the query has been canceled. If so, the subclass should return from this method as soon as possible.

This will be called from a background thread unless flags() returns the QgsLocatorFilter.FlagFast flag.

finished

Emitted when the filter finishes fetching results. [signal]

flags(self) → QgsLocatorFilter.Flags

Returns flags which specify the filter’s behavior.

hasConfigWidget(self) → bool

Should return true if the filter has a configuration widget.

See also

createConfigWidget()

isSignalConnected()
name(self) → str

Returns the unique name for the filter. This should be an untranslated string identifying the filter.

See also

displayName()

openConfigWidget(self, parent: QWidget = None)

Opens the configuration widget for the filter (if it has one), with the specified parent widget. The base class implementation does nothing. Subclasses can override this to show their own custom configuration widget.

Note

hasConfigWidget() must return true to indicate that the filter supports configuration.

prefix(self) → str

Returns the search prefix character(s) for this filter. Prefix a search with these characters will restrict the locator search to only include results from this filter.

Note

Plugins are not permitted to utilize prefixes with < 3 characters, as these are reserved for core QGIS functions. If a plugin registers a filter with a prefix shorter than 3 characters then the prefix will be ignored.

prepare(self, string: str, context: QgsLocatorContext)

Prepares the filter instance for an upcoming search for the specified string. This method is always called from the main thread, and individual filter subclasses should perform whatever tasks are required in order to allow a subsequent search to safely execute on a background thread.

priority(self) → QgsLocatorFilter.Priority

Returns the priority for the filter, which controls how results are ordered in the locator.

receivers()
resultFetched

Should be emitted by filters whenever they encounter a matching result during within their fetchResults() implementation. [signal]

sender()
senderSignalIndex()
setEnabled(self, enabled: bool)

Sets whether the filter is enabled.

See also

enabled()

setUseWithoutPrefix(self, useWithoutPrefix: bool)

Sets whether the filter should be used when no prefix is entered.

stringMatches(candidate: str, search: str) → bool

Tests a candidate string to see if it should be considered a match for a specified search string. Filter subclasses should use this method when comparing strings instead of directly using QString.contains() or Python ‘in’ checks.

timerEvent()
triggerResult(self, result: QgsLocatorResult)

Triggers a filter result from this filter. This is called when one of the results obtained by a call to fetchResults() is triggered by a user. The filter subclass must implement logic here to perform the desired operation for the search result. E.g. a file search filter would open file associated with the triggered result.

useWithoutPrefix(self) → bool

Returns true if the filter should be used when no prefix is entered.