QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 dot kuhn at gmx 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 
19 #include "qgsvaluemapconfigdlg.h"
20 
22  : QgsEditorWidgetFactory( name )
23 {
24 }
25 
26 
28 {
29  return new QgsValueMapWidgetWrapper( vl, fieldIdx, editor, parent );
30 }
31 
32 
34 {
35  return new QgsValueMapWidgetWrapper( vl, fieldIdx, 0, parent );
36 }
37 
39 {
40  return new QgsValueMapConfigDlg( vl, fieldIdx, parent );
41 }
42 
44 {
45  Q_UNUSED( layer )
46  Q_UNUSED( fieldIdx )
47 
49 
50  QDomNodeList nodes = configElement.elementsByTagName( "value" );
51 
52  for ( unsigned int i = 0; i < nodes.length(); ++i )
53  {
54  QDomElement elem = nodes.at( i ).toElement();
55  cfg.insert( elem.attribute( "key" ), elem.attribute( "value" ) );
56  }
57 
58  return cfg;
59 }
60 
61 void QgsValueMapWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
62 {
63  Q_UNUSED( layer )
64  Q_UNUSED( fieldIdx )
65 
67 
68  while ( it != config.constEnd() )
69  {
70  QDomElement elem = doc.createElement( "value" );
71 
72  elem.setAttribute( "key", it.key() );
73  elem.setAttribute( "value", it.value().toString() );
74 
75  configElement.appendChild( elem );
76 
77  ++it;
78  }
79 }
80 
81 QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
82 {
83  Q_UNUSED( vl )
84  Q_UNUSED( fieldIdx )
85  Q_UNUSED( cache )
86 
87  return config.key( value, QVariant( QString( "(%1)" ).arg( value.toString() ) ).toString() );
88 }
QDomNodeList elementsByTagName(const QString &tagname) const
QgsEditorWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override in own factory to get something different than the default (a simple QgsFilterLineEdit) ...
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.
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.
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)
uint length() 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