Skip to content
Permalink
Browse files

allow to define max number of results for some locator filters (#38628)

this allows to define:
*  maximum number of results for active layer
* global maximumum filter + per layer maximum numer of results of all layers features filter
  • Loading branch information
3nids committed Sep 8, 2020
1 parent a27420e commit e31d4cd202b5ebed778c8f66be852a91961eac83
Showing with 75 additions and 5 deletions.
  1. +68 −1 src/app/locator/qgsinbuiltlocatorfilters.cpp
  2. +7 −4 src/app/locator/qgsinbuiltlocatorfilters.h
@@ -17,6 +17,7 @@

#include <QClipboard>
#include <QMap>
#include <QSpinBox>
#include <QString>
#include <QToolButton>
#include <QUrl>
@@ -36,6 +37,7 @@
#include "qgsfeatureaction.h"
#include "qgsvectorlayerfeatureiterator.h"
#include "qgsexpressioncontextutils.h"
#include "qgssettings.h"


QgsLayerTreeLocatorFilter::QgsLayerTreeLocatorFilter( QObject *parent )
@@ -248,6 +250,9 @@ void QgsActiveLayerFeaturesLocatorFilter::prepare( const QString &string, const
if ( string.length() < 3 && !context.usingPrefix )
return;

QgsSettings settings;
mMaxTotalResults = settings.value( QStringLiteral( "locator_filters/active_layer_features/limit_global" ), 30, QgsSettings::App ).toInt();

bool allowNumeric = false;
double numericalValue = string.toDouble( &allowNumeric );

@@ -333,7 +338,7 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c
emit resultFetched( result );

found++;
if ( found >= 30 )
if ( found >= mMaxTotalResults )
break;
}
}
@@ -350,6 +355,31 @@ void QgsActiveLayerFeaturesLocatorFilter::triggerResult( const QgsLocatorResult
QgisApp::instance()->mapCanvas()->zoomToFeatureIds( layer, QgsFeatureIds() << id );
}

void QgsActiveLayerFeaturesLocatorFilter::openConfigWidget( QWidget *parent )
{
QString key = "locator_filters/active_layer_features";
QgsSettings settings;
std::unique_ptr<QDialog> dlg( new QDialog( parent ) );
dlg->restoreGeometry( settings.value( QStringLiteral( "Windows/%1/geometry" ).arg( key ) ).toByteArray() );
dlg->setWindowTitle( "All layers features locator filter" );
QFormLayout *formLayout = new QFormLayout;
QSpinBox *globalLimitSpinBox = new QSpinBox( dlg.get() );
globalLimitSpinBox->setValue( settings.value( QStringLiteral( "%1/limit_global" ).arg( key ), 30, QgsSettings::App ).toInt() );
globalLimitSpinBox->setMinimum( 1 );
globalLimitSpinBox->setMaximum( 200 );
formLayout->addRow( tr( "&Maximum number of results:" ), globalLimitSpinBox );
QDialogButtonBox *buttonbBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dlg.get() );
formLayout->addRow( buttonbBox );
dlg->setLayout( formLayout );
connect( buttonbBox, &QDialogButtonBox::accepted, [&]()
{
settings.setValue( QStringLiteral( "%1/limit_global" ).arg( key ), globalLimitSpinBox->value(), QgsSettings::App );
dlg->accept();
} );
connect( buttonbBox, &QDialogButtonBox::rejected, dlg.get(), &QDialog::reject );
dlg->exec();
}

//
// QgsAllLayersFeaturesLocatorFilter
//
@@ -371,6 +401,10 @@ void QgsAllLayersFeaturesLocatorFilter::prepare( const QString &string, const Qg
if ( string.length() < 3 && !context.usingPrefix )
return;

QgsSettings settings;
mMaxTotalResults = settings.value( "locator_filters/all_layers_features/limit_global", 15, QgsSettings::App ).toInt();
mMaxResultsPerLayer = settings.value( "locator_filters/all_layers_features/limit_per_layer", 8, QgsSettings::App ).toInt();

mPreparedLayers.clear();
const QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
@@ -526,6 +560,38 @@ void QgsAllLayersFeaturesLocatorFilter::triggerResultFromAction( const QgsLocato
}
}

