Fix checkbox search widget wrapper for boolean field types

Fixes #60152
This commit is contained in:
Nyall Dawson 2025-02-12 11:09:37 +10:00
parent af393490eb
commit 57d5bb0f67
No known key found for this signature in database
GPG Key ID: 4C61673F0BF197FC
2 changed files with 15 additions and 1 deletions

View File

@ -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;
}

View File

@ -518,6 +518,9 @@ class PyQgsCheckboxSearchWidgetWrapper(QgisTestCase):
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(