QGIS API Documentation  2.12.0-Lyon
qgsvaluemapwidgetfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvaluemapwidgetfactory.cpp
3  --------------------------------------
4  Date : 5.1.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
21 #include "qgsvaluemapconfigdlg.h"
22 
24  : QgsEditorWidgetFactory( name )
25 {
26 }
27 
28 
30 {
31  return new QgsValueMapWidgetWrapper( vl, fieldIdx, editor, parent );
32 }
33 
34 
36 {
37  return new QgsValueMapSearchWidgetWrapper( vl, fieldIdx, parent );
38 }
39 
41 {
42  return new QgsValueMapConfigDlg( vl, fieldIdx, parent );
43 }
44 
46 {
47  Q_UNUSED( layer )
48  Q_UNUSED( fieldIdx )
49 
51 
52  QDomNodeList nodes = configElement.elementsByTagName( "value" );
53 
54  for ( int i = 0; i < nodes.size(); ++i )
55  {
56  QDomElement elem = nodes.at( i ).toElement();
57  cfg.insert( elem.attribute( "key" ), elem.attribute( "value" ) );
58  }
59 
60  return cfg;
61 }
62 
63 void QgsValueMapWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
64 {
65  Q_UNUSED( layer )
66  Q_UNUSED( fieldIdx )
67 
69 
70  while ( it != config.constEnd() )
71  {
72  QDomElement elem = doc.createElement( "value" );
73 
74  elem.setAttribute( "key", it.key() );
75  elem.setAttribute( "value", it.value().toString() );
76 
77  configElement.appendChild( elem );
78 
79  ++it;
80  }
81 }
82 
83 QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
84 {
85  Q_UNUSED( vl )
86  Q_UNUSED( fieldIdx )
87  Q_UNUSED( cache )
88 
89  return config.key( value, QVariant( QString( "(%1)" ).arg( value.toString() ) ).toString() );
90 }
91 
93 {
95  map.insert( QComboBox::staticMetaObject.className(), 10 );
96  return map;
97 }
QDomNodeList elementsByTagName(const QString &tagname) const
Manages an editor widget Widget and wrapper share the same parent.
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
This class should be subclassed for every configurable editor widget type.
Wraps a value map widget.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
Manages an editor widget Widget and wrapper share the same parent.
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
const_iterator constBegin() const
QString representValue(QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value) const override
Create a pretty String representation of the value.
QDomElement toElement() const
void setAttribute(const QString &name, const QString &value)
const_iterator constEnd() const
Every attribute editor widget needs a factory, which inherits this class.
virtual QMap< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
QgsEditorWidgetConfig readConfig(const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx) override
Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.
const Key key(const T &value) const
QgsValueMapWidgetFactory(const QString &name)
iterator insert(const Key &key, const T &value)
int size() const
QDomElement createElement(const QString &tagName)
typedef ConstIterator
Represents a vector layer which manages a vector based data sets.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
QString toString() const
void writeConfig(const QgsEditorWidgetConfig &config, QDomElement &configElement, QDomDocument &doc, const QgsVectorLayer *layer, int fieldIdx) override
Serialize your configuration and save it in a xml doc.
QDomNode at(int index) const