QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 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 "qgsrangewidgetfactory.h"
17 #include "qgsrangeconfigdlg.h"
18 #include "qgsrangewidgetwrapper.h"
19 #include "qgsvectorlayer.h"
20 
21 
23  : QgsEditorWidgetFactory( name )
24 {
25 }
26 
28 {
29  return new QgsRangeWidgetWrapper( vl, fieldIdx, editor, parent );
30 }
31 
33 {
34  return new QgsRangeConfigDlg( vl, fieldIdx, parent );
35 }
36 
38 {
39  Q_UNUSED( layer );
40  Q_UNUSED( fieldIdx );
42 
43  cfg.insert( "Style", configElement.attribute( "Style" ) );
44  cfg.insert( "Min", configElement.attribute( "Min" ) );
45  cfg.insert( "Max", configElement.attribute( "Max" ) );
46  cfg.insert( "Step", configElement.attribute( "Step" ) );
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"].toString() );
65  configElement.setAttribute( "Max", config["Max"].toString() );
66  configElement.setAttribute( "Step", config["Step"].toString() );
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->fields().at( 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 }
87 
89 {
91  map.insert( QSlider::staticMetaObject.className(), 10 );
92  map.insert( QDial::staticMetaObject.className(), 10 );
93  map.insert( QSpinBox::staticMetaObject.className(), 10 );
94  map.insert( QDoubleSpinBox::staticMetaObject.className(), 10 );
95  return map;
96 }
This class should be subclassed for every configurable editor widget type.
QString attribute(const QString &name, const QString &defValue) const
Manages an editor widget Widget and wrapper share the same parent.
QgsRangeWidgetFactory(const QString &name)
virtual QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:422
QgsFields fields() const
Returns the list of fields of this layer.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
bool hasAttribute(const QString &name) const
void setAttribute(const QString &name, const QString &value)
Wraps a range widget.
Every attribute editor widget needs a factory, which inherits this class.
virtual void writeConfig(const QgsEditorWidgetConfig &config, QDomElement &configElement, QDomDocument &doc, const QgsVectorLayer *layer, int fieldIdx) override
Serialize your configuration and save it in a xml doc.
virtual QMap< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
virtual QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
iterator insert(const Key &key, const T &value)
virtual QgsEditorWidgetConfig readConfig(const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx) override
Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.
Represents a vector layer which manages a vector based data sets.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:97