Skip to content
Permalink
Browse files

[locator] add clearPreviousResults virtual method (#7256)

* [locator] add clearPreviousResults virtual method

* also clear previous results when triggering result
  • Loading branch information
3nids committed Jun 17, 2018
1 parent 7a9b298 commit 85038966748c6a9c5e0dc2c379c8bcc5a7dff93f
@@ -123,6 +123,13 @@ take some time to cancel after calling this.
bool isRunning() const;
%Docstring
Returns true if a query is currently being executed by the locator.
%End

void clearPreviousResults();
%Docstring
Will call clearPreviousResults on all filters

.. versionadded:: 3.2
%End

signals:
@@ -172,6 +172,17 @@ by a user. The filter subclass must implement logic here
to perform the desired operation for the search result.
E.g. a file search filter would open file associated with the triggered
result.
%End

virtual void clearPreviousResults();
%Docstring
This method will be called on main thread on the original filter (not a clone)
before fetching results or before triggering a result to clear any change made
by a former call to triggerResult.
For instance, this can be used to remove any on-canvas rubber bands which have been created
when a previous search result was triggered.

.. versionadded:: 3.2
%End

bool useWithoutPrefix() const;
@@ -172,6 +172,7 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
QList< QgsLocatorFilter *> threadedFilters;
for ( QgsLocatorFilter *filter : qgis::as_const( activeFilters ) )
{
filter->clearPreviousResults();
std::unique_ptr< QgsLocatorFilter > clone( filter->clone() );
connect( clone.get(), &QgsLocatorFilter::resultFetched, clone.get(), [this, filter]( QgsLocatorResult result )
{
@@ -236,6 +237,17 @@ bool QgsLocator::isRunning() const
return !mActiveThreads.empty();
}

void QgsLocator::clearPreviousResults()
{
for ( QgsLocatorFilter *filter : qgis::as_const( mFilters ) )
{
if ( filter->enabled() )
{
filter->clearPreviousResults();
}
}
}

void QgsLocator::filterSentResult( QgsLocatorResult result )
{
// if query has been canceled then discard any results we receive
@@ -139,6 +139,12 @@ class CORE_EXPORT QgsLocator : public QObject
*/
bool isRunning() const;

/**
* Will call clearPreviousResults on all filters
* \since QGIS 3.2
*/
void clearPreviousResults();

signals:

/**
@@ -207,6 +207,16 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
*/
virtual void triggerResult( const QgsLocatorResult &result ) = 0;

/**
* This method will be called on main thread on the original filter (not a clone)
* before fetching results or before triggering a result to clear any change made
* by a former call to triggerResult.
* For instance, this can be used to remove any on-canvas rubber bands which have been created
* when a previous search result was triggered.
* \since QGIS 3.2
*/
virtual void clearPreviousResults() {}

/**
* Returns true if the filter should be used when no prefix
* is entered.
@@ -339,6 +339,7 @@ void QgsLocatorWidget::acceptCurrentEntry()
QgsLocatorResult result = mProxyModel->data( index, QgsLocatorModel::ResultDataRole ).value< QgsLocatorResult >();
mResultsContainer->hide();
mLineEdit->clearFocus();
mLocator->clearPreviousResults();
result.filter->triggerResult( result );
}
}

0 comments on commit 8503896

Please sign in to comment.
You can’t perform that action at this time.