Skip to content
Permalink
Browse files

Fix text edit widget wrapper incorrectly shows "NULL" string for

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".

(cherry picked from commit fa91357)
  • Loading branch information
nyalldawson committed Feb 19, 2021
1 parent 97495c0 commit 7521861de25dcb26cb3e339acd2f344180b4960b
Showing with 18 additions and 2 deletions.
  1. +2 −2 src/gui/editorwidgets/qgstexteditwrapper.cpp
  2. +16 −0 tests/src/python/test_qgseditwidgets.py
@@ -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 )
@@ -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 );
@@ -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):

0 comments on commit 7521861

Please sign in to comment.