Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 12, 2018
1 parent 7609ab7 commit 44df58e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
9 changes: 3 additions & 6 deletions python/core/locator/qgslocatorfilter.sip.in
Expand Up @@ -132,12 +132,6 @@ Prepares the filter instance for an upcoming search for the specified ``string``
from the main thread, and individual filter subclasses should perform whatever
tasks are required in order to allow a subsequent search to safely execute
on a background thread.
%End

void executeSearchAndDelete( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback );
%Docstring
Executes a search for this filter instance, and then deletes the current instance
of the filter.
%End

virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;
Expand All @@ -152,6 +146,9 @@ signal whenever they encounter a matching result.
Subclasses should periodically check the ``feedback`` object to determine
whether the query has been canceled. If so, the subclass should return
from this method as soon as possible.

This will be called from a background thread unless flags() returns the
QgsLocatorFilter.FlagFast flag.
%End

virtual void triggerResult( const QgsLocatorResult &result ) = 0;
Expand Down
9 changes: 4 additions & 5 deletions src/core/locator/qgslocator.cpp
Expand Up @@ -152,12 +152,11 @@ void QgsLocator::fetchResults( const QString &string, const QgsLocatorContext &c
filter->moveToThread( thread );
connect( thread, &QThread::started, filter, [filter, searchString, context, feedback]
{
filter->executeSearchAndDelete( searchString, context, feedback );
if ( !feedback->isCanceled() )
filter->fetchResults( searchString, context, feedback );
filter->emit finished();
}, Qt::QueuedConnection );
connect( filter, &QgsLocatorFilter::finished, thread, [thread]
{
thread->quit();
} );
connect( filter, &QgsLocatorFilter::finished, thread, &QThread::quit );
connect( filter, &QgsLocatorFilter::finished, filter, &QgsLocatorFilter::deleteLater );
connect( thread, &QThread::finished, thread, [this, thread]
{
Expand Down
7 changes: 0 additions & 7 deletions src/core/locator/qgslocatorfilter.cpp
Expand Up @@ -32,13 +32,6 @@ QgsLocatorFilter::Flags QgsLocatorFilter::flags() const
return nullptr;
}

void QgsLocatorFilter::executeSearchAndDelete( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback )
{
if ( !feedback->isCanceled() )
fetchResults( string, context, feedback );
emit finished();
}

bool QgsLocatorFilter::stringMatches( const QString &candidate, const QString &search )
{
return candidate.contains( search, Qt::CaseInsensitive );
Expand Down
9 changes: 3 additions & 6 deletions src/core/locator/qgslocatorfilter.h
Expand Up @@ -165,12 +165,6 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
*/
virtual void prepare( const QString &string, const QgsLocatorContext &context ) { Q_UNUSED( string ); Q_UNUSED( context ); }

/**
* Executes a search for this filter instance, and then deletes the current instance
* of the filter.
*/
void executeSearchAndDelete( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback );

/**
* Retrieves the filter results for a specified search \a string. The \a context
* argument encapsulates the context relating to the search (such as a map
Expand All @@ -182,6 +176,9 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
* Subclasses should periodically check the \a feedback object to determine
* whether the query has been canceled. If so, the subclass should return
* from this method as soon as possible.
*
* This will be called from a background thread unless flags() returns the
* QgsLocatorFilter::FlagFast flag.
*/
virtual void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) = 0;

Expand Down

0 comments on commit 44df58e

Please sign in to comment.