Skip to content

Commit fea3a77

Browse files
authoredDec 5, 2017
Merge pull request #5775 from pblottiere/fix_ref_rel_null
[bugfix] Constraints are updated even if the key is deleted from the keyboard
2 parents 79e2789 + 33737a6 commit fea3a77

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed
 

‎src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
164164
connect( mMapIdentificationButton, SIGNAL( clicked() ), this, SLOT( mapIdentification() ) );
165165
connect( mRemoveFKButton, SIGNAL( clicked() ), this, SLOT( deleteForeignKey() ) );
166166
connect( mAddEntryButton, SIGNAL( clicked( bool ) ), this, SLOT( addEntry() ) );
167-
connect( mComboBox, SIGNAL( editTextChanged( QString ) ), this, SLOT( updateAddEntryButton() ) );
167+
connect( mComboBox, SIGNAL( editTextChanged( QString ) ), this, SLOT( editTextUpdated( const QString & ) ) );
168168
}
169169

170170
QgsRelationReferenceWidget::~QgsRelationReferenceWidget()
@@ -990,3 +990,13 @@ void QgsRelationReferenceWidget::disableChainedComboBoxes( const QComboBox *scb
990990
ccb = cb;
991991
}
992992
}
993+
994+
void QgsRelationReferenceWidget::editTextUpdated( const QString &text )
995+
{
996+
updateAddEntryButton();
997+
998+
// allow to raise an invalid constraint on NULL values if necessary
999+
// and when the combobox is updated manually from the keyboard
1000+
if ( text.isEmpty() && mAllowNull )
1001+
mComboBox->setCurrentIndex( 0 );
1002+
}

‎src/gui/editorwidgets/qgsrelationreferencewidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
157157
void mapToolDeactivated();
158158
void filterChanged();
159159
void addEntry();
160-
void updateAddEntryButton();
160+
void editTextUpdated( const QString &text );
161161

162162
private:
163163
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
164164
void updateAttributeEditorFrame( const QgsFeature& feature );
165165
void disableChainedComboBoxes( const QComboBox *scb );
166+
void updateAddEntryButton();
166167

167168
// initialized
168169
QgsAttributeEditorContext mEditorContext;

‎src/gui/qgsattributeform.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
740740
Q_FOREACH ( QgsEditorWidgetWrapper* depsEww, deps )
741741
depsEww->updateConstraint( ft );
742742

743-
// sync ok button status
744-
synchronizeEnabledState();
743+
// sync ok button status only
744+
synchronizeEnabledState( false );
745745

746746
mExpressionContext.setFeature( ft );
747747

@@ -986,23 +986,27 @@ void QgsAttributeForm::refreshFeature()
986986
setFeature( mFeature );
987987
}
988988

989-
void QgsAttributeForm::synchronizeEnabledState()
989+
void QgsAttributeForm::synchronizeEnabledState( bool synchronizeWidgetWrapper )
990990
{
991991
bool isEditable = ( mFeature.isValid()
992992
|| mMode == AddFeatureMode
993993
|| mMode == MultiEditMode ) && mLayer->isEditable();
994994

995-
Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets )
995+
if ( synchronizeWidgetWrapper )
996996
{
997-
bool fieldEditable = true;
998-
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
999-
if ( eww )
997+
Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets )
1000998
{
1001-
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
1002-
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
1003-
FID_IS_NEW( mFeature.id() ) );
999+
bool fieldEditable = true;
1000+
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
1001+
if ( eww )
1002+
{
1003+
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
1004+
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
1005+
FID_IS_NEW( mFeature.id() ) );
1006+
}
1007+
1008+
ww->setEnabled( isEditable && fieldEditable );
10041009
}
1005-
ww->setEnabled( isEditable && fieldEditable );
10061010
}
10071011

10081012
// push a message and disable the OK button if constraints are invalid

‎src/gui/qgsattributeform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
259259
void onConstraintStatusChanged( const QString& constraint,
260260
const QString& description, const QString& err, bool ok );
261261
void preventFeatureRefresh();
262-
void synchronizeEnabledState();
262+
void synchronizeEnabledState( bool synchronizeWidgetWrapper = true );
263263
void layerSelectionChanged();
264264

265265
//! Save multi edit changes

0 commit comments

Comments
 (0)
Please sign in to comment.