on xenial help sign in
Don't ignore empty attributes in CardAttributes.qml and improve its encapsulation Fixes: 1355901

Approved by: Andrea Cimitan, PS Jenkins bot

commit7d897880f9f91cd0b32c9f8b1538c18855869ceb authorMichał Sawicz <michal.sawicz@canonical.com> dateWed 27 Aug 2014, 15:33 (12 years ago) parent264a0237a796ef
4 files changed+12−4
plugins/Dash/CardAttributes.qml+6−3 plugins/Dash/CardCreator.js+1 tests/plugins/Dash/cardcreator/7.res+1 tests/plugins/Dash/tst_CardAttributes.qml+4−1
plugins/Dash/CardAttributes.qml+6−3
@@ -26,8 +26,10 @@ GridLayout {
2626 right: parent.right;
2727 }
2828 columns: 2 + repeater.count % 2
29+ rowSpacing: units.gu(.5)
2930 property alias model: repeater.model
30− property var color
31+ property color color: Theme.palette.normal.baseText
32+ property real fontScale: 1.0
3133
3234 Repeater {
3335 id: repeater
@@ -42,18 +44,19 @@ GridLayout {
4244 Layout.columnSpan: index == repeater.count - 1 && grid.columns == 3 && column == 1 ? 2 : 1
4345 Layout.maximumWidth: Math.max(icon.width, label.x + label.implicitWidth)
4446 Layout.fillWidth: true
47+ height: units.gu(2)
4548 StatusIcon {
4649 id: icon
4750 height: units.gu(2)
4851 sets: ["actions", "status", "apps"]
49− source: "icon" in modelData ? modelData["icon"] : ""
52+ source: "icon" in modelData && modelData["icon"] || ""
5053 color: grid.color
5154 }
5255 Label {
5356 id: label
5457 width: parent.width - x
5558 anchors.verticalCenter: parent.verticalCenter
56− text: "value" in modelData ? modelData["value"] : "";
59+ text: "value" in modelData && modelData["value"] || "";
5760 elide: Text.ElideRight
5861 maximumLineCount: 1
5962 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\
274274 objectName: "attributesRow"; \n\
275275 anchors { %1 } \n\
276276 color: %2; \n\
277+ fontScale: root.fontScale; \n\
277278 model: cardData && cardData["attributes"]; \n\
278279 }\n';
279280
tests/plugins/Dash/cardcreator/7.res+1
@@ -128,6 +128,7 @@ Image {
128128 top: subtitleLabel.bottom;
129129 }
130130 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;
131132 model: cardData && cardData["attributes"];
132133 }
133134
tests/plugins/Dash/tst_CardAttributes.qml+4−1
@@ -26,7 +26,8 @@ Item {
2626 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}],
2727 [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"},{"value":"text3"}],
2828 [{"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"}],
3031 ]
3132
3233 CardAttributes {
@@ -49,6 +50,8 @@ Item {
4950 function test_columns(data) {
5051 cardAttributes.model = data;
5152 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);
5255 }
5356 }
5457}