Skip to content
Permalink
Browse files
Handle variable precision in range dlg
  • Loading branch information
elpaso committed Oct 22, 2021
1 parent 6a22e1f commit d98c99e462144c98d8768160db7697c3d9422999
Showing with 53 additions and 3 deletions.
  1. +1 −0 python/gui/auto_generated/qgsludialog.sip.in
  2. +29 −2 src/gui/qgsludialog.cpp
  3. +4 −0 src/gui/qgsludialog.h
  4. +19 −1 src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
@@ -35,6 +35,7 @@ Returns the upper value.
.. versionadded:: 3.21
%End
void setUpperValue( const QString &val );

};

/************************************************************************
@@ -22,6 +22,9 @@ QgsLUDialog::QgsLUDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
setupUi( this );

connect( mLowerEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mLowerEdit, value ); } );
connect( mUpperEdit, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [ this ]( double value ) { setDecimalPlaces( mUpperEdit, value ); } );
}

QString QgsLUDialog::lowerValue() const
@@ -46,10 +49,34 @@ double QgsLUDialog::upperValueDouble() const

void QgsLUDialog::setLowerValue( const QString &val )
{
mLowerEdit->setValue( QLocale().toDouble( val ) );
bool ok;
const double value { QLocale().toDouble( val, &ok )};
mLowerEdit->setValue( value );
if ( ok )
{
setDecimalPlaces( mLowerEdit, value );
}
}

void QgsLUDialog::setUpperValue( const QString &val )
{
mUpperEdit->setValue( QLocale().toDouble( val ) );
bool ok;
const double value { QLocale().toDouble( val, &ok )};
mUpperEdit->setValue( value );
if ( ok )
{
setDecimalPlaces( mUpperEdit, value );
}
}

void QgsLUDialog::setDecimalPlaces( QgsDoubleSpinBox *widget, double value ) const
{
const QString strVal { QVariant( value ).toString() };
const int dotPosition( strVal.indexOf( '.' ) );
int decimals {2};
if ( dotPosition >= 0 )
{
decimals = std::max<int>( 2, strVal.length() - dotPosition - 1 );
widget->setDecimals( decimals );
}
}
@@ -48,6 +48,10 @@ class GUI_EXPORT QgsLUDialog: public QDialog, private Ui::QgsLUDialogBase
*/
double upperValueDouble() const;
void setUpperValue( const QString &val );

private:

void setDecimalPlaces( QgsDoubleSpinBox *widget, double value ) const;
};

#endif
@@ -508,7 +508,20 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
case QVariant::Type::Double:
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 12 );
bool ok;
const QVariant value = index.data( QgsCategorizedSymbolRendererWidget::CustomRoles::ValueRole );
int decimals {2};
if ( value.toDouble( &ok ); ok )
{
const QString strVal { value.toString() };
const int dotPosition( strVal.indexOf( '.' ) );
if ( dotPosition >= 0 )
{
decimals = std::max<int>( 2, strVal.length() - dotPosition - 1 );
}
}
editor->setDecimals( decimals );
editor->setClearValue( 0 );
editor->setMaximum( std::numeric_limits<double>::max() );
editor->setMinimum( std::numeric_limits<double>::lowest() );
break;
@@ -517,6 +530,7 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 0 );
editor->setClearValue( 0 );
editor->setMaximum( std::numeric_limits<int>::max() );
editor->setMinimum( std::numeric_limits<int>::min() );
break;
@@ -525,6 +539,7 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 0 );
editor->setClearValue( 0 );
editor->setMaximum( std::numeric_limits<char>::max() );
editor->setMinimum( std::numeric_limits<char>::min() );
break;
@@ -533,6 +548,7 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 0 );
editor->setClearValue( 0 );
editor->setMaximum( std::numeric_limits<unsigned int>::max() );
editor->setMinimum( 0 );
break;
@@ -541,6 +557,7 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 0 );
editor->setClearValue( 0 );
editor->setMaximum( static_cast<double>( std::numeric_limits<qlonglong>::max() ) );
editor->setMinimum( std::numeric_limits<qlonglong>::min() );
break;
@@ -549,6 +566,7 @@ QWidget *QgsCategorizedRendererViewItemDelegate::createEditor( QWidget *parent,
{
editor = new QgsDoubleSpinBox( parent );
editor->setDecimals( 0 );
editor->setClearValue( 0 );
editor->setMaximum( static_cast<double>( std::numeric_limits<unsigned long long>::max() ) );
editor->setMinimum( 0 );
break;

0 comments on commit d98c99e

Please sign in to comment.