Skip to content

Commit

Permalink
Update widget wrapper status only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Nov 30, 2017
1 parent 512acca commit 33737a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
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 33737a6

Please sign in to comment.