Skip to content
Permalink
Browse files

Merge pull request #5775 from pblottiere/fix_ref_rel_null

[bugfix] Constraints are updated even if the key is deleted from the keyboard
  • Loading branch information
pblottiere committed Dec 5, 2017
2 parents 79e2789 + 33737a6 commit fea3a770fbb48d8b5615dfc88f5d51d87daa6052
@@ -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()
@@ -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 );
}
@@ -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;
@@ -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 );

@@ -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
@@ -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

0 comments on commit fea3a77

Please sign in to comment.
You can’t perform that action at this time.