QGIS API Documentation
3.20.0-Odense (decaadbb31)
|
Abstract base class for filters which collect locator results. More...
#include <qgslocatorfilter.h>
Public Types | |
enum | Flag { FlagFast = 1 << 1 } |
Flags for locator behavior. More... | |
enum | Priority { Highest , High , Medium , Low , Lowest } |
Filter priority. Controls the order of results in the locator. More... | |
Signals | |
void | finished () |
Emitted when the filter finishes fetching results. More... | |
void | resultFetched (const QgsLocatorResult &result) |
Should be emitted by filters whenever they encounter a matching result during within their fetchResults() implementation. More... | |
Public Member Functions | |
QgsLocatorFilter (QObject *parent=nullptr) | |
Constructor for QgsLocatorFilter. More... | |
QString | activePrefix () const |
Returns the prefix in use in the locator is entered. More... | |
virtual void | clearPreviousResults () |
This method will be called on main thread on the original filter (not a clone) before fetching results or before triggering a result to clear any change made by a former call to triggerResult. More... | |
virtual QgsLocatorFilter * | clone () const =0 |
Creates a clone of the filter. More... | |
virtual QString | description () const |
Returns a translated, description for the filter. More... | |
virtual QString | displayName () const =0 |
Returns a translated, user-friendly name for the filter. More... | |
bool | enabled () const |
Returns true if the filter is enabled. More... | |
virtual void | fetchResults (const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback)=0 |
Retrieves the filter results for a specified search string. More... | |
int | fetchResultsDelay () const |
Returns the delay (in milliseconds) for the filter to wait prior to fetching results. More... | |
virtual QgsLocatorFilter::Flags | flags () const |
Returns flags which specify the filter's behavior. More... | |
virtual bool | hasConfigWidget () const |
Should return true if the filter has a configuration widget. More... | |
void | logMessage (const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Info) |
Logs a message to the log panel. More... | |
virtual QString | name () const =0 |
Returns the unique name for the filter. More... | |
virtual void | openConfigWidget (QWidget *parent=nullptr) |
Opens the configuration widget for the filter (if it has one), with the specified parent widget. More... | |
virtual QString | prefix () const |
Returns the search prefix character(s) for this filter. More... | |
virtual QStringList | prepare (const QString &string, const QgsLocatorContext &context) |
Prepares the filter instance for an upcoming search for the specified string. More... | |
virtual Priority | priority () const |
Returns the priority for the filter, which controls how results are ordered in the locator. More... | |
void | setActivePrefix (const QString &activePrefix) |
Sets the prefix as being used by the locator. More... | |
void | setEnabled (bool enabled) |
Sets whether the filter is enabled. More... | |
void | setFetchResultsDelay (int delay) |
Sets a delay (in milliseconds) for the filter to wait prior to fetching results. More... | |
void | setUseWithoutPrefix (bool useWithoutPrefix) |
Sets whether the filter should be used when no prefix is entered. More... | |
virtual void | triggerResult (const QgsLocatorResult &result)=0 |
Triggers a filter result from this filter. More... | |
virtual void | triggerResultFromAction (const QgsLocatorResult &result, const int actionId) |
Triggers a filter result from this filter for an entry in the context menu. More... | |
bool | useWithoutPrefix () const |
Returns true if the filter should be used when no prefix is entered. More... | |
Static Public Member Functions | |
static double | fuzzyScore (const QString &candidate, const QString &search) |
Tests a candidate string to see how likely it is a match for a specified search string. More... | |
static bool | stringMatches (const QString &candidate, const QString &search) |
Tests a candidate string to see if it should be considered a match for a specified search string. More... | |
Abstract base class for filters which collect locator results.
Definition at line 152 of file qgslocatorfilter.h.
Flags for locator behavior.
Enumerator | |
---|---|
FlagFast | Filter finds results quickly and can be safely run in the main thread. |
Definition at line 170 of file qgslocatorfilter.h.
Filter priority. Controls the order of results in the locator.
Enumerator | |
---|---|
Highest | Highest priority. |
High | High priority. |
Medium | Medium priority. |
Low | Low priority. |
Lowest | Lowest priority. |
Definition at line 159 of file qgslocatorfilter.h.
QgsLocatorFilter::QgsLocatorFilter | ( | QObject * | parent = nullptr | ) |
Constructor for QgsLocatorFilter.
Definition at line 26 of file qgslocatorfilter.cpp.
QString QgsLocatorFilter::activePrefix | ( | ) | const |
Returns the prefix in use in the locator is entered.
Definition at line 82 of file qgslocatorfilter.cpp.
|
inlinevirtual |
This method will be called on main thread on the original filter (not a clone) before fetching results or before triggering a result to clear any change made by a former call to triggerResult.
For instance, this can be used to remove any on-canvas rubber bands which have been created when a previous search result was triggered.
Definition at line 282 of file qgslocatorfilter.h.
|
pure virtual |
Creates a clone of the filter.
New requests are always executed in a clone of the original filter.
|
inlinevirtual |
Returns a translated, description for the filter.
Definition at line 204 of file qgslocatorfilter.h.
|
pure virtual |
Returns a translated, user-friendly name for the filter.
bool QgsLocatorFilter::enabled | ( | ) | const |
Returns true
if the filter is enabled.
Definition at line 52 of file qgslocatorfilter.cpp.
|
pure virtual |
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.
|
inline |
Returns the delay (in milliseconds) for the filter to wait prior to fetching results.
Definition at line 368 of file qgslocatorfilter.h.
|
signal |
Emitted when the filter finishes fetching results.
|
virtual |
Returns flags which specify the filter's behavior.
Definition at line 31 of file qgslocatorfilter.cpp.
|
static |
Tests a candidate string to see how likely it is a match for a specified search string.
Definition at line 47 of file qgslocatorfilter.cpp.
|
virtual |
Should return true
if the filter has a configuration widget.
Definition at line 62 of file qgslocatorfilter.cpp.
void QgsLocatorFilter::logMessage | ( | const QString & | message, |
Qgis::MessageLevel | level = Qgis::MessageLevel::Info |
||
) |
Logs a message to the log panel.
Definition at line 98 of file qgslocatorfilter.cpp.
|
pure virtual |
Returns the unique name for the filter.
This should be an untranslated string identifying the filter.
|
virtual |
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.
true
to indicate that the filter supports configuration. Definition at line 67 of file qgslocatorfilter.cpp.
|
inlinevirtual |
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.
Definition at line 228 of file qgslocatorfilter.h.
|
inlinevirtual |
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. The method returns an autocompletion list
Definition at line 237 of file qgslocatorfilter.h.
|
inlinevirtual |
Returns the priority for the filter, which controls how results are ordered in the locator.
Definition at line 215 of file qgslocatorfilter.h.
|
signal |
Should be emitted by filters whenever they encounter a matching result during within their fetchResults() implementation.
void QgsLocatorFilter::setActivePrefix | ( | const QString & | activePrefix | ) |
Sets the prefix as being used by the locator.
Definition at line 93 of file qgslocatorfilter.cpp.
void QgsLocatorFilter::setEnabled | ( | bool | enabled | ) |
Sets whether the filter is enabled.
Definition at line 57 of file qgslocatorfilter.cpp.
|
inline |
Sets a delay (in milliseconds) for the filter to wait prior to fetching results.
Definition at line 376 of file qgslocatorfilter.h.
void QgsLocatorFilter::setUseWithoutPrefix | ( | bool | useWithoutPrefix | ) |
Sets whether the filter should be used when no prefix is entered.
Definition at line 77 of file qgslocatorfilter.cpp.
|
static |
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.
Definition at line 42 of file qgslocatorfilter.cpp.
|
pure virtual |
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.
|
virtual |
Triggers a filter result from this filter for an entry in the context menu.
The entry is identified by its actionId as specified in the result of this filter.
Definition at line 36 of file qgslocatorfilter.cpp.
bool QgsLocatorFilter::useWithoutPrefix | ( | ) | const |
Returns true
if the filter should be used when no prefix is entered.
Definition at line 72 of file qgslocatorfilter.cpp.