QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrangewidgetfactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrangewidgetfactory.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 
16 #include "qgsrangewidgetfactory.h"
17 #include "qgsrangeconfigdlg.h"
18 #include "qgsrangewidgetwrapper.h"
19 #include "qgsvectorlayer.h"
20 
21 
23  : QgsEditorWidgetFactory( name )
24 {
25 }
26 
27 QgsEditorWidgetWrapper* QgsRangeWidgetFactory::create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const
28 {
29  return new QgsRangeWidgetWrapper( vl, fieldIdx, editor, parent );
30 }
31 
32 QgsEditorConfigWidget* QgsRangeWidgetFactory::configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
33 {
34  return new QgsRangeConfigDlg( vl, fieldIdx, parent );
35 }
36 
37 QgsEditorWidgetConfig QgsRangeWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
38 {
39  Q_UNUSED( layer );
40  Q_UNUSED( fieldIdx );
41  QMap<QString, QVariant> cfg;
42 
43  cfg.insert( "Style", configElement.attribute( "Style" ) );
44  cfg.insert( "Min", configElement.attribute( "Min" ).toInt() );
45  cfg.insert( "Max", configElement.attribute( "Max" ).toInt() );
46  cfg.insert( "Step", configElement.attribute( "Step" ).toInt() );
47  cfg.insert( "AllowNull", configElement.attribute( "AllowNull" ) == "1" );
48 
49  if ( configElement.hasAttribute( "Suffix" ) )
50  {
51  cfg.insert( "Suffix", configElement.attribute( "Suffix" ) );
52  }
53 
54  return cfg;
55 }
56 
57 void QgsRangeWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
58 {
59  Q_UNUSED( doc );
60  Q_UNUSED( layer );
61  Q_UNUSED( fieldIdx );
62 
63  configElement.setAttribute( "Style", config["Style"].toString() );
64  configElement.setAttribute( "Min", config["Min"].toInt() );
65  configElement.setAttribute( "Max", config["Max"].toInt() );
66  configElement.setAttribute( "Step", config["Step"].toInt() );
67  configElement.setAttribute( "AllowNull", config["AllowNull"].toBool() );
68  if ( config.contains( "Suffix" ) )
69  {
70  configElement.setAttribute( "Suffix", config["Suffix"].toString() );
71  }
72 }
73 
74 bool QgsRangeWidgetFactory::isFieldSupported( QgsVectorLayer* vl, int fieldIdx )
75 {
76  switch ( vl->pendingFields()[fieldIdx].type() )
77  {
78  case QVariant::LongLong:
79  case QVariant::Double:
80  case QVariant::Int:
81  return true;
82 
83  default:
84  return false;
85  }
86 }