Skip to content

Commit

Permalink
Merge pull request #6506 from m-kuhn/fixRange
Browse files Browse the repository at this point in the history
Fix Integer range widget with allowNull
  • Loading branch information
m-kuhn committed Mar 2, 2018
2 parents b84f014 + b37c410 commit 0d20829
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/gui/editorwidgets/qgsrangewidgetwrapper.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_postgres.py
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/src/python/test_qgsrangewidgets.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 0d20829

Please sign in to comment.