on xenial help sign in
Don't ignore empty attributes in CardAttributes.qml and improve its encapsulation Fixes: 1355901
7d89788Michał Sawicz
plugins/Dash/CardAttributes.qml+6−3
@@ -26,8 +26,10 @@ GridLayout {
26 right: parent.right;
26 right: parent.right;
27 }
27 }
28 columns: 2 + repeater.count % 2
28 columns: 2 + repeater.count % 2
29+ rowSpacing: units.gu(.5)
29 property alias model: repeater.model
30 property alias model: repeater.model
30− property var color
31+ property color color: Theme.palette.normal.baseText
32+ property real fontScale: 1.0
31
33
32 Repeater {
34 Repeater {
33 id: repeater
35 id: repeater
@@ -42,18 +44,19 @@ GridLayout {
42 Layout.columnSpan: index == repeater.count - 1 && grid.columns == 3 && column == 1 ? 2 : 1
44 Layout.columnSpan: index == repeater.count - 1 && grid.columns == 3 && column == 1 ? 2 : 1
43 Layout.maximumWidth: Math.max(icon.width, label.x + label.implicitWidth)
45 Layout.maximumWidth: Math.max(icon.width, label.x + label.implicitWidth)
44 Layout.fillWidth: true
46 Layout.fillWidth: true
47+ height: units.gu(2)
45 StatusIcon {
48 StatusIcon {
46 id: icon
49 id: icon
47 height: units.gu(2)
50 height: units.gu(2)
48 sets: ["actions", "status", "apps"]
51 sets: ["actions", "status", "apps"]
49− source: "icon" in modelData ? modelData["icon"] : ""
52+ source: "icon" in modelData && modelData["icon"] || ""
50 color: grid.color
53 color: grid.color
51 }
54 }
52 Label {
55 Label {
53 id: label
56 id: label
54 width: parent.width - x
57 width: parent.width - x
55 anchors.verticalCenter: parent.verticalCenter
58 anchors.verticalCenter: parent.verticalCenter
56− text: "value" in modelData ? modelData["value"] : "";
59+ text: "value" in modelData && modelData["value"] || "";
57 elide: Text.ElideRight
60 elide: Text.ElideRight
58 maximumLineCount: 1
61 maximumLineCount: 1
59 font.weight: "style" in modelData && modelData["style"] == "highlighted" ? Font.DemiBold : Font.Light
62 font.weight: "style" in modelData && modelData["style"] == "highlighted" ? Font.DemiBold : Font.Light
plugins/Dash/CardCreator.js+1
@@ -274,6 +274,7 @@ var kAttributesRowCode = 'CardAttributes { \n\
274 objectName: "attributesRow"; \n\
274 objectName: "attributesRow"; \n\
275 anchors { %1 } \n\
275 anchors { %1 } \n\
276 color: %2; \n\
276 color: %2; \n\
277+ fontScale: root.fontScale; \n\
277 model: cardData && cardData["attributes"]; \n\
278 model: cardData && cardData["attributes"]; \n\
278 }\n';
279 }\n';
279
280
tests/plugins/Dash/cardcreator/7.res+1
@@ -128,6 +128,7 @@ Image {
128 top: subtitleLabel.bottom;
128 top: subtitleLabel.bottom;
129 }
129 }
130 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
130 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
131+ fontScale: root.fontScale;
131 model: cardData && cardData["attributes"];
132 model: cardData && cardData["attributes"];
132 }
133 }
133
134
tests/plugins/Dash/tst_CardAttributes.qml+4−1
@@ -26,7 +26,8 @@ Item {
26 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}],
26 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}],
27 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3"}],
27 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3"}],
28 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3"},{"value":"text4"}],
28 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3"},{"value":"text4"}],
29− [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3","style":"highlighted"},{"value":"text4","icon":"image://theme/close","style":"highlighted"},{"value":"text5"}]
29+ [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3","style":"highlighted"},{"value":"text4","icon":"image://theme/close","style":"highlighted"},{"value":"text5"}],
30+ [{"value":"text1","icon":"image://theme/ok"},{},{},{},{"value":"text5", "icon": "image://theme/search"}],
30 ]
31 ]
31
32
32 CardAttributes {
33 CardAttributes {
@@ -49,6 +50,8 @@ Item {
49 function test_columns(data) {
50 function test_columns(data) {
50 cardAttributes.model = data;
51 cardAttributes.model = data;
51 compare(cardAttributes.columns, 2 + data.length % 2);
52 compare(cardAttributes.columns, 2 + data.length % 2);
53+ var rows = Math.ceil(data.length / 3);
54+ tryCompare(cardAttributes, "height", rows * units.gu(2) + (rows - 1) * cardAttributes.rowSpacing);
52 }
55 }
53 }
56 }
54}
57}