Skip to content
Permalink
Browse files

Merge pull request #2778 from SebDieBln/FixOrphanedWidgetConfigs

[Bugfix] Avoid orphaned QgsEditorWidgetConfig (refs #14136)
  • Loading branch information
m-kuhn committed Feb 23, 2016
2 parents b97e86d + e99ccb7 commit 50aa80583239676f36c9809120fbf43de06b7602
@@ -205,6 +205,24 @@ class QgsEditFormConfig : QObject
*/
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;

/**
* Remove the configuration for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return true if successful, false if the field does not exist
*/
bool removeWidgetConfig( int fieldIdx );

/**
* Remove the configuration for the editor widget used to represent the field with the given name
*
* @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
*
* @return true if successful, false if the field does not exist
*/
bool removeWidgetConfig( const QString& widgetName );

/**
* This returns true if the field is manually set to read only or if the field
* does not support editing like joins or virtual fields.
@@ -72,6 +72,19 @@ void QgsEditFormConfig::setWidgetConfig( const QString& widgetName, const QgsEdi
mWidgetConfigs[widgetName] = config;
}

bool QgsEditFormConfig::removeWidgetConfig( const QString &widgetName )
{
return mWidgetConfigs.remove( widgetName ) != 0;
}

bool QgsEditFormConfig::removeWidgetConfig( int fieldIdx )
{
if ( fieldIdx < 0 || fieldIdx >= mFields.count() )
return false;

return mWidgetConfigs.remove( mFields[fieldIdx].name() );
}

void QgsEditFormConfig::setUiForm( const QString& ui )
{
if ( ui.isEmpty() || ui.isNull() )
@@ -463,6 +463,24 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
*/
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;

/**
* Remove the configuration for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return true if successful, false if the field does not exist
*/
bool removeWidgetConfig( int fieldIdx );

/**
* Remove the configuration for the editor widget used to represent the field with the given name
*
* @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
*
* @return true if successful, false if the field does not exist
*/
bool removeWidgetConfig( const QString& widgetName );

/**
* This returns true if the field is manually set to read only or if the field
* does not support editing like joins or virtual fields.
@@ -125,6 +125,7 @@ bool QgsVectorLayerEditPassthrough::deleteAttribute( int attr )
if ( L->dataProvider()->deleteAttributes( QgsAttributeIds() << attr ) )
{
mModified = true;
L->editFormConfig()->removeWidgetConfig( attr );
emit attributeDeleted( attr );
mModified = true;
return true;
@@ -347,6 +347,7 @@ QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribu
QgsFields::FieldOrigin origin = fields.fieldOrigin( mFieldIndex );
mOriginIndex = fields.fieldOriginIndex( mFieldIndex );
mProviderField = ( origin == QgsFields::OriginProvider );
mOldEditorWidgetConfig = mBuffer->L->editFormConfig()->widgetConfig( mFieldIndex );

if ( !mProviderField )
{
@@ -401,6 +402,8 @@ void QgsVectorLayerUndoCommandDeleteAttribute::undo()
}
}

mBuffer->L->editFormConfig()->setWidgetConfig( mFieldIndex, mOldEditorWidgetConfig );

emit mBuffer->attributeAdded( mFieldIndex );
}

@@ -417,6 +420,7 @@ void QgsVectorLayerUndoCommandDeleteAttribute::redo()
mBuffer->mAddedAttributes.removeAt( mOriginIndex ); // removing temporary attribute
}

mBuffer->L->editFormConfig()->removeWidgetConfig( mFieldIndex );
mBuffer->handleAttributeDeleted( mFieldIndex ); // update changed attributes + new features
mBuffer->updateLayerFields();
emit mBuffer->attributeDeleted( mFieldIndex );
@@ -138,6 +138,7 @@ class CORE_EXPORT QgsVectorLayerUndoCommandDeleteAttribute : public QgsVectorLay
bool mProviderField;
int mOriginIndex;
QgsField mOldField;
QgsEditorWidgetConfig mOldEditorWidgetConfig;

QMap<QgsFeatureId, QVariant> mDeletedValues;
};

0 comments on commit 50aa805

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