diff --git a/python/gui/locator/qgslocatorfilter.sip b/python/gui/locator/qgslocatorfilter.sip index a3a9a9ab5d4..a3948cc9e92 100644 --- a/python/gui/locator/qgslocatorfilter.sip +++ b/python/gui/locator/qgslocatorfilter.sip @@ -139,6 +139,21 @@ class QgsLocatorFilter : QObject result. %End + bool useWithoutPrefix() const; +%Docstring + Returns true if the filter should be used when no prefix + is entered. +.. seealso:: setUseWithoutPrefix() + :rtype: bool +%End + + void setUseWithoutPrefix( bool useWithoutPrefix ); +%Docstring + Sets whether the filter should be used when no prefix + is entered. +.. seealso:: useWithoutPrefix() +%End + signals: void resultFetched( const QgsLocatorResult &result ); diff --git a/src/app/locator/qgsinbuiltlocatorfilters.cpp b/src/app/locator/qgsinbuiltlocatorfilters.cpp index d59a1cfdf2f..8319e80747b 100644 --- a/src/app/locator/qgsinbuiltlocatorfilters.cpp +++ b/src/app/locator/qgsinbuiltlocatorfilters.cpp @@ -103,7 +103,7 @@ QgsActionLocatorFilter::QgsActionLocatorFilter( const QList &parentOb : QgsLocatorFilter( parent ) , mActionParents( parentObjectsForActions ) { - + setUseWithoutPrefix( false ); } void QgsActionLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) diff --git a/src/gui/locator/qgslocator.cpp b/src/gui/locator/qgslocator.cpp index 57c9d0edd3b..f90bbb1d258 100644 --- a/src/gui/locator/qgslocator.cpp +++ b/src/gui/locator/qgslocator.cpp @@ -89,18 +89,25 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c } mFeedback = feedback; - mActiveFilters = mFilters; + mActiveFilters.clear(); QString searchString = string; if ( searchString.indexOf( ' ' ) > 0 ) { QString prefix = searchString.left( searchString.indexOf( ' ' ) ); if ( mPrefixedFilters.contains( prefix ) ) { - mActiveFilters.clear(); mActiveFilters << mPrefixedFilters.value( prefix ); searchString = searchString.mid( prefix.length() + 1 ); } } + if ( mActiveFilters.isEmpty() ) + { + Q_FOREACH ( QgsLocatorFilter *filter, mFilters ) + { + if ( filter->useWithoutPrefix() ) + mActiveFilters << filter; + } + } auto gatherFilterResults = [searchString, context, feedback]( QgsLocatorFilter * filter ) { diff --git a/src/gui/locator/qgslocatorfilter.cpp b/src/gui/locator/qgslocatorfilter.cpp index b2126b0c08a..819627e904f 100644 --- a/src/gui/locator/qgslocatorfilter.cpp +++ b/src/gui/locator/qgslocatorfilter.cpp @@ -23,3 +23,18 @@ QgsLocatorFilter::QgsLocatorFilter( QObject *parent ) { } + +bool QgsLocatorFilter::stringMatches( const QString &test, const QString &match ) +{ + return QgsStringUtils::containsFuzzy( match, test ); +} + +bool QgsLocatorFilter::useWithoutPrefix() const +{ + return mUseWithoutPrefix; +} + +void QgsLocatorFilter::setUseWithoutPrefix( bool useWithoutPrefix ) +{ + mUseWithoutPrefix = useWithoutPrefix; +} diff --git a/src/gui/locator/qgslocatorfilter.h b/src/gui/locator/qgslocatorfilter.h index 20331a5fe59..187fd8c13ca 100644 --- a/src/gui/locator/qgslocatorfilter.h +++ b/src/gui/locator/qgslocatorfilter.h @@ -154,6 +154,20 @@ class GUI_EXPORT QgsLocatorFilter : public QObject */ virtual void triggerResult( const QgsLocatorResult &result ) = 0; + /** + * Returns true if the filter should be used when no prefix + * is entered. + * \see setUseWithoutPrefix() + */ + bool useWithoutPrefix() const; + + /** + * Sets whether the filter should be used when no prefix + * is entered. + * \see useWithoutPrefix() + */ + void setUseWithoutPrefix( bool useWithoutPrefix ); + signals: /** @@ -162,6 +176,10 @@ class GUI_EXPORT QgsLocatorFilter : public QObject */ void resultFetched( const QgsLocatorResult &result ); + private: + + bool mUseWithoutPrefix = true; + }; Q_DECLARE_METATYPE( QgsLocatorResult )