21 #include <QtConcurrent>
25 << QStringLiteral(
"processing_alg" )
26 << QStringLiteral(
"layertree" )
27 << QStringLiteral(
"layouts" )
28 << QStringLiteral(
"features" )
29 << QStringLiteral(
"allfeatures" )
30 << QStringLiteral(
"calculator" )
31 << QStringLiteral(
"bookmarks" )
32 << QStringLiteral(
"optionpages" )
33 << QStringLiteral(
"edit_features" )
34 << QStringLiteral(
"goto" )
35 << QStringLiteral(
"nominatimgeocoder" ) ;
40 qRegisterMetaType<QgsLocatorResult>(
"QgsLocatorResult" );
46 qDeleteAll( mFilters );
52 mFilters.removeAll( filter );
58 if ( !prefix.isEmpty() )
60 QList<QgsLocatorFilter *>
filters = QList<QgsLocatorFilter *>();
63 if ( !filter->activePrefix().isEmpty() && filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 )
78 QMap<QString, QgsLocatorFilter *>
filters = QMap<QString, QgsLocatorFilter *>();
81 if ( !filter->activePrefix().isEmpty() && filter->enabled() )
83 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
84 filters.insertMulti( filter->activePrefix(), filter );
86 filters.insert( filter->activePrefix(), filter );
95 mFilters.append( filter );
96 filter->setParent(
this );
102 if ( prefix.isEmpty() )
104 prefix = filter->
prefix();
107 if ( !prefix.isEmpty() )
114 else if ( prefix.length() >= 3 || prefix != filter->
prefix() )
132 mAutocompletionList.clear();
138 cancelRunningQuery();
145 feedback = mOwnedFeedback.get();
149 mOwnedFeedback.reset(
nullptr );
151 mFeedback = feedback;
153 QList< QgsLocatorFilter * > activeFilters;
154 QString searchString = string;
155 QString prefix = searchString.left( std::max(
static_cast<int>( searchString.indexOf(
' ' ) ), 0 ) );
156 if ( !prefix.isEmpty() )
160 if ( filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 && filter->enabled() )
162 activeFilters << filter;
167 if ( !activeFilters.isEmpty() )
169 searchString = searchString.mid( prefix.length() + 1 );
175 if ( filter->useWithoutPrefix() && filter->enabled() )
177 activeFilters << filter;
182 QList< QgsLocatorFilter *> threadedFilters;
185 filter->clearPreviousResults();
186 std::unique_ptr< QgsLocatorFilter > clone( filter->clone() );
189 QgsMessageLog::logMessage( tr(
"QgsLocatorFilter '%1' could not provide a valid clone" ).arg( filter->name() ), QString(), Qgis::MessageLevel::Critical );
194 result.filter = filter;
195 filterSentResult( result );
197 QStringList autoCompleteList = clone->prepare( searchString, context );
200 for (
int i = 0; i < autoCompleteList.length(); i++ )
202 autoCompleteList[i].prepend( QStringLiteral(
"%1 " ).arg( prefix ) );
205 mAutocompletionList.append( autoCompleteList );
210 clone->fetchResults( searchString, context, feedback );
214 threadedFilters.append( clone.release() );
218 mActiveThreads.clear();
221 QThread *thread =
new QThread();
222 mActiveThreads.append( thread );
223 filter->moveToThread( thread );
224 connect( thread, &QThread::started, filter, [filter, searchString, context, feedback]
226 int delay = filter->fetchResultsDelay();
231 QThread::msleep( 50 );
235 filter->fetchResults( searchString, context, feedback );
237 }, Qt::QueuedConnection );
240 connect( thread, &QThread::finished, thread, [
this, thread]
242 mActiveThreads.removeAll( thread );
243 if ( mActiveThreads.empty() )
246 connect( thread, &QThread::finished, thread, &QThread::deleteLater );
252 if ( mActiveThreads.empty() )
258 cancelRunningQuery();
269 return !mActiveThreads.empty();
276 if ( filter->enabled() )
278 filter->clearPreviousResults();
292 void QgsLocator::cancelRunningQuery()
294 if ( !mActiveThreads.empty() )
298 while ( !mActiveThreads.empty() )
300 QCoreApplication::processEvents();