Skip to content

Commit

Permalink
Relation Reference Widget: Only enable form button when a feature is set
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 16, 2016
1 parent 8868303 commit 3ea35fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -323,7 +323,7 @@ void QgsRelationReferenceWidget::deleteForeignKey()
emit foreignKeyChanged( QVariant( QVariant::Int ) );
}

QgsFeature QgsRelationReferenceWidget::referencedFeature()
QgsFeature QgsRelationReferenceWidget::referencedFeature() const
{
QgsFeature f;
if ( mReferencedLayer )
Expand Down Expand Up @@ -356,7 +356,7 @@ void QgsRelationReferenceWidget::showIndeterminateState()
updateAttributeEditorFrame( QgsFeature() );
}

QVariant QgsRelationReferenceWidget::foreignKey()
QVariant QgsRelationReferenceWidget::foreignKey() const
{
if ( mReadOnlySelector )
{
Expand Down Expand Up @@ -557,6 +557,7 @@ void QgsRelationReferenceWidget::init()

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

void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature& feature )
{
mOpenFormButton->setEnabled( feature.isValid() );
// Check if we're running with an embedded frame we need to update
if ( mAttributeEditorFrame )
if ( mAttributeEditorFrame && mReferencedAttributeForm )
{
if ( mReferencedAttributeForm )
{
mReferencedAttributeForm->setFeature( feature );
}
mReferencedAttributeForm->setFeature( feature );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -62,7 +62,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
void setForeignKey( const QVariant &value );

//! returns the related feature foreign key
QVariant foreignKey();
QVariant foreignKey() const;

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

Expand Down Expand Up @@ -106,7 +106,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget

//! return the related feature (from the referenced layer)
//! if no feature is related, it returns an invalid feature
QgsFeature referencedFeature();
QgsFeature referencedFeature() const;

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

0 comments on commit 3ea35fc

Please sign in to comment.