-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsrangewidgetfactory.cpp
86 lines (73 loc) · 3.09 KB
/
qgsrangewidgetfactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************************************************
qgsrangewidgetfactory.cpp
--------------------------------------
Date : 5.1.2014
Copyright : (C) 2014 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsrangewidgetfactory.h"
#include "qgsrangeconfigdlg.h"
#include "qgsrangewidgetwrapper.h"
#include "qgsvectorlayer.h"
QgsRangeWidgetFactory::QgsRangeWidgetFactory( QString name )
: QgsEditorWidgetFactory( name )
{
}
QgsEditorWidgetWrapper* QgsRangeWidgetFactory::create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const
{
return new QgsRangeWidgetWrapper( vl, fieldIdx, editor, parent );
}
QgsEditorConfigWidget* QgsRangeWidgetFactory::configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
{
return new QgsRangeConfigDlg( vl, fieldIdx, parent );
}
QgsEditorWidgetConfig QgsRangeWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
Q_UNUSED( layer );
Q_UNUSED( fieldIdx );
QMap<QString, QVariant> cfg;
cfg.insert( "Style", configElement.attribute( "Style" ) );
cfg.insert( "Min", configElement.attribute( "Min" ) );
cfg.insert( "Max", configElement.attribute( "Max" ) );
cfg.insert( "Step", configElement.attribute( "Step" ) );
cfg.insert( "AllowNull", configElement.attribute( "AllowNull" ) == "1" );
if ( configElement.hasAttribute( "Suffix" ) )
{
cfg.insert( "Suffix", configElement.attribute( "Suffix" ) );
}
return cfg;
}
void QgsRangeWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
{
Q_UNUSED( doc );
Q_UNUSED( layer );
Q_UNUSED( fieldIdx );
configElement.setAttribute( "Style", config["Style"].toString() );
configElement.setAttribute( "Min", config["Min"].toString() );
configElement.setAttribute( "Max", config["Max"].toString() );
configElement.setAttribute( "Step", config["Step"].toString() );
configElement.setAttribute( "AllowNull", config["AllowNull"].toBool() );
if ( config.contains( "Suffix" ) )
{
configElement.setAttribute( "Suffix", config["Suffix"].toString() );
}
}
bool QgsRangeWidgetFactory::isFieldSupported( QgsVectorLayer* vl, int fieldIdx )
{
switch ( vl->pendingFields()[fieldIdx].type() )
{
case QVariant::LongLong:
case QVariant::Double:
case QVariant::Int:
return true;
default:
return false;
}
}