Skip to content

Commit 8503896

Browse files
authored
[locator] add clearPreviousResults virtual method (#7256)
* [locator] add clearPreviousResults virtual method * also clear previous results when triggering result
1 parent 7a9b298 commit 8503896

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

python/core/auto_generated/locator/qgslocator.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ take some time to cancel after calling this.
123123
bool isRunning() const;
124124
%Docstring
125125
Returns true if a query is currently being executed by the locator.
126+
%End
127+
128+
void clearPreviousResults();
129+
%Docstring
130+
Will call clearPreviousResults on all filters
131+
132+
.. versionadded:: 3.2
126133
%End
127134

128135
signals:

python/core/auto_generated/locator/qgslocatorfilter.sip.in

+11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ by a user. The filter subclass must implement logic here
172172
to perform the desired operation for the search result.
173173
E.g. a file search filter would open file associated with the triggered
174174
result.
175+
%End
176+
177+
virtual void clearPreviousResults();
178+
%Docstring
179+
This method will be called on main thread on the original filter (not a clone)
180+
before fetching results or before triggering a result to clear any change made
181+
by a former call to triggerResult.
182+
For instance, this can be used to remove any on-canvas rubber bands which have been created
183+
when a previous search result was triggered.
184+
185+
.. versionadded:: 3.2
175186
%End
176187

177188
bool useWithoutPrefix() const;

src/core/locator/qgslocator.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
172172
QList< QgsLocatorFilter *> threadedFilters;
173173
for ( QgsLocatorFilter *filter : qgis::as_const( activeFilters ) )
174174
{
175+
filter->clearPreviousResults();
175176
std::unique_ptr< QgsLocatorFilter > clone( filter->clone() );
176177
connect( clone.get(), &QgsLocatorFilter::resultFetched, clone.get(), [this, filter]( QgsLocatorResult result )
177178
{
@@ -236,6 +237,17 @@ bool QgsLocator::isRunning() const
236237
return !mActiveThreads.empty();
237238
}
238239

240+
void QgsLocator::clearPreviousResults()
241+
{
242+
for ( QgsLocatorFilter *filter : qgis::as_const( mFilters ) )
243+
{
244+
if ( filter->enabled() )
245+
{
246+
filter->clearPreviousResults();
247+
}
248+
}
249+
}
250+
239251
void QgsLocator::filterSentResult( QgsLocatorResult result )
240252
{
241253
// if query has been canceled then discard any results we receive

src/core/locator/qgslocator.h

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class CORE_EXPORT QgsLocator : public QObject
139139
*/
140140
bool isRunning() const;
141141

142+
/**
143+
* Will call clearPreviousResults on all filters
144+
* \since QGIS 3.2
145+
*/
146+
void clearPreviousResults();
147+
142148
signals:
143149

144150
/**

src/core/locator/qgslocatorfilter.h

+10
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
207207
*/
208208
virtual void triggerResult( const QgsLocatorResult &result ) = 0;
209209

210+
/**
211+
* This method will be called on main thread on the original filter (not a clone)
212+
* before fetching results or before triggering a result to clear any change made
213+
* by a former call to triggerResult.
214+
* For instance, this can be used to remove any on-canvas rubber bands which have been created
215+
* when a previous search result was triggered.
216+
* \since QGIS 3.2
217+
*/
218+
virtual void clearPreviousResults() {}
219+
210220
/**
211221
* Returns true if the filter should be used when no prefix
212222
* is entered.

src/gui/locator/qgslocatorwidget.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ void QgsLocatorWidget::acceptCurrentEntry()
339339
QgsLocatorResult result = mProxyModel->data( index, QgsLocatorModel::ResultDataRole ).value< QgsLocatorResult >();
340340
mResultsContainer->hide();
341341
mLineEdit->clearFocus();
342+
mLocator->clearPreviousResults();
342343
result.filter->triggerResult( result );
343344
}
344345
}

0 commit comments

Comments
 (0)