Skip to content

Commit ab607ce

Browse files
committed
[bugfix] Fix minimum values for range widgets
Fixes #17878 QGIS 3 Vector Layer Fields Garbled when Clicking the Toggle Editing Icon
1 parent fd53880 commit ab607ce

File tree

3 files changed

+43
-49
lines changed

3 files changed

+43
-49
lines changed

src/gui/editorwidgets/qgsrangeconfigdlg.cpp

+22-9
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,30 @@ QgsRangeConfigDlg::QgsRangeConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget
2222
{
2323
setupUi( this );
2424

25-
minimumSpinBox->setMinimum( std::numeric_limits<int>::min() );
25+
minimumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
2626
minimumSpinBox->setMaximum( std::numeric_limits<int>::max() );
27-
minimumSpinBox->setValue( std::numeric_limits<int>::min() );
27+
minimumSpinBox->setValue( std::numeric_limits<int>::lowest() );
2828

29-
maximumSpinBox->setMinimum( std::numeric_limits<int>::min() );
29+
maximumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
3030
maximumSpinBox->setMaximum( std::numeric_limits<int>::max() );
3131
maximumSpinBox->setValue( std::numeric_limits<int>::max() );
3232

3333
stepSpinBox->setMaximum( std::numeric_limits<int>::max() );
3434
stepSpinBox->setValue( 1 );
3535

36+
minimumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
37+
minimumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
38+
minimumDoubleSpinBox->setValue( std::numeric_limits<double>::min() );
39+
40+
maximumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
41+
maximumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
42+
maximumDoubleSpinBox->setValue( std::numeric_limits<double>::max() );
43+
44+
// Use integer here:
45+
stepDoubleSpinBox->setMaximum( std::numeric_limits<int>::max() );
46+
stepDoubleSpinBox->setValue( 1 );
47+
48+
3649
QString text;
3750

3851
switch ( vl->fields().at( fieldIdx ).type() )
@@ -44,9 +57,9 @@ QgsRangeConfigDlg::QgsRangeConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget
4457
rangeStackedWidget->setCurrentIndex( vl->fields().at( fieldIdx ).type() == QVariant::Double ? 1 : 0 );
4558

4659
rangeWidget->clear();
47-
rangeWidget->addItem( tr( "Editable" ), "SpinBox" );
48-
rangeWidget->addItem( tr( "Slider" ), "Slider" );
49-
rangeWidget->addItem( tr( "Dial" ), "Dial" );
60+
rangeWidget->addItem( tr( "Editable" ), QStringLiteral( "SpinBox" ) );
61+
rangeWidget->addItem( tr( "Slider" ), QStringLiteral( "Slider" ) );
62+
rangeWidget->addItem( tr( "Dial" ), QStringLiteral( "Dial" ) );
5063

5164
QVariant min = vl->minimumValue( fieldIdx );
5265
QVariant max = vl->maximumValue( fieldIdx );
@@ -111,11 +124,11 @@ QVariantMap QgsRangeConfigDlg::config()
111124

112125
void QgsRangeConfigDlg::setConfig( const QVariantMap &config )
113126
{
114-
minimumDoubleSpinBox->setValue( config.value( QStringLiteral( "Min" ), -std::numeric_limits<double>::max() ).toDouble() );
115-
maximumDoubleSpinBox->setValue( config.value( QStringLiteral( "Max" ), std::numeric_limits<double>::max() ).toDouble() );
127+
minimumDoubleSpinBox->setValue( config.value( QStringLiteral( "Min" ), std::numeric_limits<double>::lowest() ).toDouble( ) );
128+
maximumDoubleSpinBox->setValue( config.value( QStringLiteral( "Max" ), std::numeric_limits<double>::max() ).toDouble( ) );
116129
stepDoubleSpinBox->setValue( config.value( QStringLiteral( "Step" ), 1.0 ).toDouble() );
117130

118-
minimumSpinBox->setValue( config.value( QStringLiteral( "Min" ), std::numeric_limits<int>::min() ).toInt() );
131+
minimumSpinBox->setValue( config.value( QStringLiteral( "Min" ), std::numeric_limits<int>::lowest() ).toInt() );
119132
maximumSpinBox->setValue( config.value( QStringLiteral( "Max" ), std::numeric_limits<int>::max() ).toInt() );
120133
stepSpinBox->setValue( config.value( QStringLiteral( "Step" ), 1 ).toInt() );
121134

src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ template<class T>
6464
static void setupIntEditor( const QVariant &min, const QVariant &max, const QVariant &step, T *slider, QgsRangeWidgetWrapper *wrapper )
6565
{
6666
// must use a template function because those methods are overloaded and not inherited by some classes
67-
slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::min() );
67+
slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
6868
slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
6969
slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
7070
QObject::connect( slider, SIGNAL( valueChanged( int ) ), wrapper, SLOT( emitValueChanged() ) );
@@ -95,27 +95,34 @@ void QgsRangeWidgetWrapper::initWidget( QWidget *editor )
9595
mDoubleSpinBox->setDecimals( layer()->fields().at( fieldIdx() ).precision() );
9696
}
9797

98-
double minval = min.toDouble();
99-
double stepval = step.toDouble();
10098
QgsDoubleSpinBox *qgsWidget = dynamic_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );
99+
100+
double stepval = step.isValid() ? step.toDouble() : 1.0;
101+
double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
102+
double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
103+
101104
if ( qgsWidget )
102105
qgsWidget->setShowClearButton( allowNull );
106+
// Make room for null value: use the minimum
103107
if ( allowNull )
104108
{
109+
double decr;
105110
if ( precision > 0 )
106111
{
107-
minval -= 10 ^ -precision;
112+
decr = 10 ^ -precision;
108113
}
109114
else
110115
{
111-
minval -= stepval;
116+
decr = stepval;
112117
}
118+
minval = std::min( std::numeric_limits<double>::lowest() + decr, minval );
119+
minval -= decr;
113120
mDoubleSpinBox->setValue( minval );
114121
mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
115122
}
116-
mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits<double>::min() );
117-
mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits<double>::max() );
118-
mDoubleSpinBox->setSingleStep( step.isValid() ? step.toDouble() : 1.0 );
123+
mDoubleSpinBox->setMinimum( minval );
124+
mDoubleSpinBox->setMaximum( maxval );
125+
mDoubleSpinBox->setSingleStep( stepval );
119126
if ( config( QStringLiteral( "Suffix" ) ).isValid() )
120127
mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );
121128

