Skip to content
Permalink
Browse files

fix saving of edittype configuration and remove redundant storage of …

…labelontop

and editable state.
  • Loading branch information
jef-n committed Jul 24, 2014
1 parent 693c2e7 commit 62e59c896f2162b14fc47ec12a4a309ac3a8bd07
@@ -41,6 +41,7 @@ class QgsEditorWidgetRegistry : QObject
* @param config A configuration which should be used for the widget creation
* @param editor An editor widget which will be used instead of an autocreated widget
* @param parent The parent which will be used for the created wrapper and the created widget
* @param context The editor context (not available in python bindings)
*
* @return A new widget wrapper
*/
@@ -1858,21 +1858,12 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
}
}

//edit types
QDomElement editTypesElement = doc.createElement( "edittypes" );

Q_FOREACH( QgsField field, pendingFields().toList() )
{
QDomElement editTypeElement = doc.createElement( "edittype" );
editTypeElement.setAttribute( "name", field.name() );
editTypeElement.setAttribute( "editable", mFieldEditables[field.name()] ? 1 : 0 );
editTypeElement.setAttribute( "labelontop", mLabelOnTop[field.name()] ? 1 : 0 );


editTypesElement.appendChild( editTypeElement );
}

node.appendChild( editTypesElement );
// FIXME
// edittypes are written to the layerNode
// by slot QgsEditorWidgetRegistry::writeMapLayer()
// triggered by signal QgsProject::writeMapLayer()
// still other editing settings are written here,
// although they are not part of symbology either

QDomElement efField = doc.createElement( "editform" );
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( mEditForm ) );
@@ -190,42 +190,36 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
return;
}

QDomNode editTypesNode = doc.createElement( "edittypes" );

for ( int idx = 0; idx < vectorLayer->pendingFields().count(); ++idx )
{
const QgsField &field = vectorLayer->pendingFields()[ idx ];
const QString& widgetType = vectorLayer->editorWidgetV2( idx );
if ( !mWidgetFactories.contains( widgetType ) )
{
QgsMessageLog::logMessage( tr( "Could not save unknown editor widget type '%1'." ).arg( widgetType ) );
continue;
}

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

for ( int i = 0; i < editTypeNodes.size(); i++ )
{
QDomElement editTypeElement = editTypeNodes.at( i ).toElement();

QString name = editTypeElement.attribute( "name" );

if ( vectorLayer->fieldNameIndex( name ) != idx )
continue;

editTypeElement.setAttribute( "widgetv2type", widgetType );
QDomElement editTypeElement = doc.createElement( "edittype" );
editTypeElement.setAttribute( "name", field.name() );
editTypeElement.setAttribute( "widgetv2type", widgetType );

if ( mWidgetFactories.contains( widgetType ) )
{
QDomElement ewv2CfgElem = doc.createElement( "widgetv2config" );
ewv2CfgElem.setAttribute( "fieldEditable", vectorLayer->fieldEditable( idx ) );
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->labelOnTop( idx ) );
if ( mWidgetFactories.contains( widgetType ) )
{
QDomElement ewv2CfgElem = doc.createElement( "widgetv2config" );
ewv2CfgElem.setAttribute( "fieldEditable", vectorLayer->fieldEditable( idx ) );
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->labelOnTop( idx ) );

mWidgetFactories[widgetType]->writeConfig( vectorLayer->editorWidgetV2Config( idx ), ewv2CfgElem, doc, vectorLayer, idx );
mWidgetFactories[widgetType]->writeConfig( vectorLayer->editorWidgetV2Config( idx ), ewv2CfgElem, doc, vectorLayer, idx );

editTypeElement.appendChild( ewv2CfgElem );
}
else
{
QgsMessageLog::logMessage( tr( "Unknown attribute editor widget '%1'" ).arg( widgetType ) );
}
editTypeElement.appendChild( ewv2CfgElem );
}

editTypesNode.appendChild( editTypeElement );
}

layerElem.appendChild( editTypesNode );
}
@@ -51,7 +51,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
* @param config A configuration which should be used for the widget creation
* @param editor An editor widget which will be used instead of an autocreated widget
* @param parent The parent which will be used for the created wrapper and the created widget
* @param context The editor context
* @param context The editor context (not available in python bindings)
*
* @return A new widget wrapper
*/

0 comments on commit 62e59c8

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