Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #33246 from m-kuhn/nan_null
Support for NaN in text edit widget
  • Loading branch information
m-kuhn committed Dec 7, 2019
2 parents 759f1ef + 93ecb00 commit 4d6758d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgstexteditwrapper.cpp
Expand Up @@ -228,10 +228,10 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
if ( !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
v = QgsApplication::nullRepresentation();
}
else if ( val.type() == QVariant::Double && std::isnan( val.toDouble() ) )
v = QgsApplication::nullRepresentation();
else
{
v = field().displayString( val );
}

// For numbers, remove the group separator that might cause validation errors
// when the user is editing the field value.
Expand Down
7 changes: 5 additions & 2 deletions tests/src/python/test_qgseditwidgets.py
Expand Up @@ -57,11 +57,14 @@ def doAttributeTest(self, idx, expected):
editwidget.setValue(NULL)
self.assertEqual(editwidget.value(), expected[3])

editwidget.setValue(float('nan'))
self.assertEqual(editwidget.value(), expected[4])

def test_SetValue(self):
self.createLayerWithOnePoint()

self.doAttributeTest(0, ['value', '123', NULL, NULL])
self.doAttributeTest(1, [NULL, 123, NULL, NULL])
self.doAttributeTest(0, ['value', '123', NULL, NULL, NULL])
self.doAttributeTest(1, [NULL, 123, NULL, NULL, NULL])

def testStringWithMaxLen(self):
""" tests that text edit wrappers correctly handle string fields with a maximum length """
Expand Down

0 comments on commit 4d6758d

Please sign in to comment.