Skip to content

Commit

Permalink
Merge pull request #5775 from pblottiere/fix_ref_rel_null
Browse files Browse the repository at this point in the history
[bugfix] Constraints are updated even if the key is deleted from the keyboard
  • Loading branch information
pblottiere authored Dec 5, 2017
2 parents 79e2789 + 33737a6 commit fea3a77
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
12 changes: 11 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
connect( mMapIdentificationButton, SIGNAL( clicked() ), this, SLOT( mapIdentification() ) );
connect( mRemoveFKButton, SIGNAL( clicked() ), this, SLOT( deleteForeignKey() ) );
connect( mAddEntryButton, SIGNAL( clicked( bool ) ), this, SLOT( addEntry() ) );
connect( mComboBox, SIGNAL( editTextChanged( QString ) ), this, SLOT( updateAddEntryButton() ) );
connect( mComboBox, SIGNAL( editTextChanged( QString ) ), this, SLOT( editTextUpdated( const QString & ) ) );
}

QgsRelationReferenceWidget::~QgsRelationReferenceWidget()
Expand Down Expand Up @@ -990,3 +990,13 @@ void QgsRelationReferenceWidget::disableChainedComboBoxes( const QComboBox *scb
ccb = cb;
}
}

void QgsRelationReferenceWidget::editTextUpdated( const QString &text )
{
updateAddEntryButton();

// allow to raise an invalid constraint on NULL values if necessary
// and when the combobox is updated manually from the keyboard
if ( text.isEmpty() && mAllowNull )
mComboBox->setCurrentIndex( 0 );
}
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
void mapToolDeactivated();
void filterChanged();
void addEntry();
void updateAddEntryButton();
void editTextUpdated( const QString &text );

private:
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
void updateAttributeEditorFrame( const QgsFeature& feature );
void disableChainedComboBoxes( const QComboBox *scb );
void updateAddEntryButton();

// initialized
QgsAttributeEditorContext mEditorContext;
Expand Down
26 changes: 15 additions & 11 deletions src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
Q_FOREACH ( QgsEditorWidgetWrapper* depsEww, deps )
depsEww->updateConstraint( ft );

// sync ok button status
synchronizeEnabledState();
// sync ok button status only
synchronizeEnabledState( false );

mExpressionContext.setFeature( ft );

Expand Down Expand Up @@ -986,23 +986,27 @@ void QgsAttributeForm::refreshFeature()
setFeature( mFeature );
}

void QgsAttributeForm::synchronizeEnabledState()
void QgsAttributeForm::synchronizeEnabledState( bool synchronizeWidgetWrapper )
{
bool isEditable = ( mFeature.isValid()
|| mMode == AddFeatureMode
|| mMode == MultiEditMode ) && mLayer->isEditable();

Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets )
if ( synchronizeWidgetWrapper )
{
bool fieldEditable = true;
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
if ( eww )
Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets )
{
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
FID_IS_NEW( mFeature.id() ) );
bool fieldEditable = true;
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
if ( eww )
{
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
FID_IS_NEW( mFeature.id() ) );
}

ww->setEnabled( isEditable && fieldEditable );
}
ww->setEnabled( isEditable && fieldEditable );
}

// push a message and disable the OK button if constraints are invalid
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsattributeform.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
void onConstraintStatusChanged( const QString& constraint,
const QString& description, const QString& err, bool ok );
void preventFeatureRefresh();
void synchronizeEnabledState();
void synchronizeEnabledState( bool synchronizeWidgetWrapper = true );
void layerSelectionChanged();

//! Save multi edit changes
Expand Down

0 comments on commit fea3a77

Please sign in to comment.