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" )
33 << QStringLiteral(
"goto" );
38 qRegisterMetaType<QgsLocatorResult>(
"QgsLocatorResult" );
44 qDeleteAll( mFilters );
50 mFilters.removeAll( filter );
56 if ( !prefix.isEmpty() )
58 QList<QgsLocatorFilter *>
filters = QList<QgsLocatorFilter *>();
61 if ( !filter->activePrefix().isEmpty() && filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 )
76 QMap<QString, QgsLocatorFilter *>
filters = QMap<QString, QgsLocatorFilter *>();
79 if ( !filter->activePrefix().isEmpty() && filter->enabled() )
81 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
82 filters.insertMulti( filter->activePrefix(), filter );
84 filters.insert( filter->activePrefix(), filter );
93 mFilters.append( filter );
94 filter->setParent(
this );
98 bool enabled = settings.
value( QStringLiteral(
"locator_filters/enabled_%1" ).arg( filter->
name() ),
true, QgsSettings::Section::Gui ).toBool();
99 bool byDefault = settings.
value( QStringLiteral(
"locator_filters/default_%1" ).arg( filter->
name() ), filter->
useWithoutPrefix(), QgsSettings::Section::Gui ).toBool();
100 QString prefix = settings.
value( QStringLiteral(
"locator_filters/prefix_%1" ).arg( filter->
name() ), filter->
prefix(), QgsSettings::Section::Gui ).toString();
101 if ( prefix.isEmpty() )
103 prefix = filter->
prefix();
106 if ( !prefix.isEmpty() )
113 else if ( prefix.length() >= 3 || prefix != filter->
prefix() )
131 mAutocompletionList.clear();
137 cancelRunningQuery();
144 feedback = mOwnedFeedback.get();
148 mOwnedFeedback.reset(
nullptr );
150 mFeedback = feedback;
152 QList< QgsLocatorFilter * > activeFilters;
153 QString searchString = string;
154 QString prefix = searchString.left( std::max( searchString.indexOf(
' ' ), 0 ) );
155 if ( !prefix.isEmpty() )
159 if ( filter->activePrefix().compare( prefix, Qt::CaseInsensitive ) == 0 && filter->enabled() )
161 activeFilters << filter;
166 if ( !activeFilters.isEmpty() )
168 searchString = searchString.mid( prefix.length() + 1 );
174 if ( filter->useWithoutPrefix() && filter->enabled() )
176 activeFilters << filter;
181 QList< QgsLocatorFilter *> threadedFilters;
184 filter->clearPreviousResults();
185 std::unique_ptr< QgsLocatorFilter > clone( filter->clone() );
188 result.filter = filter;
189 filterSentResult( result );
191 QStringList autoCompleteList = clone->prepare( searchString, context );
194 for (
int i = 0; i < autoCompleteList.length(); i++ )
196 autoCompleteList[i].prepend( QStringLiteral(
"%1 " ).arg( prefix ) );
199 mAutocompletionList.append( autoCompleteList );
204 clone->fetchResults( searchString, context, feedback );
208 threadedFilters.append( clone.release() );
212 mActiveThreads.clear();
215 QThread *thread =
new QThread();
216 mActiveThreads.append( thread );
217 filter->moveToThread( thread );
218 connect( thread, &QThread::started, filter, [filter, searchString, context, feedback]
221 filter->fetchResults( searchString, context, feedback );
223 }, Qt::QueuedConnection );
226 connect( thread, &QThread::finished, thread, [
this, thread]
228 mActiveThreads.removeAll( thread );
229 if ( mActiveThreads.empty() )
232 connect( thread, &QThread::finished, thread, &QThread::deleteLater );
238 if ( mActiveThreads.empty() )
244 cancelRunningQuery();
255 return !mActiveThreads.empty();
262 if ( filter->enabled() )
264 filter->clearPreviousResults();
278 void QgsLocator::cancelRunningQuery()
280 if ( !mActiveThreads.empty() )
284 while ( !mActiveThreads.empty() )
286 QCoreApplication::processEvents();