fix saving of edittype configuration and remove redundant storage of labelontop

and editable state.
This commit is contained in:
Juergen E. Fischer 2014-07-24 19:04:42 +02:00
parent 693c2e72dd
commit 62e59c896f
4 changed files with 25 additions and 39 deletions

View File

@ -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
*/

View File

@ -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 ) );

View File

@ -190,8 +190,11 @@ 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 ) )
{
@ -199,33 +202,24 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
continue;
}
QDomNodeList editTypeNodes = layerElem.namedItem( "edittypes" ).childNodes();
for ( int i = 0; i < editTypeNodes.size(); i++ )
QDomElement editTypeElement = doc.createElement( "edittype" );
editTypeElement.setAttribute( "name", field.name() );
editTypeElement.setAttribute( "widgetv2type", widgetType );
if ( mWidgetFactories.contains( widgetType ) )
{
QDomElement editTypeElement = editTypeNodes.at( i ).toElement();
QDomElement ewv2CfgElem = doc.createElement( "widgetv2config" );
ewv2CfgElem.setAttribute( "fieldEditable", vectorLayer->fieldEditable( idx ) );
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->labelOnTop( idx ) );
QString name = editTypeElement.attribute( "name" );
mWidgetFactories[widgetType]->writeConfig( vectorLayer->editorWidgetV2Config( idx ), ewv2CfgElem, doc, vectorLayer, idx );
if ( vectorLayer->fieldNameIndex( name ) != idx )
continue;
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 ) );
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 );
}

View File

@ -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
*/