QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 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 
16 #include "qgslegacyhelpers.h"
17 
18 #include "qgsvectorlayer.h"
19 
21 {
22  QString widgetType = "TextEdit"; // Fallback
23 
24  switch ( editType )
25  {
27  {
28  widgetType = "ValueMap";
29  QDomNodeList valueMapNodes = editTypeElement.childNodes();
30 
31  for ( int j = 0; j < valueMapNodes.size(); j++ )
32  {
33  QDomElement value = valueMapNodes.at( j ).toElement();
34  cfg.insert( value.attribute( "key" ), value.attribute( "value" ) );
35  }
36  break;
37  }
38 
40  {
41  widgetType = "Range";
42  cfg.insert( "Style", "Edit" );
43  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
44  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
45  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
46  break;
47  }
48 
50  {
51  widgetType = "SliderRange";
52  cfg.insert( "Style", "Slider" );
53  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
54  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
55  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
56  break;
57  }
58 
60  {
61  widgetType = "DialRange";
62  cfg.insert( "Style", "Dial" );
63  cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
64  cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
65  cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
66  break;
67  }
68 
70  {
71  widgetType = "CheckBox";
72  cfg.insert( "CheckedState", editTypeElement.attribute( "checked" ) );
73  cfg.insert( "UncheckedState", editTypeElement.attribute( "unchecked" ) );
74  break;
75  }
76 
78  {
79  widgetType = "ValueRelation";
80  cfg.insert( "AllowNull", editTypeElement.attribute( "allowNull" ) == "true" );
81  cfg.insert( "OrderByValue", editTypeElement.attribute( "orderByValue" ) == "true" );
82  cfg.insert( "AllowMulti", editTypeElement.attribute( "allowMulti", "false" ) == "true" );
83  QString filterExpression;
84  if ( editTypeElement.hasAttribute( "filterAttributeColumn" ) &&
85  editTypeElement.hasAttribute( "filterAttributeValue" ) )
86  {
87  filterExpression = QString( "\"%1\"='%2'" )
88  .arg( editTypeElement.attribute( "filterAttributeColumn" ) )
89  .arg( editTypeElement.attribute( "filterAttributeValue" ) );
90  }
91  else
92  {
93  filterExpression = editTypeElement.attribute( "filterExpression", QString::null );
94  }
95  cfg.insert( "FilterExpression", filterExpression );
96  cfg.insert( "Layer", editTypeElement.attribute( "layer" ) );
97  cfg.insert( "Key", editTypeElement.attribute( "key" ) );
98  cfg.insert( "Value", editTypeElement.attribute( "value" ) );
99 
100  break;
101  }
102 
104  {
105  widgetType = "DateTime";
106  cfg.insert( "display_format", editTypeElement.attribute( "dateFormat" ) );
107  cfg.insert( "field_format", "yyyy-MM-dd" );
108  break;
109  }
110 
112  {
113  widgetType = "Photo";
114  cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
115  cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
116  break;
117  }
118 
120  {
121  widgetType = "WebView";
122  cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
123  cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
124  break;
125  }
126 
128  {
129  widgetType = "Classification";
130  break;
131  }
132 
134  {
135  widgetType = "FileName";
136  break;
137  }
138 
140  {
141  widgetType = "TextEdit";
142  cfg.insert( "IsMultiline", false );
143  vl->setFieldEditable( vl->pendingFields().fieldNameIndex( name ), false );
144  break;
145  }
146 
148  {
149  widgetType = "Hidden";
150  break;
151  }
152 
154  {
155  widgetType = "TextEdit";
156  cfg.insert( "IsMultiline", false );
157  break;
158  }
159 
161  {
162  widgetType = "TextEdit";
163  cfg.insert( "IsMultiline", true );
164  cfg.insert( "UseHtml", false );
165  break;
166  }
167 
169  {
170  widgetType = "Enumeration";
171  break;
172  }
173 
175  {
176  widgetType = "UniqueValues";
177  cfg.insert( "Editable", false );
178  break;
179  }
180 
182  {
183  widgetType = "UniqueValues";
184  cfg.insert( "Editable", true );
185  break;
186  }
187 
189  {
190  widgetType = "UuidGenerator";
191  break;
192  }
193 
195  {
196  widgetType = "Color";
197  break;
198  }
199 
200  case QgsVectorLayer::EditorWidgetV2: // Should not land here
201  break;
202  }
203 
204  return widgetType;
205 }
206 
208 {
209  int idx = vl->fieldNameIndex( name );
210 
211  if ( !vl->fieldEditable( idx ) )
212  {
214  }
215 
216  if ( editType == "Hidden" )
217  {
218  return QgsVectorLayer::Hidden;
219  }
220 
221  if ( editType == "ValueMap" )
222  {
224  }
225 
226  if ( editType == "TextEdit" )
227  {
228  if ( cfg.value( "IsMultiline" ).toBool() )
229  {
231  }
232  else
233  {
235  }
236  }
237 
238  if ( editType == "Range" )
239  {
240  if ( cfg.value( "Style" ).toString() == "SliderRange" )
241  {
243  }
244  else if ( cfg.value( "Style" ).toString() == "DialRange" )
245  {
247  }
248  else
249  {
251  }
252  }
253 
254  if ( editType == "UuidGenerator" )
255  {
257  }
258 
259  if ( editType == "UniqueValues" )
260  {
261  if ( cfg.value( "Editable" ).toBool() )
262  {
264  }
265  else
266  {
268 
269  }
270  }
271 
272  if ( editType == "Classification" )
273  {
275  }
276 
277  if ( editType == "CheckBox" )
278  {
280  }
281 
282  if ( editType == "DateTime" )
283  {
285  }
286 
287  if ( editType == "FileName" )
288  {
290  }
291 
292  if ( editType == "WebView" )
293  {
295  }
296 
297  if ( editType == "Photo" )
298  {
299  return QgsVectorLayer::Photo;
300  }
301 
302  if ( editType == "Color" )
303  {
304  return QgsVectorLayer::Color;
305  }
306 
307  if ( editType == "Enumeration" )
308  {
310  }
311 
313 }
bool fieldEditable(int idx)
is edit widget editable
QString attribute(const QString &name, const QString &defValue) const
The attribute value should not be changed in the attribute form.
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs...
Definition: qgsfield.cpp:354
QDomNodeList childNodes() const
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
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
void setFieldEditable(int idx, bool editable)
set edit widget editable
iterator insert(const Key &key, const T &value)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
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