Skip to content

Commit

Permalink
Fix text edit widget wrapper incorrectly shows "NULL" string for
Browse files Browse the repository at this point in the history
indeterminate state

When editing multiple features with differing values for a text
edit widget field, the widget should show an empty line edit
and not a widget showing "NULL".
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 16, 2021
1 parent 03c3dad commit 5249896
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgstexteditwrapper.cpp
Expand Up @@ -195,7 +195,6 @@ bool QgsTextEditWrapper::valid() const

void QgsTextEditWrapper::showIndeterminateState()
{
//note - this is deliberately a zero length string, not a null string!
if ( mTextEdit )
mTextEdit->blockSignals( true );
if ( mPlainTextEdit )
Expand All @@ -208,7 +207,8 @@ void QgsTextEditWrapper::showIndeterminateState()
mLineEdit->setPlaceholderText( QString() );
}

setWidgetValue( QString() );
//note - this is deliberately a zero length string, not a null string!
setWidgetValue( QStringLiteral( "" ) ); // skip-keyword-check

if ( mTextEdit )
mTextEdit->blockSignals( false );
Expand Down
16 changes: 16 additions & 0 deletions tests/src/python/test_qgseditwidgets.py
Expand Up @@ -93,6 +93,22 @@ def testStringWithMaxLen(self):

QgsProject.instance().removeAllMapLayers()

def test_indeterminate_state(self):
"""
Test the indeterminate state for the wrapper
"""
layer = QgsVectorLayer("none?field=fld:string", "layer", "memory")
reg = QgsGui.editorWidgetRegistry()
configWdg = reg.createConfigWidget('TextEdit', layer, 0, None)
config = configWdg.config()
editwidget = reg.create('TextEdit', layer, 0, config, None, None)

editwidget.setValue('value')
self.assertEqual(editwidget.value(), 'value')
editwidget.showIndeterminateState()
self.assertFalse(editwidget.value())
self.assertFalse(editwidget.widget().toPlainText())


class TestQgsValueRelationWidget(unittest.TestCase):

Expand Down

0 comments on commit 5249896

Please sign in to comment.