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 ) )
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 );
290 void QgsEditorWidgetRegistry::writeSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage )
292 Q_UNUSED( errorMessage )
297 writeMapLayer( vl, element, doc );
const QgsEditorWidgetConfig editorWidgetV2Config(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
const QString & name() const
Gets the name of the field.
bool fieldEditable(int idx)
is edit widget editable
Base class for all map layer types.
QgsMapLayer::LayerType type() const
Get the type of the layer.
This class contains context information for attribute editor widgets.
static QgsMapLayerRegistry * instance()
#define Q_NOWARN_DEPRECATED_PUSH
A bar for displaying non-blocking messages to the user.
Map canvas is a class for displaying all GIS data types on a canvas.
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
int count() const
Return number of items.
Encapsulate a field in an attribute table or data source.
bool labelOnTop(int idx)
label widget on top
void setEditorWidgetV2Config(int attrIdx, const QgsEditorWidgetConfig &config)
Set the editor widget config for a field.
#define Q_NOWARN_DEPRECATED_POP
void setEditorWidgetV2(int attrIdx, const QString &widgetType)
Set the editor widget type for a field.
static Q_DECL_DEPRECATED const QString convertEditType(QgsVectorLayer::EditType editType, QgsEditorWidgetConfig &cfg, QgsVectorLayer *vl, const QString &name, const QDomElement &editTypeElement=QDomElement())
static QgsMessageLog * instance()
static QgsProject * instance()
access to canonical QgsProject instance
void setFieldEditable(int idx, bool editable)
set edit widget editable
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void setLabelOnTop(int idx, bool onTop)
label widget on top
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.