Skip to content

Commit

Permalink
Only show action results when . prefix is used
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 17, 2017
1 parent 102a466 commit a53516d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
15 changes: 15 additions & 0 deletions python/gui/locator/qgslocatorfilter.sip
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -103,7 +103,7 @@ QgsActionLocatorFilter::QgsActionLocatorFilter( const QList<QWidget *> &parentOb
: QgsLocatorFilter( parent )
, mActionParents( parentObjectsForActions )
{

setUseWithoutPrefix( false );
}

void QgsActionLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback )
Expand Down
11 changes: 9 additions & 2 deletions src/gui/locator/qgslocator.cpp
Expand Up @@ -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 )
{
Expand Down
15 changes: 15 additions & 0 deletions src/gui/locator/qgslocatorfilter.cpp
Expand Up @@ -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;
}
18 changes: 18 additions & 0 deletions src/gui/locator/qgslocatorfilter.h
Expand Up @@ -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:

/**
Expand All @@ -162,6 +176,10 @@ class GUI_EXPORT QgsLocatorFilter : public QObject
*/
void resultFetched( const QgsLocatorResult &result );

private:

bool mUseWithoutPrefix = true;

};

Q_DECLARE_METATYPE( QgsLocatorResult )
Expand Down

0 comments on commit a53516d

Please sign in to comment.