summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2020-08-06 11:27:27 +0200
committerMarco Bubke <marco.bubke@qt.io>2020-08-10 09:40:34 +0000
commitb5d59c75a7dee830483631cd9045d5338fc25c2d (patch)
tree9a2ddf40d5ec852ca7eb57396f58d702efef5f81
parentb4027b7943e52374141ec6b66e9ec0ceadfe81e9 (diff)
downloadqt-creator-b5d59c75a7dee830483631cd9045d5338fc25c2d.tar.gz
QmlDesigner: Fix bool handling in the list model editor
Task-number: QDS-2581 Change-Id: I47a9ed4ca55532bb7199a6c5dd4894b7adb7d05d Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp11
-rw-r--r--tests/unit/unittest/listmodeleditor-test.cpp66
2 files changed, 77 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
index 48b1ad6fc9..b73a53f76c 100644
--- a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
+++ b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
@@ -51,6 +51,17 @@ public:
QVariant maybeConvertToNumber(const QVariant &value)
{
+ if (value.type() == QVariant::Bool)
+ return value;
+
+ if (value.type() == QVariant::String) {
+ const QString text = value.toString();
+ if (text == "true")
+ return QVariant(true);
+ if (text == "false")
+ return QVariant(false);
+ }
+
bool canConvert = false;
double convertedValue = value.toDouble(&canConvert);
if (canConvert) {
diff --git a/tests/unit/unittest/listmodeleditor-test.cpp b/tests/unit/unittest/listmodeleditor-test.cpp
index 0a5a91327a..bdd5e9c070 100644
--- a/tests/unit/unittest/listmodeleditor-test.cpp
+++ b/tests/unit/unittest/listmodeleditor-test.cpp
@@ -1310,4 +1310,70 @@ TEST_F(ListModelEditor, ListViewHasModelBinding)
ElementsAre("pic.png", "poo", 111, IsInvalid())));
}
+TEST_F(ListModelEditor, AddBooleanDisplayValues)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, true);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), true, 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, AddBooleanProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, true);
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", "foo"),
+ IsVariantProperty("value", true),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
+TEST_F(ListModelEditor, AddTrueAsStringProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, "true");
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", true),
+ IsVariantProperty("value", 1),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
+TEST_F(ListModelEditor, AddFalseAsStringProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, "false");
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", false),
+ IsVariantProperty("value", 1),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
} // namespace