Skip to content

Commit 3ea35fc

Browse files
committed
Relation Reference Widget: Only enable form button when a feature is set
1 parent 8868303 commit 3ea35fc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void QgsRelationReferenceWidget::deleteForeignKey()
323323
emit foreignKeyChanged( QVariant( QVariant::Int ) );
324324
}
325325

326-
QgsFeature QgsRelationReferenceWidget::referencedFeature()
326+
QgsFeature QgsRelationReferenceWidget::referencedFeature() const
327327
{
328328
QgsFeature f;
329329
if ( mReferencedLayer )
@@ -356,7 +356,7 @@ void QgsRelationReferenceWidget::showIndeterminateState()
356356
updateAttributeEditorFrame( QgsFeature() );
357357
}
358358

359-
QVariant QgsRelationReferenceWidget::foreignKey()
359+
QVariant QgsRelationReferenceWidget::foreignKey() const
360360
{
361361
if ( mReadOnlySelector )
362362
{
@@ -557,6 +557,7 @@ void QgsRelationReferenceWidget::init()
557557

558558
// Only connect after iterating, to have only one iterator on the referenced table at once
559559
connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
560+
updateAttributeEditorFrame( mFeature );
560561
QApplication::restoreOverrideCursor();
561562
}
562563
}
@@ -706,13 +707,11 @@ void QgsRelationReferenceWidget::comboReferenceChanged( int index )
706707

707708
void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature& feature )
708709
{
710+
mOpenFormButton->setEnabled( feature.isValid() );
709711
// Check if we're running with an embedded frame we need to update
710-
if ( mAttributeEditorFrame )
712+
if ( mAttributeEditorFrame && mReferencedAttributeForm )
711713
{
712-
if ( mReferencedAttributeForm )
713-
{
714-
mReferencedAttributeForm->setFeature( feature );
715-
}
714+
mReferencedAttributeForm->setFeature( feature );
716715
}
717716
}
718717

src/gui/editorwidgets/qgsrelationreferencewidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
6262
void setForeignKey( const QVariant &value );
6363

6464
//! returns the related feature foreign key
65-
QVariant foreignKey();
65+
QVariant foreignKey() const;
6666

6767
void setEditorContext( const QgsAttributeEditorContext& context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
6868

@@ -106,7 +106,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
106106

107107
//! return the related feature (from the referenced layer)
108108
//! if no feature is related, it returns an invalid feature
109-
QgsFeature referencedFeature();
109+
QgsFeature referencedFeature() const;
110110

111111
/** Sets the widget to display in an indeterminate "mixed value" state.
112112
* @note added in QGIS 2.16

0 commit comments

Comments
 (0)