void QgsAllLayersFeaturesLocatorFilter::openConfigWidget( QWidget *parent )
{
QString key = "locator_filters/all_layers_features";
QgsSettings settings;
std::unique_ptr<QDialog> dlg( new QDialog( parent ) );
dlg->restoreGeometry( settings.value( QStringLiteral( "Windows/%1/geometry" ).arg( key ) ).toByteArray() );
dlg->setWindowTitle( "All layers features locator filter" );
QFormLayout *formLayout = new QFormLayout;
QSpinBox *globalLimitSpinBox = new QSpinBox( dlg.get() );
globalLimitSpinBox->setValue( settings.value( QStringLiteral( "%1/limit_global" ).arg( key ), 15, QgsSettings::App ).toInt() );
globalLimitSpinBox->setMinimum( 1 );
globalLimitSpinBox->setMaximum( 200 );
formLayout->addRow( tr( "&Maximum number of results:" ), globalLimitSpinBox );
QSpinBox *parLayerLimitSpinBox = new QSpinBox( dlg.get() );
parLayerLimitSpinBox->setValue( settings.value( QStringLiteral( "%1/limit_per_layer" ).arg( key ), 8, QgsSettings::App ).toInt() );
parLayerLimitSpinBox->setMinimum( 1 );
parLayerLimitSpinBox->setMaximum( 200 );
formLayout->addRow( tr( "&Maximum number of results per layer:" ), parLayerLimitSpinBox );
QDialogButtonBox *buttonbBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dlg.get() );
formLayout->addRow( buttonbBox );
dlg->setLayout( formLayout );
connect( buttonbBox, &QDialogButtonBox::accepted, [&]()
{
settings.setValue( QStringLiteral( "%1/limit_global" ).arg( key ), globalLimitSpinBox->value(), QgsSettings::App );
settings.setValue( QStringLiteral( "%1/limit_per_layer" ).arg( key ), parLayerLimitSpinBox->value(), QgsSettings::App );
dlg->accept();
} );
connect( buttonbBox, &QDialogButtonBox::rejected, dlg.get(), &QDialog::reject );
dlg->exec();
}


//
// QgsExpressionCalculatorLocatorFilter
//
@@ -942,3 +1008,4 @@ void QgsGotoLocatorFilter::triggerResult( const QgsLocatorResult &result )

mapCanvas->flashGeometries( QList< QgsGeometry >() << QgsGeometry::fromPointXY( point ) );
}

@@ -105,6 +105,8 @@ class APP_EXPORT QgsActiveLayerFeaturesLocatorFilter : public QgsLocatorFilter
void prepare( const QString &string, const QgsLocatorContext &context ) override;
void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
void triggerResult( const QgsLocatorResult &result ) override;
bool hasConfigWidget() const override {return true;}
void openConfigWidget( QWidget *parent ) override;

private:

@@ -114,6 +116,7 @@ class APP_EXPORT QgsActiveLayerFeaturesLocatorFilter : public QgsLocatorFilter
QString mLayerId;
QIcon mLayerIcon;
QStringList mAttributeAliases;
int mMaxTotalResults = 30;
};

class APP_EXPORT QgsAllLayersFeaturesLocatorFilter : public QgsLocatorFilter
@@ -151,13 +154,13 @@ class APP_EXPORT QgsAllLayersFeaturesLocatorFilter : public QgsLocatorFilter
void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
void triggerResult( const QgsLocatorResult &result ) override;
void triggerResultFromAction( const QgsLocatorResult &result, const int actionId ) override;
bool hasConfigWidget() const override {return true;}
void openConfigWidget( QWidget *parent ) override;

private:
int mMaxResultsPerLayer = 6;
int mMaxTotalResults = 12;
int mMaxResultsPerLayer = 8;
int mMaxTotalResults = 15;
QList<std::shared_ptr<PreparedLayer>> mPreparedLayers;


};

class APP_EXPORT QgsExpressionCalculatorLocatorFilter : public QgsLocatorFilter

0 comments on commit e31d4cd

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