Skip to content

Commit a53516d

Browse files
committedMay 17, 2017
Only show action results when . prefix is used
1 parent 102a466 commit a53516d

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed
 

‎python/gui/locator/qgslocatorfilter.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ class QgsLocatorFilter : QObject
139139
result.
140140
%End
141141

142+
bool useWithoutPrefix() const;
143+
%Docstring
144+
Returns true if the filter should be used when no prefix
145+
is entered.
146+
.. seealso:: setUseWithoutPrefix()
147+
:rtype: bool
148+
%End
149+
150+
void setUseWithoutPrefix( bool useWithoutPrefix );
151+
%Docstring
152+
Sets whether the filter should be used when no prefix
153+
is entered.
154+
.. seealso:: useWithoutPrefix()
155+
%End
156+
142157
signals:
143158

144159
void resultFetched( const QgsLocatorResult &result );

‎src/app/locator/qgsinbuiltlocatorfilters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ QgsActionLocatorFilter::QgsActionLocatorFilter( const QList<QWidget *> &parentOb
103103
: QgsLocatorFilter( parent )
104104
, mActionParents( parentObjectsForActions )
105105
{
106-
106+
setUseWithoutPrefix( false );
107107
}
108108

109109
void QgsActionLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback )

‎src/gui/locator/qgslocator.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,25 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
8989
}
9090
mFeedback = feedback;
9191

92-
mActiveFilters = mFilters;
92+
mActiveFilters.clear();
9393
QString searchString = string;
9494
if ( searchString.indexOf( ' ' ) > 0 )
9595
{
9696
QString prefix = searchString.left( searchString.indexOf( ' ' ) );
9797
if ( mPrefixedFilters.contains( prefix ) )
9898
{
99-
mActiveFilters.clear();
10099
mActiveFilters << mPrefixedFilters.value( prefix );
101100
searchString = searchString.mid( prefix.length() + 1 );
102101
}
103102
}
103+
if ( mActiveFilters.isEmpty() )
104+
{
105+
Q_FOREACH ( QgsLocatorFilter *filter, mFilters )
106+
{
107+
if ( filter->useWithoutPrefix() )
108+
mActiveFilters << filter;
109+
}
110+
}
104111

105112
auto gatherFilterResults = [searchString, context, feedback]( QgsLocatorFilter * filter )
106113
{

‎src/gui/locator/qgslocatorfilter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ QgsLocatorFilter::QgsLocatorFilter( QObject *parent )
2323
{
2424

2525
}
26+
27+
bool QgsLocatorFilter::stringMatches( const QString &test, const QString &match )
28+
{
29+
return QgsStringUtils::containsFuzzy( match, test );
30+
}
31+
32+
bool QgsLocatorFilter::useWithoutPrefix() const
33+
{
34+
return mUseWithoutPrefix;
35+
}
36+
37+
void QgsLocatorFilter::setUseWithoutPrefix( bool useWithoutPrefix )
38+
{
39+
mUseWithoutPrefix = useWithoutPrefix;
40+
}

‎src/gui/locator/qgslocatorfilter.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ class GUI_EXPORT QgsLocatorFilter : public QObject
154154
*/
155155
virtual void triggerResult( const QgsLocatorResult &result ) = 0;
156156

157+
/**
158+
* Returns true if the filter should be used when no prefix
159+
* is entered.
160+
* \see setUseWithoutPrefix()
161+
*/
162+
bool useWithoutPrefix() const;
163+
164+
/**
165+
* Sets whether the filter should be used when no prefix
166+
* is entered.
167+
* \see useWithoutPrefix()
168+
*/
169+
void setUseWithoutPrefix( bool useWithoutPrefix );
170+
157171
signals:
158172

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

179+
private:
180+
181+
bool mUseWithoutPrefix = true;
182+
165183
};
166184

167185
Q_DECLARE_METATYPE( QgsLocatorResult )

0 commit comments

Comments
 (0)
Please sign in to comment.