Skip to content
Permalink
Browse files

[bugfix] Fix minimum values for range widgets

Fixes #17878 QGIS 3 Vector Layer Fields Garbled when Clicking the Toggle Editing Icon
  • Loading branch information
elpaso committed Jan 27, 2018
1 parent fd53880 commit ab607ce36a19e10208b41f41c0c545cd124d55e2
@@ -22,17 +22,30 @@ QgsRangeConfigDlg::QgsRangeConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget
{
setupUi( this );

minimumSpinBox->setMinimum( std::numeric_limits<int>::min() );
minimumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
minimumSpinBox->setMaximum( std::numeric_limits<int>::max() );
minimumSpinBox->setValue( std::numeric_limits<int>::min() );
minimumSpinBox->setValue( std::numeric_limits<int>::lowest() );

maximumSpinBox->setMinimum( std::numeric_limits<int>::min() );
maximumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
maximumSpinBox->setMaximum( std::numeric_limits<int>::max() );
maximumSpinBox->setValue( std::numeric_limits<int>::max() );

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

minimumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
minimumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
minimumDoubleSpinBox->setValue( std::numeric_limits<double>::min() );

maximumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
maximumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
maximumDoubleSpinBox->setValue( std::numeric_limits<double>::max() );

// Use integer here:
stepDoubleSpinBox->setMaximum( std::numeric_limits<int>::max() );
stepDoubleSpinBox->setValue( 1 );


QString text;

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

rangeWidget->clear();
rangeWidget->addItem( tr( "Editable" ), "SpinBox" );
rangeWidget->addItem( tr( "Slider" ), "Slider" );
rangeWidget->addItem( tr( "Dial" ), "Dial" );
rangeWidget->addItem( tr( "Editable" ), QStringLiteral( "SpinBox" ) );
rangeWidget->addItem( tr( "Slider" ), QStringLiteral( "Slider" ) );
rangeWidget->addItem( tr( "Dial" ), QStringLiteral( "Dial" ) );

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

void QgsRangeConfigDlg::setConfig( const QVariantMap &config )
{
minimumDoubleSpinBox->setValue( config.value( QStringLiteral( "Min" ), -std::numeric_limits<double>::max() ).toDouble() );
maximumDoubleSpinBox->setValue( config.value( QStringLiteral( "Max" ), std::numeric_limits<double>::max() ).toDouble() );
minimumDoubleSpinBox->setValue( config.value( QStringLiteral( "Min" ), std::numeric_limits<double>::lowest() ).toDouble( ) );
maximumDoubleSpinBox->setValue( config.value( QStringLiteral( "Max" ), std::numeric_limits<double>::max() ).toDouble( ) );
stepDoubleSpinBox->setValue( config.value( QStringLiteral( "Step" ), 1.0 ).toDouble() );

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

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

double minval = min.toDouble();
double stepval = step.toDouble();
QgsDoubleSpinBox *qgsWidget = dynamic_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );

double stepval = step.isValid() ? step.toDouble() : 1.0;
double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();

if ( qgsWidget )
qgsWidget->setShowClearButton( allowNull );
// Make room for null value: use the minimum
if ( allowNull )
{
double decr;
if ( precision > 0 )
{
minval -= 10 ^ -precision;
decr = 10 ^ -precision;
}
else
{
minval -= stepval;
decr = stepval;
}
minval = std::min( std::numeric_limits<double>::lowest() + decr, minval );
minval -= decr;
mDoubleSpinBox->setValue( minval );
mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
}
mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits<double>::min() );
mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits<double>::max() );
mDoubleSpinBox->setSingleStep( step.isValid() ? step.toDouble() : 1.0 );
mDoubleSpinBox->setMinimum( minval );
mDoubleSpinBox->setMaximum( maxval );
mDoubleSpinBox->setSingleStep( stepval );
if ( config( QStringLiteral( "Suffix" ) ).isValid() )
mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );

@@ -76,7 +76,7 @@
<item row="2" column="0">
<widget class="QStackedWidget" name="rangeStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="intPage">
<layout class="QFormLayout" name="formLayout">
@@ -91,8 +91,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="minimumSpinBox">
</widget>
<widget class="QSpinBox" name="minimumSpinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="maximumLabel">
@@ -102,8 +101,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="maximumSpinBox">
</widget>
<widget class="QSpinBox" name="maximumSpinBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="stepLabel">
@@ -113,8 +111,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="stepSpinBox">
</widget>
<widget class="QSpinBox" name="stepSpinBox"/>
</item>
</layout>
</widget>
@@ -145,36 +142,13 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox">
<property name="minimum">
<double>-1.79769e+308</double>
</property>
<property name="maximum">
<double>1.79769e+308</double>
</property>
<property name="value">
<double>-1.79769e+308</double>
</property>
</widget>
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox"/>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox">
<property name="minimum">
<double>-1.79769e+308</double>
</property>
<property name="maximum">
<double>1.79769e+308</double>
</property>
<property name="value">
<double>1.79769e+308</double>
</property>
</widget>
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox"/>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="stepDoubleSpinBox">
<property name="maximum">
<double>1.79769e+308</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>

0 comments on commit ab607ce

Please sign in to comment.
You can’t perform that action at this time.