Skip to content
Permalink
Browse files

Simplify code

  • Loading branch information
nyalldawson committed Feb 12, 2018
1 parent 7609ab7 commit 44df58e54dd16c945dc482935e8fc656e5f90c4d
@@ -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;
@@ -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;
@@ -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]
{
@@ -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 );
@@ -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
@@ -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;

0 comments on commit 44df58e

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