@@ -65,10 +65,21 @@ QWidget* QgsRangeWidgetWrapper::createWidget( QWidget* parent )
65
65
return editor;
66
66
}
67
67
68
+ template <class T >
69
+ static void setupIntEditor ( const QVariant& min, const QVariant& max, const QVariant& step, T* slider, QgsRangeWidgetWrapper* wrapper )
70
+ {
71
+ // must use a template function because those methods are overloaded and not inherited by some classes
72
+ slider->setMinimum ( min.isValid () ? min.toInt () : std::numeric_limits<int >::min () );
73
+ slider->setMaximum ( max.isValid () ? max.toInt () : std::numeric_limits<int >::max () );
74
+ slider->setSingleStep ( step.isValid () ? step.toInt () : 1 );
75
+ QObject::connect ( slider, SIGNAL ( valueChanged ( int ) ), wrapper, SLOT ( valueChanged ( int ) ) );
76
+ }
77
+
68
78
void QgsRangeWidgetWrapper::initWidget ( QWidget* editor )
69
79
{
70
80
mDoubleSpinBox = qobject_cast<QDoubleSpinBox*>( editor );
71
81
mIntSpinBox = qobject_cast<QSpinBox*>( editor );
82
+
72
83
mDial = qobject_cast<QDial*>( editor );
73
84
mSlider = qobject_cast<QSlider*>( editor );
74
85
mQgsDial = qobject_cast<QgsDial*>( editor );
@@ -107,90 +118,40 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
107
118
mDoubleSpinBox ->setValue ( minval );
108
119
mDoubleSpinBox ->setSpecialValueText ( QSettings ().value ( " qgis/nullValue" , " NULL" ).toString () );
109
120
}
110
- if ( min.isValid () )
111
- mDoubleSpinBox ->setMinimum ( min.toDouble () );
112
- if ( max.isValid () )
113
- mDoubleSpinBox ->setMaximum ( max.toDouble () );
114
- if ( step.isValid () )
115
- mDoubleSpinBox ->setSingleStep ( step.toDouble () );
121
+ mDoubleSpinBox ->setMinimum ( min.isValid () ? min.toDouble () : std::numeric_limits<double >::min () );
122
+ mDoubleSpinBox ->setMaximum ( max.isValid () ? max.toDouble () : std::numeric_limits<double >::max () );
123
+ mDoubleSpinBox ->setSingleStep ( step.isValid () ? step.toDouble () : 1.0 );
116
124
if ( config ( " Suffix" ).isValid () )
117
125
mDoubleSpinBox ->setSuffix ( config ( " Suffix" ).toString () );
118
126
119
127
connect ( mDoubleSpinBox , SIGNAL ( valueChanged ( double ) ), this , SLOT ( valueChanged ( double ) ) );
120
128
}
121
-
122
- if ( mIntSpinBox )
129
+ else if ( mIntSpinBox )
123
130
{
124
- int minval = min.toInt ();
125
- int stepval = step.toInt ();
126
131
QgsSpinBox* qgsWidget = dynamic_cast <QgsSpinBox*>( mIntSpinBox );
127
132
if ( qgsWidget )
128
133
qgsWidget->setShowClearButton ( allowNull );
129
134
if ( allowNull )
130
135
{
136
+ int minval = min.toInt ();
137
+ int stepval = step.toInt ();
131
138
minval -= stepval;
132
139
mIntSpinBox ->setValue ( minval );
133
140
mIntSpinBox ->setSpecialValueText ( QSettings ().value ( " qgis/nullValue" , " NULL" ).toString () );
134
141
}
135
- if ( min.isValid () )
136
- mIntSpinBox ->setMinimum ( min.toInt () );
137
- if ( max.isValid () )
138
- mIntSpinBox ->setMaximum ( max.toInt () );
139
- if ( step.isValid () )
140
- mIntSpinBox ->setSingleStep ( step.toInt () );
142
+ setupIntEditor ( min, max, step, mIntSpinBox , this );
141
143
if ( config ( " Suffix" ).isValid () )
142
144
mIntSpinBox ->setSuffix ( config ( " Suffix" ).toString () );
143
- connect ( mIntSpinBox , SIGNAL ( valueChanged ( int ) ), this , SLOT ( valueChanged ( int ) ) );
144
145
}
145
-
146
-
147
- if ( mQgsDial || mQgsSlider )
146
+ else
148
147
{
149
148
field ().convertCompatible ( min );
150
149
field ().convertCompatible ( max );
151
150
field ().convertCompatible ( step );
152
-
153
- if ( mQgsSlider )
154
- {
155
- if ( min.isValid () )
156
- mQgsSlider ->setMinimum ( min );
157
- if ( max.isValid () )
158
- mQgsSlider ->setMaximum ( max );
159
- if ( step.isValid () )
160
- mQgsSlider ->setSingleStep ( step );
161
- }
162
-
163
- if ( mQgsDial )
164
- {
165
- if ( min.isValid () )
166
- mQgsDial ->setMinimum ( min );
167
- if ( max.isValid () )
168
- mQgsDial ->setMaximum ( max );
169
- if ( step.isValid () )
170
- mQgsDial ->setSingleStep ( step );
171
- }
172
-
173
- connect ( editor, SIGNAL ( valueChanged ( QVariant ) ), this , SLOT ( valueChangedVariant ( QVariant ) ) );
174
- }
175
- else if ( mDial )
176
- {
177
- if ( min.isValid () )
178
- mDial ->setMinimum ( min.toInt () );
179
- if ( max.isValid () )
180
- mDial ->setMaximum ( max.toInt () );
181
- if ( step.isValid () )
182
- mDial ->setSingleStep ( step.toInt () );
183
- connect ( mDial , SIGNAL ( valueChanged ( int ) ), this , SLOT ( valueChanged ( int ) ) );
184
- }
185
- else if ( mSlider )
186
- {
187
- if ( min.isValid () )
188
- mSlider ->setMinimum ( min.toInt () );
189
- if ( max.isValid () )
190
- mSlider ->setMaximum ( max.toInt () );
191
- if ( step.isValid () )
192
- mSlider ->setSingleStep ( step.toInt () );
193
- connect ( mSlider , SIGNAL ( valueChanged ( int ) ), this , SLOT ( valueChanged ( int ) ) );
151
+ if ( mQgsDial ) setupIntEditor ( min, max, step, mQgsDial , this );
152
+ else if ( mQgsSlider ) setupIntEditor ( min, max, step, mQgsSlider , this );
153
+ else if ( mDial ) setupIntEditor ( min, max, step, mDial , this );
154
+ else if ( mSlider ) setupIntEditor ( min, max, step, mSlider , this );
194
155
}
195
156
}
196
157
0 commit comments