Skip to content

Commit 8d9cf9d

Browse files
pvalseccPatrick Valsecchi
authored and
Patrick Valsecchi
committed
Fix auto conf of QgsRangeWidgetWrapper
The default range was 0..100, made it to min..max of the type. QgsRangeWidgetWrapper is auto selected only for Int and Double QVariants, now. The used widgets don't support 64 bits and Uint ranges.
1 parent 45373d0 commit 8d9cf9d

File tree

6 files changed

+55
-79
lines changed

6 files changed

+55
-79
lines changed

src/gui/editorwidgets/qgsrangeconfigdlg.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ QgsEditorWidgetConfig QgsRangeConfigDlg::config()
100100

101101
void QgsRangeConfigDlg::setConfig( const QgsEditorWidgetConfig& config )
102102
{
103-
minimumDoubleSpinBox->setValue( config.value( "Min", 0.0 ).toDouble() );
104-
maximumDoubleSpinBox->setValue( config.value( "Max", 5.0 ).toDouble() );
103+
minimumDoubleSpinBox->setValue( config.value( "Min", -std::numeric_limits<double>::max() ).toDouble() );
104+
maximumDoubleSpinBox->setValue( config.value( "Max", std::numeric_limits<double>::max() ).toDouble() );
105105
stepDoubleSpinBox->setValue( config.value( "Step", 1.0 ).toDouble() );
106106

107-
minimumSpinBox->setValue( config.value( "Min", 0 ).toInt() );
108-
maximumSpinBox->setValue( config.value( "Max", 5 ).toInt() );
107+
minimumSpinBox->setValue( config.value( "Min", std::numeric_limits<int>::min() ).toInt() );
108+
maximumSpinBox->setValue( config.value( "Max", std::numeric_limits<int>::max() ).toInt() );
109109
stepSpinBox->setValue( config.value( "Step", 1 ).toInt() );
110110

111111
rangeWidget->setCurrentIndex( rangeWidget->findData( config.value( "Style", "SpinBox" ) ) );

src/gui/editorwidgets/qgsrangewidgetfactory.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ void QgsRangeWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QD
7373

7474
unsigned int QgsRangeWidgetFactory::fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const
7575
{
76-
return vl->fields().at( fieldIdx ).isNumeric() ? 20 : 0;
76+
const QgsField field = vl->fields().at( fieldIdx );
77+
if ( field.type() == QVariant::Int || field.type() == QVariant::Double ) return 20;
78+
if ( field.isNumeric() ) return 5; // widgets used support only signed 32bits (int) and double
79+
return 0;
7780
}
7881

7982
QMap<const char*, int> QgsRangeWidgetFactory::supportedWidgetTypes()

src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

+23-62
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,21 @@ QWidget* QgsRangeWidgetWrapper::createWidget( QWidget* parent )
6565
return editor;
6666
}
6767

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+
6878
void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
6979
{
7080
mDoubleSpinBox = qobject_cast<QDoubleSpinBox*>( editor );
7181
mIntSpinBox = qobject_cast<QSpinBox*>( editor );
82+
7283
mDial = qobject_cast<QDial*>( editor );
7384
mSlider = qobject_cast<QSlider*>( editor );
7485
mQgsDial = qobject_cast<QgsDial*>( editor );
@@ -107,90 +118,40 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
107118
mDoubleSpinBox->setValue( minval );
108119
mDoubleSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
109120
}
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 );
116124
if ( config( "Suffix" ).isValid() )
117125
mDoubleSpinBox->setSuffix( config( "Suffix" ).toString() );
118126

