From 4701c8957be0a9be099601d29928185bfe76a892 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 23 Nov 2024 11:48:48 +0700 Subject: [PATCH] Allow for QML locator filters to pass on parameters to the locator processing source --- src/core/locator/qfieldlocatorfilter.cpp | 12 +++++++++++- src/core/locator/qfieldlocatorfilter.h | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/locator/qfieldlocatorfilter.cpp b/src/core/locator/qfieldlocatorfilter.cpp index e25a7f7e7f..e51a40c1a1 100644 --- a/src/core/locator/qfieldlocatorfilter.cpp +++ b/src/core/locator/qfieldlocatorfilter.cpp @@ -34,11 +34,21 @@ QFieldLocatorFilter *QFieldLocatorFilter::clone() const filter->setName( mName ); filter->setDisplayName( mDisplayName ); filter->setPrefix( mPrefix ); + filter->setParameters( mParameters ); filter->setSource( mSource ); filter->setLocatorBridge( mLocatorBridge ); return filter; } +void QFieldLocatorFilter::setParameters( const QVariantMap ¶meters ) +{ + if ( mParameters == parameters ) + return; + + mParameters = parameters; + emit parametersChanged(); +} + void QFieldLocatorFilter::setSource( const QUrl &source ) { if ( mSource.path() == source.path() ) @@ -128,7 +138,7 @@ void QFieldLocatorFilter::fetchResults( const QString &string, const QgsLocatorC connect( object, SIGNAL( fetchResultsEnded() ), &loop, SLOT( quit() ) ); connect( feedback, &QgsFeedback::canceled, &loop, &QEventLoop::quit ); - QMetaObject::invokeMethod( object, QStringLiteral( "fetchResults" ).toStdString().c_str(), QVariant( string ), QVariant::fromValue( context ) ); + QMetaObject::invokeMethod( object, QStringLiteral( "fetchResults" ).toStdString().c_str(), QVariant( string ), QVariant::fromValue( context ), QVariant::fromValue( mParameters ) ); if ( !mFetchResultsEnded ) { loop.exec(); diff --git a/src/core/locator/qfieldlocatorfilter.h b/src/core/locator/qfieldlocatorfilter.h index 3c0f84cc10..e4b210a950 100644 --- a/src/core/locator/qfieldlocatorfilter.h +++ b/src/core/locator/qfieldlocatorfilter.h @@ -38,7 +38,10 @@ class QFieldLocatorFilter : public QgsLocatorFilter Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged ) Q_PROPERTY( QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged ) Q_PROPERTY( QString prefix READ prefix WRITE setPrefix NOTIFY prefixChanged ) + + Q_PROPERTY( QVariantMap parameters READ parameters WRITE setParameters NOTIFY parametersChanged ) Q_PROPERTY( QUrl source READ source WRITE setSource NOTIFY sourceChanged ) + Q_PROPERTY( LocatorModelSuperBridge *locatorBridge READ locatorBridge WRITE setLocatorBridge NOTIFY locatorBridgeChanged ) public: @@ -57,6 +60,9 @@ class QFieldLocatorFilter : public QgsLocatorFilter QUrl source() const { return mSource; } void setSource( const QUrl &source ); + QVariantMap parameters() const { return mParameters; } + void setParameters( const QVariantMap ¶meters ); + LocatorModelSuperBridge *locatorBridge() const { return mLocatorBridge; } void setLocatorBridge( LocatorModelSuperBridge *locatorBridge ); @@ -70,6 +76,7 @@ class QFieldLocatorFilter : public QgsLocatorFilter void nameChanged(); void displayNameChanged(); void prefixChanged(); + void parametersChanged(); void sourceChanged(); void locatorBridgeChanged(); @@ -84,6 +91,7 @@ class QFieldLocatorFilter : public QgsLocatorFilter bool mFetchResultsEnded = false; + QVariantMap mParameters; QUrl mSource; LocatorModelSuperBridge *mLocatorBridge = nullptr;