src/ui/editorwidgets/qgsrangeconfigdlgbase.ui

+6-32
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<item row="2" column="0">
7777
<widget class="QStackedWidget" name="rangeStackedWidget">
7878
<property name="currentIndex">
79-
<number>0</number>
79+
<number>1</number>
8080
</property>
8181
<widget class="QWidget" name="intPage">
8282
<layout class="QFormLayout" name="formLayout">
@@ -91,8 +91,7 @@
9191
</widget>
9292
</item>
9393
<item row="0" column="1">
94-
<widget class="QSpinBox" name="minimumSpinBox">
95-
</widget>
94+
<widget class="QSpinBox" name="minimumSpinBox"/>
9695
</item>
9796
<item row="1" column="0">
9897
<widget class="QLabel" name="maximumLabel">
@@ -102,8 +101,7 @@
102101
</widget>
103102
</item>
104103
<item row="1" column="1">
105-
<widget class="QSpinBox" name="maximumSpinBox">
106-
</widget>
104+
<widget class="QSpinBox" name="maximumSpinBox"/>
107105
</item>
108106
<item row="2" column="0">
109107
<widget class="QLabel" name="stepLabel">
@@ -113,8 +111,7 @@
113111
</widget>
114112
</item>
115113
<item row="2" column="1">
116-
<widget class="QSpinBox" name="stepSpinBox">
117-
</widget>
114+
<widget class="QSpinBox" name="stepSpinBox"/>
118115
</item>
119116
</layout>
120117
</widget>
@@ -145,36 +142,13 @@
145142
</widget>
146143
</item>
147144
<item row="0" column="1">
148-
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox">
149-
<property name="minimum">
150-
<double>-1.79769e+308</double>
151-
</property>
152-
<property name="maximum">
153-
<double>1.79769e+308</double>
154-
</property>
155-
<property name="value">
156-
<double>-1.79769e+308</double>
157-
</property>
158-
</widget>
145+
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox"/>
159146
</item>
160147
<item row="1" column="1">
161-
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox">
162-
<property name="minimum">
163-
<double>-1.79769e+308</double>
164-
</property>
165-
<property name="maximum">
166-
<double>1.79769e+308</double>
167-
</property>
168-
<property name="value">
169-
<double>1.79769e+308</double>
170-
</property>
171-
</widget>
148+
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox"/>
172149
</item>
173150
<item row="2" column="1">
174151
<widget class="QDoubleSpinBox" name="stepDoubleSpinBox">
175-
<property name="maximum">
176-
<double>1.79769e+308</double>
177-
</property>
178152
<property name="value">
179153
<double>1.000000000000000</double>
180154
</property>

0 commit comments

Comments
 (0)