Skip to content
Permalink
Browse files
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.
  • Loading branch information
pvalsecc authored and Patrick Valsecchi committed Sep 7, 2016
1 parent 45373d0 commit 8d9cf9d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 79 deletions.
@@ -100,12 +100,12 @@ QgsEditorWidgetConfig QgsRangeConfigDlg::config()

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

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

rangeWidget->setCurrentIndex( rangeWidget->findData( config.value( "Style", "SpinBox" ) ) );
@@ -73,7 +73,10 @@ void QgsRangeWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config, QD

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

QMap<const char*, int> QgsRangeWidgetFactory::supportedWidgetTypes()
@@ -65,10 +65,21 @@ QWidget* QgsRangeWidgetWrapper::createWidget( QWidget* parent )
return editor;
}

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->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( valueChanged( int ) ) );
}

void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
{
mDoubleSpinBox = qobject_cast<QDoubleSpinBox*>( editor );
mIntSpinBox = qobject_cast<QSpinBox*>( editor );

mDial = qobject_cast<QDial*>( editor );
mSlider = qobject_cast<QSlider*>( editor );
mQgsDial = qobject_cast<QgsDial*>( editor );
@@ -107,90 +118,40 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
mDoubleSpinBox->setValue( minval );
mDoubleSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}
if ( min.isValid() )
mDoubleSpinBox->setMinimum( min.toDouble() );
if ( max.isValid() )
mDoubleSpinBox->setMaximum( max.toDouble() );
if ( step.isValid() )
mDoubleSpinBox->setSingleStep( step.toDouble() );
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 );
if ( config( "Suffix" ).isValid() )
mDoubleSpinBox->setSuffix( config( "Suffix" ).toString() );

connect( mDoubleSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( valueChanged( double ) ) );
}

if ( mIntSpinBox )
else if ( mIntSpinBox )
{
int minval = min.toInt();
int stepval = step.toInt();
QgsSpinBox* qgsWidget = dynamic_cast<QgsSpinBox*>( mIntSpinBox );
if ( qgsWidget )
qgsWidget->setShowClearButton( allowNull );
if ( allowNull )
{
int minval = min.toInt();
int stepval = step.toInt();
minval -= stepval;
mIntSpinBox->setValue( minval );
mIntSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}
if ( min.isValid() )
mIntSpinBox->setMinimum( min.toInt() );
if ( max.isValid() )
mIntSpinBox->setMaximum( max.toInt() );
if ( step.isValid() )
mIntSpinBox->setSingleStep( step.toInt() );
setupIntEditor( min, max, step, mIntSpinBox, this );
if ( config( "Suffix" ).isValid() )
mIntSpinBox->setSuffix( config( "Suffix" ).toString() );
connect( mIntSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
}


if ( mQgsDial || mQgsSlider )
else
{
field().convertCompatible( min );
field().convertCompatible( max );
field().convertCompatible( step );

if ( mQgsSlider )
{
if ( min.isValid() )
mQgsSlider->setMinimum( min );
if ( max.isValid() )
mQgsSlider->setMaximum( max );
if ( step.isValid() )
mQgsSlider->setSingleStep( step );
}

if ( mQgsDial )
{
if ( min.isValid() )
mQgsDial->setMinimum( min );
if ( max.isValid() )
mQgsDial->setMaximum( max );
if ( step.isValid() )
mQgsDial->setSingleStep( step );
}

connect( editor, SIGNAL( valueChanged( QVariant ) ), this, SLOT( valueChangedVariant( QVariant ) ) );
}
else if ( mDial )
{
if ( min.isValid() )
mDial->setMinimum( min.toInt() );
if ( max.isValid() )
mDial->setMaximum( max.toInt() );
if ( step.isValid() )
mDial->setSingleStep( step.toInt() );
connect( mDial, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
}
else if ( mSlider )
{
if ( min.isValid() )
mSlider->setMinimum( min.toInt() );
if ( max.isValid() )
mSlider->setMaximum( max.toInt() );
if ( step.isValid() )
mSlider->setSingleStep( step.toInt() );
connect( mSlider, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
if ( mQgsDial ) setupIntEditor( min, max, step, mQgsDial, this );
else if ( mQgsSlider ) setupIntEditor( min, max, step, mQgsSlider, this );
else if ( mDial ) setupIntEditor( min, max, step, mDial, this );
else if ( mSlider ) setupIntEditor( min, max, step, mSlider, this );
}
}

@@ -21,6 +21,7 @@
#include <QSpinBox>
#include <QDoubleSpinBox>

class QAbstractSlider;
class QSlider;
class QDial;
class QgsSlider;
@@ -93,10 +93,13 @@
<item row="0" column="1">
<widget class="QSpinBox" name="minimumSpinBox">
<property name="minimum">
<number>-999999999</number>
<number>−2147483648</number>
</property>
<property name="maximum">
<number>999999999</number>
<number>2147483647</number>
</property>
<property name="value">
<number>−2147483648</number>
</property>
</widget>
</item>
@@ -110,13 +113,13 @@
<item row="1" column="1">
<widget class="QSpinBox" name="maximumSpinBox">
<property name="minimum">
<number>-999999999</number>
<number>−2147483648</number>
</property>
<property name="maximum">
<number>999999999</number>
<number>2147483647</number>
</property>
<property name="value">
<number>5</number>
<number>2147483647</number>
</property>
</widget>
</item>
@@ -130,7 +133,7 @@
<item row="2" column="1">
<widget class="QSpinBox" name="stepSpinBox">
<property name="maximum">
<number>999999999</number>
<number>2147483647</number>
</property>
<property name="value">
<number>1</number>
@@ -168,30 +171,33 @@
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="minimumDoubleSpinBox">
<property name="minimum">
<double>-999999999.990000009536743</double>
<double>-1.79769e+308</double>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
<double>1.79769e+308</double>
</property>
<property name="value">
<double>-1.79769e+308</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="maximumDoubleSpinBox">
<property name="minimum">
<double>-999999999.990000009536743</double>
<double>-1.79769e+308</double>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
<double>1.79769e+308</double>
</property>
<property name="value">
<double>5.000000000000000</double>
<double>1.79769e+308</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="stepDoubleSpinBox">
<property name="maximum">
<double>999999999.990000009536743</double>
<double>1.79769e+308</double>
</property>
<property name="value">
<double>1.000000000000000</double>
@@ -68,6 +68,11 @@ class TestQgsEditorWidgetRegistry: public QObject
checkSimple( "integer", "Range" );
}

void longLongType()
{
checkSimple( "int8", "TextEdit" ); // no current widget supports 64 bit integers => default to TextEdit
}

void doubleType()
{
checkSimple( "double", "Range" );

0 comments on commit 8d9cf9d

Please sign in to comment.