QGIS API Documentation  2.14.0-Essen
qgslegacyhelpers.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegacyhelpers.cpp
3  --------------------------------------
4  Date : 13.5.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 
16 #include "qgslegacyhelpers.h"
17 
18 #include "qgsvectorlayer.h"
19 
21 {
23  QString widgetType = "TextEdit"; // Fallback
24 
25  switch ( editType )
26  {
28  {
29  widgetType = "ValueMap";
30  QDomNodeList valueMapNodes = editTypeElement.childNodes();
31 
32  for ( int j = 0; j < valueMapNodes.size(); j++ )
33  {
34  QDomElement value = valueMapNodes.at( j ).toElement();
35  cfg.insert( value.attribute( "key" ), value.attribute( "value" ) );
36  }
37  break;
38  }
39 
41  {
42  widgetType = "Range";
43  cfg.insert( "Style", "Edit" );
44  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
45  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
46  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
47  break;
48  }
49 
51  {
52  widgetType = "SliderRange";
53  cfg.insert( "Style", "Slider" );
54  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
55  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
56  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
57  break;
58  }
59 
61  {
62  widgetType = "DialRange";
63  cfg.insert( "Style", "Dial" );
64  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
65  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
66  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
67  break;
68  }
69 
71  {
72  widgetType = "CheckBox";
73  cfg.insert( "CheckedState", editTypeElement.attribute( "checked" ) );
74  cfg.insert( "UncheckedState", editTypeElement.attribute( "unchecked" ) );
75  break;
76  }
77 
79  {
80  widgetType = "ValueRelation";
81  cfg.insert( "AllowNull", editTypeElement.attribute( "allowNull" ) == "true" );
82  cfg.insert( "OrderByValue", editTypeElement.attribute( "orderByValue" ) == "true" );
83  cfg.insert( "AllowMulti", editTypeElement.attribute( "allowMulti", "false" ) == "true" );
84  QString filterExpression;
85  if ( editTypeElement.hasAttribute( "filterAttributeColumn" ) &&
86  editTypeElement.hasAttribute( "filterAttributeValue" ) )
87  {
88  filterExpression = QString( "\"%1\"='%2'" )
89  .arg( editTypeElement.attribute( "filterAttributeColumn" ),
90  editTypeElement.attribute( "filterAttributeValue" ) );
91  }
92  else
93  {
94  filterExpression = editTypeElement.attribute( "filterExpression", QString::null );
95  }
96  cfg.insert( "FilterExpression", filterExpression );
97  cfg.insert( "Layer", editTypeElement.attribute( "layer" ) );
98  cfg.insert( "Key", editTypeElement.attribute( "key" ) );
99  cfg.insert( "Value", editTypeElement.attribute( "value" ) );
100 
101  break;
102  }
103 
105  {
106  widgetType = "DateTime";
107  cfg.insert( "display_format", editTypeElement.attribute( "dateFormat" ) );
108  cfg.insert( "field_format", "yyyy-MM-dd" );
109  break;
110  }
111 
113  {
114  widgetType = "Photo";
115  cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
116  cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
117  break;
118  }
119 
121  {
122  widgetType = "WebView";
123  cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
124  cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
125  break;
126  }
127 
129  {
130  widgetType = "Classification";
131  break;
132  }
133 
135  {
136  widgetType = "FileName";
137  break;
138  }
139 
141  {
142  widgetType = "TextEdit";
143  cfg.insert( "IsMultiline", false );
144  vl->setFieldEditable( vl->fields().fieldNameIndex( name ), false );
145  break;
146  }
147 
149  {
150  widgetType = "Hidden";
151  break;
152  }
153 
155  {
156  widgetType = "TextEdit";
157  cfg.insert( "IsMultiline", false );
158  break;
159  }
160 
162  {
163  widgetType = "TextEdit";
164  cfg.insert( "IsMultiline", true );
165  cfg.insert( "UseHtml", false );
166  break;
167  }
168 
170  {
171  widgetType = "Enumeration";
172  break;
173  }
174 
176  {
177  widgetType = "UniqueValues";
178  cfg.insert( "Editable", false );
179  break;
180  }
181 
183  {
184  widgetType = "UniqueValues";
185  cfg.insert( "Editable", true );
186  break;
187  }
188 
190  {
191  widgetType = "UuidGenerator";
192  break;
193  }
194 
196  {
197  widgetType = "Color";
198  break;
199  }
200 
201  case QgsVectorLayer::EditorWidgetV2: // Should not land here
202  break;
203  }
204 
205  return widgetType;
207 }
208 
210 {
212 
213  int idx = vl->fieldNameIndex( name );
214 
215  if ( !vl->fieldEditable( idx ) )
216  {
218  }
219 
220  if ( editType == "Hidden" )
221  {
222  return QgsVectorLayer::Hidden;
223  }
224 
225  if ( editType == "ValueMap" )
226  {
228  }
229 
230  if ( editType == "TextEdit" )
231  {
232  if ( cfg.value( "IsMultiline" ).toBool() )
233  {
235  }
236  else
237  {
239  }
240  }
241 
242  if ( editType == "Range" )
243  {
244  if ( cfg.value( "Style" ).toString() == "SliderRange" )
245  {
247  }
248  else if ( cfg.value( "Style" ).toString() == "DialRange" )
249  {
251  }
252  else
253  {
255  }
256  }
257 
258  if ( editType == "UuidGenerator" )
259  {
261  }
262 
263  if ( editType == "UniqueValues" )
264  {
265  if ( cfg.value( "Editable" ).toBool() )
266  {
268  }
269  else
270  {
272 
273  }
274  }
275 
276  if ( editType == "Classification" )
277  {
279  }
280 
281  if ( editType == "CheckBox" )
282  {
284  }
285 
286  if ( editType == "DateTime" )
287  {
289  }
290 
291  if ( editType == "FileName" )
292  {
294  }
295 
296  if ( editType == "WebView" )
297  {
299  }
300 
301  if ( editType == "Photo" )
302  {
303  return QgsVectorLayer::Photo;
304  }
305 
306  if ( editType == "Color" )
307  {
308  return QgsVectorLayer::Color;
309  }
310 
311  if ( editType == "Enumeration" )
312  {
314  }
315 
318 }
QString attribute(const QString &name, const QString &defValue) const
The attribute value should not be changed in the attribute form.
QgsFields fields() const
Returns the list of fields of this layer.
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:503
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:407
QDomNodeList childNodes() const
Q_DECL_DEPRECATED void setFieldEditable(int idx, bool editable)
Set edit widget editable.
QDomElement toElement() const
bool hasAttribute(const QString &name) const
The attribute value should not be shown in the attribute form.
int toInt(bool *ok, int base) const
Q_DECL_DEPRECATED bool fieldEditable(int idx)
Is edit widget editable.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:408
uuid generator - readonly and automatically intialized
static Q_DECL_DEPRECATED const QString convertEditType(QgsVectorLayer::EditType editType, QgsEditorWidgetConfig &cfg, QgsVectorLayer *vl, const QString &name, const QDomElement &editTypeElement=QDomElement())
float toFloat(bool *ok) const
iterator insert(const Key &key, const T &value)
int size() const
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.
modularized edit widgets
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
value map from an table
QDomNode at(int index) const
const T value(const Key &key) const