1+ /* **************************************************************************
2+ qgskeyvaluewidgetfactory.cpp
3+ --------------------------------------
4+ Date : 08.2016
5+ Copyright : (C) 2016 Patrick Valsecchi
6+ Email : patrick.valsecchi@camptocamp.com
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+
16+ #include " qgskeyvaluewidgetfactory.h"
17+ #include " qgskeyvaluewidgetwrapper.h"
18+ #include " qgsdummyconfigdlg.h"
19+ #include " qgsfield.h"
20+ #include " qgsvectorlayer.h"
21+
22+ #include < QVariant>
23+ #include < QSettings>
24+
25+ QgsKeyValueWidgetFactory::QgsKeyValueWidgetFactory ( const QString& name ):
26+ QgsEditorWidgetFactory( name )
27+ {
28+ }
29+
30+ QgsEditorWidgetWrapper* QgsKeyValueWidgetFactory::create ( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
31+ {
32+ return new QgsKeyValueWidgetWrapper ( vl, fieldIdx, editor, parent );
33+ }
34+
35+ QgsEditorConfigWidget* QgsKeyValueWidgetFactory::configWidget ( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const
36+ {
37+ Q_UNUSED ( vl );
38+ Q_UNUSED ( fieldIdx );
39+ Q_UNUSED ( parent );
40+ return new QgsDummyConfigDlg ( vl, fieldIdx, parent, QObject::tr ( " Key/Value field" ) );
41+ }
42+
43+ QgsEditorWidgetConfig QgsKeyValueWidgetFactory::readConfig ( const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx )
44+ {
45+ Q_UNUSED ( configElement );
46+ Q_UNUSED ( layer );
47+ Q_UNUSED ( fieldIdx );
48+ return QgsEditorWidgetConfig ();
49+ }
50+
51+ void QgsKeyValueWidgetFactory::writeConfig ( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
52+ {
53+ Q_UNUSED ( config );
54+ Q_UNUSED ( configElement );
55+ Q_UNUSED ( doc );
56+ Q_UNUSED ( layer );
57+ Q_UNUSED ( fieldIdx );
58+ }
59+
60+ QString QgsKeyValueWidgetFactory::representValue ( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const
61+ {
62+ Q_UNUSED ( vl );
63+ Q_UNUSED ( fieldIdx );
64+ Q_UNUSED ( config );
65+ Q_UNUSED ( cache );
66+
67+ if ( value.isNull () )
68+ {
69+ QSettings settings;
70+ return settings.value ( " qgis/nullValue" , " NULL" ).toString ();
71+ }
72+
73+ QString result;
74+ const QVariantMap map = value.toMap ();
75+ for ( QVariantMap::const_iterator i = map.constBegin (); i != map.constEnd (); ++i )
76+ {
77+ if ( !result.isEmpty () ) result.append ( " , " );
78+ result.append ( i.key () ).append ( " : " ).append ( i.value ().toString () );
79+ }
80+ return result;
81+ }
82+
83+ Qt::AlignmentFlag QgsKeyValueWidgetFactory::alignmentFlag ( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const
84+ {
85+ Q_UNUSED ( vl );
86+ Q_UNUSED ( fieldIdx );
87+ Q_UNUSED ( config );
88+
89+ return Qt::AlignLeft;
90+ }
91+
92+ unsigned int QgsKeyValueWidgetFactory::fieldScore ( const QgsVectorLayer* vl, int fieldIdx ) const
93+ {
94+ const QgsField field = vl->fields ().field ( fieldIdx );
95+ return field.type () == QVariant::Map ? 20 : 0 ;
96+ }
0 commit comments