Skip to content

Commit

Permalink
fix saving of edittype configuration and remove redundant storage of …
Browse files Browse the repository at this point in the history
…labelontop

and editable state.
  • Loading branch information
jef-n committed Jul 24, 2014
1 parent 693c2e7 commit 62e59c8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 39 deletions.
1 change: 1 addition & 0 deletions python/gui/editorwidgets/core/qgseditorwidgetregistry.sip
Expand Up @@ -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
*/
Expand Down
21 changes: 6 additions & 15 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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 ) );
Expand Down
40 changes: 17 additions & 23 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -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 );
}
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.h
Expand Up @@ -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
*/
Expand Down

0 comments on commit 62e59c8

Please sign in to comment.