81 qDeleteAll( mWidgetFactories.values() );
86 if ( mWidgetFactories.contains( widgetId ) )
105 if ( mWidgetFactories.contains( widgetId ) )
107 return mWidgetFactories[widgetId]->configWidget( vl, fieldIdx, parent );
114 if ( mWidgetFactories.contains( widgetId ) )
116 return mWidgetFactories[widgetId]->name();
124 return mWidgetFactories;
129 return mWidgetFactories.value( widgetId );
134 if ( !widgetFactory )
139 else if ( mWidgetFactories.contains( widgetId ) )
141 QgsMessageLog::instance()->logMessage( QString(
"QgsEditorWidgetRegistry: Factory with id %1 already registered." ).arg( widgetId ) );
146 mWidgetFactories.insert( widgetId, widgetFactory );
151 void QgsEditorWidgetRegistry::readMapLayer(
QgsMapLayer* mapLayer,
const QDomElement& layerElem )
159 Q_ASSERT( vectorLayer );
161 QDomNodeList editTypeNodes = layerElem.namedItem(
"edittypes" ).childNodes();
163 for (
int i = 0; i < editTypeNodes.size(); i++ )
165 QDomNode editTypeNode = editTypeNodes.at( i );
166 QDomElement editTypeElement = editTypeNode.toElement();
168 QString
name = editTypeElement.attribute(
"name" );
184 ewv2Type = readLegacyConfig( vectorLayer, editTypeElement, cfg );
188 ewv2Type = editTypeElement.attribute(
"widgetv2type" );
190 if ( mWidgetFactories.contains( ewv2Type ) )
193 QDomElement ewv2CfgElem = editTypeElement.namedItem(
"widgetv2config" ).toElement();
195 if ( !ewv2CfgElem.isNull() )
197 cfg = mWidgetFactories[ewv2Type]->readEditorConfig( ewv2CfgElem, vectorLayer, idx );
200 vectorLayer->
setFieldEditable( idx, ewv2CfgElem.attribute(
"fieldEditable",
"1" ) ==
"1" );
201 vectorLayer->
setLabelOnTop( idx, ewv2CfgElem.attribute(
"labelOnTop",
"0" ) ==
"1" );
213 QString name = editTypeElement.attribute(
"name" );
222 void QgsEditorWidgetRegistry::writeMapLayer(
QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc )
const
235 QDomNode editTypesNode = doc.createElement(
"edittypes" );
241 if ( !mWidgetFactories.contains( widgetType ) )
248 QDomElement editTypeElement = doc.createElement(
"edittype" );
249 editTypeElement.setAttribute(
"name", field.
name() );
250 editTypeElement.setAttribute(
"widgetv2type", widgetType );
252 if ( mWidgetFactories.contains( widgetType ) )
254 QDomElement ewv2CfgElem = doc.createElement(
"widgetv2config" );
255 ewv2CfgElem.setAttribute(
"fieldEditable", vectorLayer->
fieldEditable( idx ) );
256 ewv2CfgElem.setAttribute(
"labelOnTop", vectorLayer->
labelOnTop( idx ) );
258 mWidgetFactories[widgetType]->writeConfig( vectorLayer->
editorWidgetV2Config( idx ), ewv2CfgElem, doc, vectorLayer, idx );
260 editTypeElement.appendChild( ewv2CfgElem );
263 editTypesNode.appendChild( editTypeElement );
266 layerElem.appendChild( editTypesNode );
269 void QgsEditorWidgetRegistry::mapLayerAdded(
QgsMapLayer* mapLayer )
275 connect( vl, SIGNAL( readCustomSymbology(
const QDomElement&, QString& ) ),
this, SLOT( readSymbology(
const QDomElement&, QString& ) ) );
276 connect( vl, SIGNAL( writeCustomSymbology( QDomElement&, QDomDocument&, QString& ) ),
this, SLOT( writeSymbology( QDomElement&, QDomDocument&, QString& ) ) );
280 void QgsEditorWidgetRegistry::readSymbology(
const QDomElement& element, QString& errorMessage )
282 Q_UNUSED( errorMessage )
287 readMapLayer( vl, element );
292 Q_UNUSED( errorMessage )
297 writeMapLayer( vl, element, doc );