From dd19040226bc687d28d34a9f758e6bd8fe2a97f8 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 18 Sep 2020 17:58:18 +0200 Subject: [PATCH] do not display twice the same result --- src/app/locator/qgsinbuiltlocatorfilters.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/locator/qgsinbuiltlocatorfilters.cpp b/src/app/locator/qgsinbuiltlocatorfilters.cpp index f7b146ab6af..1655f1311ce 100644 --- a/src/app/locator/qgsinbuiltlocatorfilters.cpp +++ b/src/app/locator/qgsinbuiltlocatorfilters.cpp @@ -354,7 +354,7 @@ QStringList QgsActiveLayerFeaturesLocatorFilter::prepare( const QString &string, void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &, QgsFeedback *feedback ) { - int found = 0; + QgsFeatureIds featuresFound; QgsFeature f; QString searchString = string; fieldRestriction( searchString ); @@ -377,8 +377,9 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c result.score = static_cast< double >( searchString.length() ) / result.displayString.size(); emit resultFetched( result ); - found++; - if ( found >= mMaxTotalResults ) + featuresFound << f.id(); + + if ( featuresFound.count() >= mMaxTotalResults ) break; } } @@ -389,6 +390,10 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c if ( feedback->isCanceled() ) return; + // do not display twice the same feature + if ( featuresFound.contains( f.id() ) ) + continue; + QgsLocatorResult result; mContext.setFeature( f ); @@ -418,8 +423,8 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c result.score = static_cast< double >( searchString.length() ) / result.displayString.size(); emit resultFetched( result ); - found++; - if ( found >= mMaxTotalResults ) + featuresFound << f.id(); + if ( featuresFound.count() >= mMaxTotalResults ) break; } }