Skip to content

Commit e99ccb7

Browse files
committed
remove the accompanying QgsEditorWidgetConfig when removing a field
(refs #14136)
1 parent 0c0d72b commit e99ccb7

6 files changed

+55
-0
lines changed

python/core/qgseditformconfig.sip

+18
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ class QgsEditFormConfig : QObject
205205
*/
206206
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;
207207

208+
/**
209+
* Remove the configuration for the editor widget used to represent the field at the given index
210+
*
211+
* @param fieldIdx The index of the field
212+
*
213+
* @return true if successful, false if the field does not exist
214+
*/
215+
bool removeWidgetConfig( int fieldIdx );
216+
217+
/**
218+
* Remove the configuration for the editor widget used to represent the field with the given name
219+
*
220+
* @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
221+
*
222+
* @return true if successful, false if the field does not exist
223+
*/
224+
bool removeWidgetConfig( const QString& widgetName );
225+
208226
/**
209227
* This returns true if the field is manually set to read only or if the field
210228
* does not support editing like joins or virtual fields.

src/core/qgseditformconfig.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ void QgsEditFormConfig::setWidgetConfig( const QString& widgetName, const QgsEdi
7272
mWidgetConfigs[widgetName] = config;
7373
}
7474

75+
bool QgsEditFormConfig::removeWidgetConfig( const QString &widgetName )
76+
{
77+
return mWidgetConfigs.remove( widgetName ) != 0;
78+
}
79+
80+
bool QgsEditFormConfig::removeWidgetConfig( int fieldIdx )
81+
{
82+
if ( fieldIdx < 0 || fieldIdx >= mFields.count() )
83+
return false;
84+
85+
return mWidgetConfigs.remove( mFields[fieldIdx].name() );
86+
}
87+
7588
void QgsEditFormConfig::setUiForm( const QString& ui )
7689
{
7790
if ( ui.isEmpty() || ui.isNull() )

src/core/qgseditformconfig.h

+18
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,24 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
463463
*/
464464
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;
465465

466+
/**
467+
* Remove the configuration for the editor widget used to represent the field at the given index
468+
*
469+
* @param fieldIdx The index of the field
470+
*
471+
* @return true if successful, false if the field does not exist
472+
*/
473+
bool removeWidgetConfig( int fieldIdx );
474+
475+
/**
476+
* Remove the configuration for the editor widget used to represent the field with the given name
477+
*
478+
* @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
479+
*
480+
* @return true if successful, false if the field does not exist
481+
*/
482+
bool removeWidgetConfig( const QString& widgetName );
483+
466484
/**
467485
* This returns true if the field is manually set to read only or if the field
468486
* does not support editing like joins or virtual fields.

src/core/qgsvectorlayereditpassthrough.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ bool QgsVectorLayerEditPassthrough::deleteAttribute( int attr )
125125
if ( L->dataProvider()->deleteAttributes( QgsAttributeIds() << attr ) )
126126
{
127127
mModified = true;
128+
L->editFormConfig()->removeWidgetConfig( attr );
128129
emit attributeDeleted( attr );
129130
mModified = true;
130131
return true;

src/core/qgsvectorlayerundocommand.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribu
347347
QgsFields::FieldOrigin origin = fields.fieldOrigin( mFieldIndex );
348348
mOriginIndex = fields.fieldOriginIndex( mFieldIndex );
349349
mProviderField = ( origin == QgsFields::OriginProvider );
350+
mOldEditorWidgetConfig = mBuffer->L->editFormConfig()->widgetConfig( mFieldIndex );
350351

351352
if ( !mProviderField )
352353
{
@@ -401,6 +402,8 @@ void QgsVectorLayerUndoCommandDeleteAttribute::undo()
401402
}
402403
}
403404

405+
mBuffer->L->editFormConfig()->setWidgetConfig( mFieldIndex, mOldEditorWidgetConfig );
406+
404407
emit mBuffer->attributeAdded( mFieldIndex );
405408
}
406409

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

423+
mBuffer->L->editFormConfig()->removeWidgetConfig( mFieldIndex );
420424
mBuffer->handleAttributeDeleted( mFieldIndex ); // update changed attributes + new features
421425
mBuffer->updateLayerFields();
422426
emit mBuffer->attributeDeleted( mFieldIndex );

src/core/qgsvectorlayerundocommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class CORE_EXPORT QgsVectorLayerUndoCommandDeleteAttribute : public QgsVectorLay
138138
bool mProviderField;
139139
int mOriginIndex;
140140
QgsField mOldField;
141+
QgsEditorWidgetConfig mOldEditorWidgetConfig;
141142

142143
QMap<QgsFeatureId, QVariant> mDeletedValues;
143144
};

0 commit comments

Comments
 (0)