Skip to content

Commit

Permalink
Fix loading of editor widget configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 5, 2016
1 parent f38e03b commit 63654e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -214,6 +214,8 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle

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

QgsEditFormConfig formConfig = vectorLayer->editFormConfig();

for ( int i = 0; i < editTypeNodes.size(); i++ )
{
QDomNode editTypeNode = editTypeNodes.at( i );
Expand All @@ -230,27 +232,29 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle

if ( mWidgetFactories.contains( ewv2Type ) )
{
vectorLayer->editFormConfig().setWidgetType( idx, ewv2Type );
formConfig.setWidgetType( idx, ewv2Type );
QDomElement ewv2CfgElem = editTypeElement.namedItem( "widgetv2config" ).toElement();

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

vectorLayer->editFormConfig().setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
vectorLayer->editFormConfig().setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
vectorLayer->editFormConfig().setNotNull( idx, ewv2CfgElem.attribute( "notNull", "0" ) == "1" );
vectorLayer->editFormConfig().setExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
vectorLayer->editFormConfig().setExpressionDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );
formConfig.setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
formConfig.setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
formConfig.setNotNull( idx, ewv2CfgElem.attribute( "notNull", "0" ) == "1" );
formConfig.setExpression( idx, ewv2CfgElem.attribute( "constraint", QString() ) );
formConfig.setExpressionDescription( idx, ewv2CfgElem.attribute( "constraintDescription", QString() ) );

vectorLayer->editFormConfig().setWidgetConfig( idx, cfg );
formConfig.setWidgetConfig( idx, cfg );
}
else
{
QgsMessageLog::logMessage( tr( "Unknown attribute editor widget '%1'" ).arg( ewv2Type ) );
}
}

vectorLayer->setEditFormConfig( formConfig );
}

void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc ) const
Expand Down
4 changes: 3 additions & 1 deletion tests/src/app/testqgsvectorlayersaveasdialog.cpp
Expand Up @@ -75,7 +75,9 @@ void TestQgsVectorLayerSaveAsDialog::testAttributesAsDisplayedValues()
QVERIFY( tempLayer->isValid() );

// Set a widget
tempLayer->editFormConfig().setWidgetType( 0, "ValueRelation" );
QgsEditFormConfig editFormConfig = tempLayer->editFormConfig();
editFormConfig.setWidgetType( 0, "ValueRelation" );
tempLayer->setEditFormConfig( editFormConfig );

QgsVectorLayerSaveAsDialog d( tempLayer.data() );

Expand Down

0 comments on commit 63654e5

Please sign in to comment.