Skip to content

Commit

Permalink
Fix checkbox search widget wrapper for boolean field types
Browse files Browse the repository at this point in the history
Fixes #60152
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 12, 2025
1 parent ea0e8f9 commit bd53243
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/gui/editorwidgets/qgscheckboxsearchwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ QVariant QgsCheckboxSearchWidgetWrapper::value() const
{
QVariant v;

const QMetaType::Type fieldType = layer()->fields().at( mFieldIdx ).type();

if ( mCheckBox )
v = mCheckBox->isChecked() ? config( QStringLiteral( "CheckedState" ), true ) : config( QStringLiteral( "UncheckedState" ), false );
{
if ( fieldType == QMetaType::Type::Bool )
{
v = mCheckBox->isChecked();
}
else
{
v = mCheckBox->isChecked() ? config( QStringLiteral( "CheckedState" ), true ) : config( QStringLiteral( "UncheckedState" ), false );
}
}

return v;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgssearchwidgetwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ def testCreateExpression(self):
parent = QWidget()
w = QgsCheckboxSearchWidgetWrapper(layer, 2)
w.initWidget(parent)
# boolean fields should ignore CheckedState/UncheckedState config
config = {"CheckedState": 5, "UncheckedState": 9}
w.setConfig(config)
c = w.widget()
c.setChecked(True)
self.assertEqual(
Expand Down

0 comments on commit bd53243

Please sign in to comment.