@@ -44,18 +44,24 @@ void QgsLocator::deregisterFilter( QgsLocatorFilter *filter )
4444{
4545 cancelRunningQuery ();
4646 mFilters .removeAll ( filter );
47- QString key = mPrefixedFilters .key ( filter );
48- if ( !key.isEmpty () )
49- mPrefixedFilters .remove ( key );
47+ mPrefixedFilters .remove ( mPrefixedFilters .key ( filter ), filter );
5048 delete filter;
5149}
5250
53- QList<QgsLocatorFilter *> QgsLocator::filters ()
51+ QList<QgsLocatorFilter *> QgsLocator::filters ( const QString &prefix )
5452{
55- return mFilters ;
53+ if ( !prefix.isEmpty () )
54+ return mPrefixedFilters .values ( prefix );
55+ else
56+ return mFilters ;
57+ }
58+
59+ QStringList QgsLocator::prefixes ()
60+ {
61+ return mPrefixedFilters .keys ();
5662}
5763
58- QMap <QString, QgsLocatorFilter *> QgsLocator::prefixedFilters () const
64+ QMultiMap <QString, QgsLocatorFilter *> QgsLocator::prefixedFilters () const
5965{
6066 return mPrefixedFilters ;
6167}
@@ -64,12 +70,18 @@ void QgsLocator::setCustomPrefix( QgsLocatorFilter *filter, const QString &prefi
6470{
6571 if ( filter )
6672 {
67- QgsSettings ().setValue ( QStringLiteral ( " locator_filters/prefix_%1" ).arg ( filter->name () ), prefix, QgsSettings::Section::Gui );
68- QString oldPrefix = mPrefixedFilters .key ( filter );
69- if ( !oldPrefix.isEmpty () )
70- mPrefixedFilters .remove ( oldPrefix );
71-
72- mPrefixedFilters .insert ( prefix, filter );
73+ mPrefixedFilters .remove ( mPrefixedFilters .key ( filter ), filter );
74+ if ( !prefix.isEmpty () && prefix != filter->prefix () )
75+ {
76+ QgsSettings ().setValue ( QStringLiteral ( " locator_filters/prefix_%1" ).arg ( filter->name () ), prefix, QgsSettings::Section::Gui );
77+ mPrefixedFilters .insert ( prefix, filter );
78+ }
79+ else
80+ {
81+ // reset the setting if the string is empty or equal to the native prefix
82+ // one should the default checkbox instead
83+ QgsSettings ().remove ( QStringLiteral ( " locator_filters/prefix_%1" ).arg ( filter->name () ), QgsSettings::Section::Gui );
84+ }
7385 }
7486}
7587
@@ -129,17 +141,26 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
129141
130142 QList< QgsLocatorFilter * > activeFilters;
131143 QString searchString = string;
132- if ( searchString.indexOf ( ' ' ) > 0 )
144+ QString prefix = searchString.left ( std::max ( searchString.indexOf ( ' ' ), 0 ) );
145+ if ( !prefix.isEmpty () )
133146 {
134- QString prefix = searchString. left ( searchString. indexOf ( ' ' ) );
135- if ( mPrefixedFilters .contains ( prefix ) && mPrefixedFilters . value ( prefix )-> enabled () )
147+ QMultiMap< QString, QgsLocatorFilter *>::const_iterator it = mPrefixedFilters . constFind ( prefix );
148+ while ( it != mPrefixedFilters .constEnd ( ) && it. key () == prefix )
136149 {
137- activeFilters << mPrefixedFilters .value ( prefix );
138- searchString = searchString.mid ( prefix.length () + 1 );
150+ QgsLocatorFilter *filter = it.value ();
151+ if ( filter->enabled () )
152+ {
153+ activeFilters << filter;
154+ }
155+ ++it;
139156 }
140157 context.usingPrefix = !activeFilters.empty ();
141158 }
142- if ( activeFilters.isEmpty () )
159+ if ( !activeFilters.isEmpty () )
160+ {
161+ searchString = searchString.mid ( prefix.length () + 1 );
162+ }
163+ else
143164 {
144165 for ( QgsLocatorFilter *filter : qgis::as_const ( mFilters ) )
145166 {
0 commit comments