20 #include <QtConcurrent>
24 << QStringLiteral(
"processing_alg" )
25 << QStringLiteral(
"layertree" )
26 << QStringLiteral(
"layouts" )
27 << QStringLiteral(
"features" )
28 << QStringLiteral(
"allfeatures" )
29 << QStringLiteral(
"calculator" )
30 << QStringLiteral(
"bookmarks" )
31 << QStringLiteral(
"optionpages" )
32 << QStringLiteral(
"edit_features" );
37 qRegisterMetaType<QgsLocatorResult>(
"QgsLocatorResult" );
43 qDeleteAll( mFilters );
49 mFilters.removeAll( filter );
55 if ( !prefix.isEmpty() )
57 QList<QgsLocatorFilter *>
filters = QList<QgsLocatorFilter *>();
60 if ( !filter->activePrefix().isEmpty() && filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 )
75 QMap<QString, QgsLocatorFilter *>
filters = QMap<QString, QgsLocatorFilter *>();
78 if ( !filter->activePrefix().isEmpty() && filter->enabled() )
80 filters.insertMulti( filter->activePrefix(), filter );
88 mFilters.append( filter );
89 filter->setParent(
this );
93 bool enabled = settings.
value( QStringLiteral(
"locator_filters/enabled_%1" ).arg( filter->
name() ),
true, QgsSettings::Section::Gui ).toBool();
94 bool byDefault = settings.
value( QStringLiteral(
"locator_filters/default_%1" ).arg( filter->
name() ), filter->
useWithoutPrefix(), QgsSettings::Section::Gui ).toBool();
95 QString prefix = settings.
value( QStringLiteral(
"locator_filters/prefix_%1" ).arg( filter->
name() ), filter->
prefix(), QgsSettings::Section::Gui ).toString();
96 if ( prefix.isEmpty() )
101 if ( !prefix.isEmpty() )
108 else if ( prefix.length() >= 3 || prefix != filter->
prefix() )
130 cancelRunningQuery();
137 feedback = mOwnedFeedback.get();
141 mOwnedFeedback.reset(
nullptr );
143 mFeedback = feedback;
145 QList< QgsLocatorFilter * > activeFilters;
146 QString searchString = string;
147 QString prefix = searchString.left( std::max( searchString.indexOf(
' ' ), 0 ) );
148 if ( !prefix.isEmpty() )
152 if ( filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 && filter->enabled() )
154 activeFilters << filter;
159 if ( !activeFilters.isEmpty() )
161 searchString = searchString.mid( prefix.length() + 1 );
167 if ( filter->useWithoutPrefix() && filter->enabled() )
169 activeFilters << filter;
174 QList< QgsLocatorFilter *> threadedFilters;
177 filter->clearPreviousResults();
178 std::unique_ptr< QgsLocatorFilter > clone( filter->clone() );
181 result.filter = filter;
182 filterSentResult( result );
184 clone->prepare( searchString, context );
189 clone->fetchResults( searchString, context, feedback );
194 threadedFilters.append( clone.release() );
198 mActiveThreads.clear();
201 QThread *thread =
new QThread();
202 mActiveThreads.append( thread );
203 filter->moveToThread( thread );
204 connect( thread, &QThread::started, filter, [filter, searchString, context, feedback]
207 filter->fetchResults( searchString, context, feedback );
209 }, Qt::QueuedConnection );
212 connect( thread, &QThread::finished, thread, [
this, thread]
214 mActiveThreads.removeAll( thread );
215 if ( mActiveThreads.empty() )
218 connect( thread, &QThread::finished, thread, &QThread::deleteLater );
222 if ( mActiveThreads.empty() )
228 cancelRunningQuery();
239 return !mActiveThreads.empty();
246 if ( filter->enabled() )
248 filter->clearPreviousResults();
262 void QgsLocator::cancelRunningQuery()
264 if ( !mActiveThreads.empty() )
268 while ( !mActiveThreads.empty() )
270 QCoreApplication::processEvents();