Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix open form button not always enabled in relation reference widget (#…
…42144)

* fix open form button not always enabled in relation reference widget

when the underlying model has more feature than what the model fetches by default (100),
the feature is not fetched yet when the combobox has its index changed

the new signal allows to be aware when the feature is ready to be used
  • Loading branch information
3nids authored and nyalldawson committed Apr 17, 2021
1 parent 7324c92 commit 82c67f3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
9 changes: 9 additions & 0 deletions python/core/auto_generated/qgsfeaturepickermodelbase.sip.in
Expand Up @@ -154,6 +154,15 @@ If set to 0, no limit is applied when fetching

signals:

void currentFeatureChanged();
%Docstring
Emitted when the current feature in the model has changed
This emitted both when the extra value changes and when the extra value status changes.
It allows being notified when the feature is fetched after the extra value has been set.

.. versionadded:: 3.16.5
%End

void sourceLayerChanged();
%Docstring
The source layer from which features will be fetched.
Expand Down
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsfeaturelistcombobox.sip.in
Expand Up @@ -221,6 +221,13 @@ Normally the primary key of the layer.
void allowNullChanged();
%Docstring
Determines if a NULL value should be available in the list.
%End

void currentFeatureChanged();
%Docstring
Emitted when the current feature changes

.. versionadded:: 3.16.5
%End

};
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsfeaturepickermodelbase.cpp
Expand Up @@ -28,6 +28,11 @@ QgsFeaturePickerModelBase::QgsFeaturePickerModelBase( QObject *parent )
mReloadTimer.setInterval( 100 );
mReloadTimer.setSingleShot( true );
connect( &mReloadTimer, &QTimer::timeout, this, &QgsFeaturePickerModelBase::scheduledReload );

// 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 );
}


Expand Down Expand Up @@ -513,11 +518,13 @@ void QgsFeaturePickerModelBase::setExtraIdentifierValueUnguarded( const QVariant
if ( !isNull )
{
mEntries.prepend( createEntry( identifierValue ) );
setExtraValueDoesNotExist( true );
reloadCurrentFeature();
}
else
{
mEntries.prepend( QgsFeatureExpressionValuesGatherer::nullEntry( mSourceLayer ) );
setExtraValueDoesNotExist( false );
}
endInsertRows();

Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsfeaturepickermodelbase.h
Expand Up @@ -177,6 +177,14 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST

signals:

/**
* Emitted when the current feature in the model has changed
* This emitted both when the extra value changes and when the extra value status changes.
* It allows being notified when the feature is fetched after the extra value has been set.
* \since QGIS 3.16.5
*/
void currentFeatureChanged();

/**
* The source layer from which features will be fetched.
*/
Expand Down
5 changes: 2 additions & 3 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -599,7 +599,7 @@ void QgsRelationReferenceWidget::init()
}

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsRelationReferenceWidget::comboReferenceChanged );
connect( mComboBox, &QgsFeatureListComboBox::currentFeatureChanged, this, &QgsRelationReferenceWidget::comboReferenceChanged );

QApplication::restoreOverrideCursor();

Expand Down Expand Up @@ -723,9 +723,8 @@ void QgsRelationReferenceWidget::mapIdentification()
}
}

void QgsRelationReferenceWidget::comboReferenceChanged( int index )
void QgsRelationReferenceWidget::comboReferenceChanged()
{
Q_UNUSED( index )
mReferencedLayer->getFeatures( mComboBox->currentFeatureRequest() ).nextFeature( mFeature );
highlightFeature( mFeature );
updateAttributeEditorFrame( mFeature );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -287,7 +287,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
private slots:
void highlightActionTriggered( QAction *action );
void deleteHighlight();
void comboReferenceChanged( int index );
void comboReferenceChanged();
void featureIdentified( const QgsFeature &feature );
void setMapTool( QgsMapTool *mapTool );
void unsetMapTool();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsfeaturelistcombobox.cpp
Expand Up @@ -61,6 +61,8 @@ QgsFeatureListComboBox::QgsFeatureListComboBox( QWidget *parent )

connect( mLineEdit, &QgsFilterLineEdit::textEdited, this, &QgsFeatureListComboBox::onCurrentTextChanged );

connect( mModel, &QgsFeatureFilterModel::currentFeatureChanged, this, &QgsFeatureListComboBox::currentFeatureChanged );

setToolTip( tr( "Just start typing what you are looking for." ) );
}

Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsfeaturelistcombobox.h
Expand Up @@ -234,6 +234,12 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
*/
void allowNullChanged();

/**
* Emitted when the current feature changes
* \since QGIS 3.16.5
*/
void currentFeatureChanged();

private slots:
void onCurrentTextChanged( const QString &text );
void onFilterUpdateCompleted();
Expand All @@ -253,6 +259,7 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
bool mIsCurrentlyEdited = false;

friend class TestQgsFeatureListComboBox;
friend class TestQgsRelationReferenceWidget;
};


Expand Down

0 comments on commit 82c67f3

Please sign in to comment.