119127
connect( mDoubleSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( valueChanged( double ) ) );
120128
}
121-
122-
if ( mIntSpinBox )
129+
else if ( mIntSpinBox )
123130
{
124-
int minval = min.toInt();
125-
int stepval = step.toInt();
126131
QgsSpinBox* qgsWidget = dynamic_cast<QgsSpinBox*>( mIntSpinBox );
127132
if ( qgsWidget )
128133
qgsWidget->setShowClearButton( allowNull );
129134
if ( allowNull )
130135
{
136+
int minval = min.toInt();
137+
int stepval = step.toInt();
131138
minval -= stepval;
132139
mIntSpinBox->setValue( minval );
133140
mIntSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
134141
}
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 );
141143
if ( config( "Suffix" ).isValid() )
142144
mIntSpinBox->setSuffix( config( "Suffix" ).toString() );
143-
connect( mIntSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
144145
}
145-
146-
147-
if ( mQgsDial || mQgsSlider )
146+
else
148147
{
149148
field().convertCompatible( min );
150149
field().convertCompatible( max );
151150
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 );
194155
}
195156
}
196157

src/gui/editorwidgets/qgsrangewidgetwrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QSpinBox>
2222
#include <QDoubleSpinBox>
2323

24+
class QAbstractSlider;
2425
class QSlider;
2526
class QDial;
2627
class QgsSlider;

src/ui/editorwidgets/qgsrangeconfigdlgbase.ui

+18-12
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@
9393
<item row="0" column="1">
9494
<widget class="QSpinBox" name="minimumSpinBox">
9595
<property name="minimum">
96-
<number>-999999999</number>
96+
<number>−2147483648</number>
9797
</property>
9898
<property name="maximum">
99-
<number>999999999</number>
99+
<number>2147483647</number>
100+
</property>
101+
<property name="value">
102+
<number>−2147483648</number>
100103
</property>
101104
</widget>
102105
</item>
@@ -110,13 +113,13 @@
110113
<item row="1" column="1">
111114
<widget class="QSpinBox" name="maximumSpinBox">
112115
<property name="minimum">
113-
<number>-999999999</number>
116+
<number>−2147483648</number>
114117
</property>
115118
<property name="maximum">
116-
<number>999999999</number>
119+
<number>2147483647</number>
117120
</property>
118121
<property name="value">
119-
<number>5</number>
122+
<number>2147483647</number>
120123
</property>
121124
</widget>
122125
</item>
@@ -130,7 +133,7 @@
130133
<item row="2" column="1">
131134
<widget class="QSpinBox" name="stepSpinBox">
132135
<property name="maximum">
133-
<number>999999999</number>
136+
<number>2147483647</number>
134137
</property>
135138
<property name="value">
136139
<number>1</number>
@@ -168,30 +171,33 @@
168171
<item row="0" column="1">
169172
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox">
170173
<property name="minimum">
171-
<double>-999999999.990000009536743</double>
174+
<double>-1.79769e+308</double>
172175
</property>
173176
<property name="maximum">
174-
<double>999999999.990000009536743</double>
177+
<double>1.79769e+308</double>
178+
</property>
179+
<property name="value">
180+
<double>-1.79769e+308</double>
175181
</property>
176182
</widget>
177183
</item>
178184
<item row="1" column="1">
179185
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox">
180186
<property name="minimum">
181-
<double>-999999999.990000009536743</double>
187+
<double>-1.79769e+308</double>
182188
</property>
183189
<property name="maximum">
184-
<double>999999999.990000009536743</double>
190+
<double>1.79769e+308</double>
185191
</property>
186192
<property name="value">
187-
<double>5.000000000000000</double>
193+
<double>1.79769e+308</double>
188194
</property>
189195
</widget>
190196
</item>
191197
<item row="2" column="1">
192198
<widget class="QDoubleSpinBox" name="stepDoubleSpinBox">
193199
<property name="maximum">
194-
<double>999999999.990000009536743</double>
200+
<double>1.79769e+308</double>
195201
</property>
196202
<property name="value">
197203
<double>1.000000000000000</double>

tests/src/gui/testqgseditorwidgetregistry.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class TestQgsEditorWidgetRegistry: public QObject
6868
checkSimple( "integer", "Range" );
6969
}
7070

71+
void longLongType()
72+
{
73+
checkSimple( "int8", "TextEdit" ); // no current widget supports 64 bit integers => default to TextEdit
74+
}
75+
7176
void doubleType()
7277
{
7378
checkSimple( "double", "Range" );

0 commit comments

Comments
 (0)