QGIS API Documentation  2.8.2-Wien
 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 
27 QgsEditorWidgetWrapper* QgsValueMapWidgetFactory::create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const
28 {
29  return new QgsValueMapWidgetWrapper( vl, fieldIdx, editor, parent );
30 }
31 
33 {
34  return new QgsValueMapConfigDlg( vl, fieldIdx, parent );
35 }
36 
37 QgsEditorWidgetConfig QgsValueMapWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
38 {
39  Q_UNUSED( layer )
40  Q_UNUSED( fieldIdx )
41 
43 
44  QDomNodeList nodes = configElement.elementsByTagName( "value" );
45 
46  for ( unsigned int i = 0; i < nodes.length(); ++i )
47  {
48  QDomElement elem = nodes.at( i ).toElement();
49  cfg.insert( elem.attribute( "key" ), elem.attribute( "value" ) );
50  }
51 
52  return cfg;
53 }
54 
55 void QgsValueMapWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
56 {
57  Q_UNUSED( layer )
58  Q_UNUSED( fieldIdx )
59 
60  QgsEditorWidgetConfig::ConstIterator it = config.constBegin();
61 
62  while ( it != config.constEnd() )
63  {
64  QDomElement elem = doc.createElement( "value" );
65 
66  elem.setAttribute( "key", it.key() );
67  elem.setAttribute( "value", it.value().toString() );
68 
69  configElement.appendChild( elem );
70 
71  ++it;
72  }
73 }
74 
75 QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
76 {
77  Q_UNUSED( vl )
78  Q_UNUSED( fieldIdx )
79  Q_UNUSED( cache )
80 
81  return config.key( value, QVariant( QString( "(%1)" ).arg( value.toString() ) ).toString() );
82 }