Skip to content
Permalink
Browse files

Merge pull request #6506 from m-kuhn/fixRange

Fix Integer range widget with allowNull
  • Loading branch information
m-kuhn committed Mar 2, 2018
2 parents b84f014 + b37c410 commit 0d208298b700ca6c0b6a031089caf38e62001a88
@@ -98,7 +98,7 @@ void QgsRangeWidgetWrapper::initWidget( QWidget *editor )

mDoubleSpinBox->setDecimals( precisionval );

QgsDoubleSpinBox *qgsWidget = dynamic_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );
QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );


if ( qgsWidget )
@@ -128,22 +128,22 @@ void QgsRangeWidgetWrapper::initWidget( QWidget *editor )
mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );

connect( mDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ),
this, [ = ]( double value ) { emit valueChanged( value ); } );
this, [ = ]( double ) { emitValueChanged(); } );
}
else if ( mIntSpinBox )
{
QgsSpinBox *qgsWidget = dynamic_cast<QgsSpinBox *>( mIntSpinBox );
QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox );
if ( qgsWidget )
qgsWidget->setShowClearButton( allowNull );
int minval = min.toInt();
if ( allowNull )
{
int minval = min.toInt();
int stepval = step.toInt();
minval -= stepval;
mIntSpinBox->setValue( minval );
mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
}
setupIntEditor( min, max, step, mIntSpinBox, this );
setupIntEditor( minval, max, step, mIntSpinBox, this );
if ( config( QStringLiteral( "Suffix" ) ).isValid() )
mIntSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );
}
@@ -466,7 +466,7 @@ def testTransactionConstrains(self):

# check new values
self.assertTrue(vl.getFeatures('id=1').nextFeature(f))
self.assertEqual(f.attributes(), [1, 1, 0])
self.assertEqual(f.attributes(), [1, 1, NULL])

def testTransactionTuple(self):
# create a vector layer based on postgres
@@ -45,6 +45,7 @@ def __createRangeWidget(self, allownull=False):
reg = QgsGui.editorWidgetRegistry()
configWdg = reg.createConfigWidget('Range', self.layer, 1, None)
config = configWdg.config()
config["Min"] = 0

# if null shall be allowed
if allownull:
@@ -84,10 +85,13 @@ def test_range_widget_null_allowed(self):
rangewidget = self.__createRangeWidget(True)

rangewidget.setValue(NULL)
assert rangewidget.value() == NULL
self.assertEqual(rangewidget.value(), NULL)

rangewidget.setValue(None)
assert rangewidget.value() == NULL
self.assertEqual(rangewidget.value(), NULL)

rangewidget.setValue(0)
self.assertEqual(rangewidget.value(), 0)


if __name__ == '__main__':

0 comments on commit 0d20829

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