Skip to content

Commit 63654e5

Browse files
committedSep 5, 2016
Fix loading of editor widget configuration
1 parent f38e03b commit 63654e5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle
214214

215215
QDomNodeList editTypeNodes = layerElem.namedItem( "edittypes" ).childNodes();
216216

217+
QgsEditFormConfig formConfig = vectorLayer->editFormConfig();
218+
217219
for ( int i = 0; i < editTypeNodes.size(); i++ )
218220
{
219221
QDomNode editTypeNode = editTypeNodes.at( i );
@@ -230,27 +232,29 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle
230232

231233
if ( mWidgetFactories.contains( ewv2Type ) )
232234
{
233-
vectorLayer->editFormConfig().setWidgetType( idx, ewv2Type );
235+
formConfig.setWidgetType( idx, ewv2Type );
234236
QDomElement ewv2CfgElem = editTypeElement.namedItem( "widgetv2config" ).toElement();
235237

236238
if ( !ewv2CfgElem.isNull() )
237239
{
238240
cfg = mWidgetFactories[ewv2Type]->readEditorConfig( ewv2CfgElem, vectorLayer, idx );
239241
}
240242

241-
vectorLayer->editFormConfig().setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
242-
vectorLayer->editFormConfig().setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
243-
vectorLayer->editFormConfig().setNotNull( idx, ewv2CfgElem.attribute( "notNull", "0" ) == "1" );
244-
vectorLayer->editFormConfig().setExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
245-
vectorLayer->editFormConfig().setExpressionDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );
243+
formConfig.setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
244+
formConfig.setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
245+
formConfig.setNotNull( idx, ewv2CfgElem.attribute( "notNull", "0" ) == "1" );
246+
formConfig.setExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
247+
formConfig.setExpressionDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );
246248

247-
vectorLayer->editFormConfig().setWidgetConfig( idx, cfg );
249+
formConfig.setWidgetConfig( idx, cfg );
248250
}
249251
else
250252
{
251253
QgsMessageLog::logMessage( tr( "Unknown attribute editor widget '%1'" ).arg( ewv2Type ) );
252254
}
253255
}
256+
257+
vectorLayer->setEditFormConfig( formConfig );
254258
}
255259

256260
void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc ) const

‎tests/src/app/testqgsvectorlayersaveasdialog.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ void TestQgsVectorLayerSaveAsDialog::testAttributesAsDisplayedValues()
7575
QVERIFY( tempLayer->isValid() );
7676

7777
// Set a widget
78-
tempLayer->editFormConfig().setWidgetType( 0, "ValueRelation" );
78+
QgsEditFormConfig editFormConfig = tempLayer->editFormConfig();
79+
editFormConfig.setWidgetType( 0, "ValueRelation" );
80+
tempLayer->setEditFormConfig( editFormConfig );
7981

8082
QgsVectorLayerSaveAsDialog d( tempLayer.data() );
8183

0 commit comments

Comments
 (0)
Please sign in to comment.