Skip to content

Commit

Permalink
remove the accompanying QgsEditorWidgetConfig when removing a field
Browse files Browse the repository at this point in the history
(refs #14136)
  • Loading branch information
SebDieBln committed Feb 20, 2016
1 parent 0c0d72b commit e99ccb7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/core/qgseditformconfig.sip
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -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() )
Expand Down
18 changes: 18 additions & 0 deletions src/core/qgseditformconfig.h
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayereditpassthrough.cpp
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectorlayerundocommand.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -401,6 +402,8 @@ void QgsVectorLayerUndoCommandDeleteAttribute::undo()
}
}

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

emit mBuffer->attributeAdded( mFieldIndex );
}

Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayerundocommand.h
Expand Up @@ -138,6 +138,7 @@ class CORE_EXPORT QgsVectorLayerUndoCommandDeleteAttribute : public QgsVectorLay
bool mProviderField;
int mOriginIndex;
QgsField mOldField;
QgsEditorWidgetConfig mOldEditorWidgetConfig;

QMap<QgsFeatureId, QVariant> mDeletedValues;
};
Expand Down

0 comments on commit e99ccb7

Please sign in to comment.