From 061936b8b0e1fa134a9208258954037715c12d3b Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 2 May 2024 12:17:42 +0700 Subject: [PATCH] [attribute form] Fix initial multi editing state of relation reference editor widgets --- .../core/auto_generated/qgsfeaturepickermodelbase.sip.in | 2 +- .../gui/auto_generated/qgsfeaturelistcombobox.sip.in | 7 +++++++ .../core/auto_generated/qgsfeaturepickermodelbase.sip.in | 2 +- python/gui/auto_generated/qgsfeaturelistcombobox.sip.in | 7 +++++++ src/core/qgsfeaturepickermodelbase.cpp | 1 - src/core/qgsfeaturepickermodelbase.h | 2 +- src/gui/editorwidgets/qgsrelationreferencewidget.cpp | 8 ++++++++ src/gui/editorwidgets/qgsrelationreferencewidget.h | 1 + src/gui/qgsfeaturelistcombobox.cpp | 1 + src/gui/qgsfeaturelistcombobox.h | 6 ++++++ 10 files changed, 33 insertions(+), 4 deletions(-) diff --git a/python/PyQt6/core/auto_generated/qgsfeaturepickermodelbase.sip.in b/python/PyQt6/core/auto_generated/qgsfeaturepickermodelbase.sip.in index 65cfc4b9f256..d3f8afbb573c 100644 --- a/python/PyQt6/core/auto_generated/qgsfeaturepickermodelbase.sip.in +++ b/python/PyQt6/core/auto_generated/qgsfeaturepickermodelbase.sip.in @@ -213,7 +213,7 @@ The index at which the extra identifier value is available within the model. void extraValueDoesNotExistChanged(); %Docstring -Flag indicating that the extraIdentifierValue does not exist in the data. +Notification that the model has found a feature tied to the extraIdentifierValue. %End void beginUpdate(); diff --git a/python/PyQt6/gui/auto_generated/qgsfeaturelistcombobox.sip.in b/python/PyQt6/gui/auto_generated/qgsfeaturelistcombobox.sip.in index c096043271ec..4cec92bdd72d 100644 --- a/python/PyQt6/gui/auto_generated/qgsfeaturelistcombobox.sip.in +++ b/python/PyQt6/gui/auto_generated/qgsfeaturelistcombobox.sip.in @@ -240,6 +240,13 @@ Determines if a NULL value should be available in the list. Emitted when the current feature changes .. versionadded:: 3.16.5 +%End + + void currentFeatureFoundChanged(); +%Docstring +Emitted when the feature picker model changes its feature found state + +.. versionadded:: 3.38 %End }; diff --git a/python/core/auto_generated/qgsfeaturepickermodelbase.sip.in b/python/core/auto_generated/qgsfeaturepickermodelbase.sip.in index aa1ba01044a4..a87755e5e316 100644 --- a/python/core/auto_generated/qgsfeaturepickermodelbase.sip.in +++ b/python/core/auto_generated/qgsfeaturepickermodelbase.sip.in @@ -213,7 +213,7 @@ The index at which the extra identifier value is available within the model. void extraValueDoesNotExistChanged(); %Docstring -Flag indicating that the extraIdentifierValue does not exist in the data. +Notification that the model has found a feature tied to the extraIdentifierValue. %End void beginUpdate(); diff --git a/python/gui/auto_generated/qgsfeaturelistcombobox.sip.in b/python/gui/auto_generated/qgsfeaturelistcombobox.sip.in index c096043271ec..4cec92bdd72d 100644 --- a/python/gui/auto_generated/qgsfeaturelistcombobox.sip.in +++ b/python/gui/auto_generated/qgsfeaturelistcombobox.sip.in @@ -240,6 +240,13 @@ Determines if a NULL value should be available in the list. Emitted when the current feature changes .. versionadded:: 3.16.5 +%End + + void currentFeatureFoundChanged(); +%Docstring +Emitted when the feature picker model changes its feature found state + +.. versionadded:: 3.38 %End }; diff --git a/src/core/qgsfeaturepickermodelbase.cpp b/src/core/qgsfeaturepickermodelbase.cpp index 3bc2e330391b..3fde29ac2f83 100644 --- a/src/core/qgsfeaturepickermodelbase.cpp +++ b/src/core/qgsfeaturepickermodelbase.cpp @@ -30,7 +30,6 @@ QgsFeaturePickerModelBase::QgsFeaturePickerModelBase( QObject *parent ) // The fact that the feature changed is a combination of the 2 signals: // If the extra value is set to a feature currently not fetched, it will go through an intermediate step while the extra value does not exist (as it call reloadFeature) connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueChanged, this, &QgsFeaturePickerModelBase::currentFeatureChanged ); - connect( this, &QgsFeaturePickerModelBase::extraValueDoesNotExistChanged, this, &QgsFeaturePickerModelBase::currentFeatureChanged ); } diff --git a/src/core/qgsfeaturepickermodelbase.h b/src/core/qgsfeaturepickermodelbase.h index e4ca702f40e8..6fcfeb7005cd 100644 --- a/src/core/qgsfeaturepickermodelbase.h +++ b/src/core/qgsfeaturepickermodelbase.h @@ -241,7 +241,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST void extraIdentifierValueIndexChanged( int index ); /** - * Flag indicating that the extraIdentifierValue does not exist in the data. + * Notification that the model has found a feature tied to the extraIdentifierValue. */ void extraValueDoesNotExistChanged(); diff --git a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp index c6d68352c10e..9eabb970729e 100644 --- a/src/gui/editorwidgets/qgsrelationreferencewidget.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencewidget.cpp @@ -494,6 +494,7 @@ void QgsRelationReferenceWidget::init() // Only connect after iterating, to have only one iterator on the referenced table at once connect( mComboBox, &QgsFeatureListComboBox::currentFeatureChanged, this, &QgsRelationReferenceWidget::comboReferenceChanged ); + connect( mComboBox, &QgsFeatureListComboBox::currentFeatureFoundChanged, this, &QgsRelationReferenceWidget::comboReferenceFoundChanged ); QApplication::restoreOverrideCursor(); @@ -626,6 +627,13 @@ void QgsRelationReferenceWidget::comboReferenceChanged() emitForeignKeysChanged( mComboBox->identifierValues() ); } +void QgsRelationReferenceWidget::comboReferenceFoundChanged() +{ + mReferencedLayer->getFeatures( mComboBox->currentFeatureRequest() ).nextFeature( mFeature ); + highlightFeature( mFeature ); + updateAttributeEditorFrame( mFeature ); +} + void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature &feature ) { mOpenFormButton->setEnabled( feature.isValid() ); diff --git a/src/gui/editorwidgets/qgsrelationreferencewidget.h b/src/gui/editorwidgets/qgsrelationreferencewidget.h index 3ac01b2e390c..6e9825df804a 100644 --- a/src/gui/editorwidgets/qgsrelationreferencewidget.h +++ b/src/gui/editorwidgets/qgsrelationreferencewidget.h @@ -294,6 +294,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget void highlightActionTriggered( QAction *action ); void deleteHighlight(); void comboReferenceChanged(); + void comboReferenceFoundChanged(); void featureIdentified( const QgsFeature &feature ); void setMapTool( QgsMapTool *mapTool ); void unsetMapTool(); diff --git a/src/gui/qgsfeaturelistcombobox.cpp b/src/gui/qgsfeaturelistcombobox.cpp index 86e7c15fc1e3..4db42736fc8b 100644 --- a/src/gui/qgsfeaturelistcombobox.cpp +++ b/src/gui/qgsfeaturelistcombobox.cpp @@ -65,6 +65,7 @@ QgsFeatureListComboBox::QgsFeatureListComboBox( QWidget *parent ) connect( mLineEdit, &QgsFilterLineEdit::cleared, this, &QgsFeatureListComboBox::onFilterLineEditCleared ); connect( mModel, &QgsFeatureFilterModel::currentFeatureChanged, this, &QgsFeatureListComboBox::currentFeatureChanged ); + connect( mModel, &QgsFeatureFilterModel::extraValueDoesNotExistChanged, this, &QgsFeatureListComboBox::currentFeatureFoundChanged ); setToolTip( tr( "Just start typing what you are looking for." ) ); } diff --git a/src/gui/qgsfeaturelistcombobox.h b/src/gui/qgsfeaturelistcombobox.h index 9d6c1cc76af9..1cfe1a8b9703 100644 --- a/src/gui/qgsfeaturelistcombobox.h +++ b/src/gui/qgsfeaturelistcombobox.h @@ -251,6 +251,12 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox */ void currentFeatureChanged(); + /** + * Emitted when the feature picker model changes its feature found state + * \since QGIS 3.38 + */ + void currentFeatureFoundChanged(); + private slots: void onCurrentTextChanged( const QString &text ); void onFilterLineEditCleared();