on xenial help sign in
Do not use template in generated card creator code

We can resolve it while doing the code generation Approved by: Andrea Cimitan

commit3af8283d6baebd565d6b0b9980996a038b77395a authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 16 Jun 2015, 15:12 (11 years ago) parent43fb6152543e08
18 files changed+75−72
plugins/Dash/CardCreator.js+22−10 qml/Dash/CardCarousel.qml−1 qml/Dash/CardGrid.qml−1 qml/Dash/CardHorizontalList.qml−1 qml/Dash/CardTool.qml+16−15 qml/Dash/CardVerticalJournal.qml−1 tests/plugins/Dash/cardcreator/1.res+1−2 tests/plugins/Dash/cardcreator/2.res+3−8 tests/plugins/Dash/cardcreator/3.res+1−2 tests/plugins/Dash/cardcreator/4.res+1−2 tests/plugins/Dash/cardcreator/5.res+1−2 tests/plugins/Dash/cardcreator/5.tst+1−1 tests/plugins/Dash/cardcreator/6.res+3−8 tests/plugins/Dash/cardcreator/6.tst+1−1 tests/plugins/Dash/cardcreator/7.res+3−8 tests/plugins/Dash/cardcreator/7.tst+1−1 tests/qmltests/Dash/tst_Card.qml−1 tests/qmltests/Dash/tst_GenericScopeView.qml+21−7
plugins/Dash/CardCreator.js+22−10
@@ -16,6 +16,9 @@
1616
1717.pragma library
1818
19+// %1 is the template["card-background"] string
20+// %2 is the template["card-background"]["elements"][0]
21+// %3 is the template["card-background"]["elements"][1]
1922var kBackgroundLoaderCode = 'Loader {\n\
2023 id: backgroundLoader; \n\
2124 objectName: "backgroundLoader"; \n\
@@ -34,18 +37,14 @@ var kBackgroundLoaderCode = 'Loader {\n\
3437 objectName: "backgroundImage"; \n\
3538 source: { \n\
3639 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
37− else if (template && typeof template["card-background"] === "string") return template["card-background"]; \n\
38− else return ""; \n\
40+ else return "%1"; \n\
3941 } \n\
4042 } \n\
4143 function getColor(index) { \n\
4244 if (cardData && typeof cardData["background"] === "object" \n\
4345 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
4446 return cardData["background"]["elements"][index]; \n\
45− } else if (template && typeof template["card-background"] === "object" \n\
46− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) { \n\
47− return template["card-background"]["elements"][index]; \n\
48− } else return undefined; \n\
47+ } else return index === 0 ? %2 : %3; \n\
4948 } \n\
5049 } \n\
5150 }\n';
@@ -315,9 +314,11 @@ var kSummaryLabelCode = 'Label { \n\
315314
316315function cardString(template, components) {
317316 var code;
317+
318+ var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
319+
318320 code = 'AbstractButton { \n\
319321 id: root; \n\
320− property var template; \n\
321322 property var components; \n\
322323 property var cardData; \n\
323324 property var artShapeBorderSource: undefined; \n\
@@ -330,8 +331,8 @@ function cardString(template, components) {
330331 property bool asynchronous: true; \n\
331332 property bool showHeader: true; \n\
332333 implicitWidth: childrenRect.width; \n\
333− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true); \n\
334− \n';
334+ enabled: %1; \n\
335+ \n'.arg(templateInteractive);
335336
336337 var hasArt = components["art"] && components["art"]["field"] || false;
337338 var hasSummary = components["summary"] || false;
@@ -348,7 +349,18 @@ function cardString(template, components) {
348349 var hasAttributes = hasTitle && components["attributes"]["field"] || false;
349350
350351 if (hasBackground) {
351− code += kBackgroundLoaderCode;
352+ var templateCardBackground = (template && typeof template["card-background"] === "string") ? template["card-background"] : "";
353+ var backgroundElements0;
354+ var backgroundElements1;
355+ if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
356+ if (template["card-background"]["elements"][0] !== undefined) {
357+ backgroundElements0 = '"%1"'.arg(template["card-background"]["elements"][0]);
358+ }
359+ if (template["card-background"]["elements"][1] !== undefined) {
360+ backgroundElements1 = '"%1"'.arg(template["card-background"]["elements"][1]);
361+ }
362+ }
363+ code += kBackgroundLoaderCode.arg(templateCardBackground).arg(backgroundElements0).arg(backgroundElements1);
352364 }
353365
354366 if (hasArt) {
qml/Dash/CardCarousel.qml−1
@@ -61,7 +61,6 @@ DashRenderer {
6161 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
6262 item.height = Qt.binding(function() { return cardTool.cardHeight; });
6363 item.cardData = Qt.binding(function() { return model; });
64− item.template = Qt.binding(function() { return cardTool.template; });
6564 item.components = Qt.binding(function() { return cardTool.components; });
6665 item.fontScale = Qt.binding(function() { return carousel.fontScale; });
6766 item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
qml/Dash/CardGrid.qml−1
@@ -66,7 +66,6 @@ DashRenderer {
6666 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
6767 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
6868 item.cardData = Qt.binding(function() { return model; });
69− item.template = Qt.binding(function() { return cardTool.template; });
7069 item.components = Qt.binding(function() { return cardTool.components; });
7170 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7271 item.scopeStyle = root.scopeStyle;
qml/Dash/CardHorizontalList.qml−1
@@ -53,7 +53,6 @@ DashRenderer {
5353 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
5454 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
5555 item.cardData = Qt.binding(function() { return model; });
56− item.template = Qt.binding(function() { return cardTool.template; });
5756 item.components = Qt.binding(function() { return cardTool.components; });
5857 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
5958 item.scopeStyle = root.scopeStyle;
qml/Dash/CardTool.qml+16−15
@@ -198,8 +198,8 @@ Item {
198198
199199 Loader {
200200 id: cardLoader
201− property var fields: ["art", "mascot", "title", "subtitle", "summary", "attributes"]
202− property var maxData: {
201+ readonly property var fields: ["art", "mascot", "title", "subtitle", "summary", "attributes"]
202+ readonly property var maxData: {
203203 "art": Qt.resolvedUrl("graphics/pixel.png"),
204204 "mascot": Qt.resolvedUrl("graphics/pixel.png"),
205205 "title": "—\n—",
@@ -211,26 +211,27 @@ Item {
211211 onLoaded: {
212212 item.objectName = "cardToolCard";
213213 item.asynchronous = false;
214− item.template = Qt.binding(function() { return cardTool.template; });
215214 item.components = Qt.binding(function() { return cardTool.components; });
216215 item.width = Qt.binding(function() { return cardTool.cardWidth || item.implicitWidth; });
217216 item.height = Qt.binding(function() { return cardTool.cardHeight || item.implicitHeight; });
218217 }
219218 Connections {
220− target: cardLoader.item
221− onComponentsChanged: {
222− var data = {};
223− for (var k in cardLoader.fields) {
224− var component = cardLoader.item.components[cardLoader.fields[k]];
225− var key = cardLoader.fields[k];
226− if ((typeof component === "string" && component.length > 0) ||
227− (typeof component === "object" && component !== null
228− && typeof component["field"] === "string" && component["field"].length > 0)) {
229− data[key] = cardLoader.maxData[key];
230− }
219+ target: cardTool
220+ onTemplateChanged: cardLoader.updateCardData();
221+ onComponentsChanged: cardLoader.updateCardData();
222+ }
223+ function updateCardData() {
224+ var data = {};
225+ for (var k in fields) {
226+ var component = cardTool.components[fields[k]];
227+ var key = fields[k];
228+ if ((typeof component === "string" && component.length > 0) ||
229+ (typeof component === "object" && component !== null
230+ && typeof component["field"] === "string" && component["field"].length > 0)) {
231+ data[key] = maxData[key];
231232 }
232− cardLoader.item.cardData = data;
233233 }
234+ item.cardData = data;
234235 }
235236 }
236237}
qml/Dash/CardVerticalJournal.qml−1
@@ -72,7 +72,6 @@ DashRenderer {
7272 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
7373 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
7474 item.cardData = Qt.binding(function() { return model; });
75− item.template = Qt.binding(function() { return cardTool.template; });
7675 item.components = Qt.binding(function() { return cardTool.components; });
7776 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7877 item.scopeStyle = root.scopeStyle;
tests/plugins/Dash/cardcreator/1.res+1−2
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; }
1918readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
tests/plugins/Dash/cardcreator/2.res+3−8
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817Loader {
1918 id: backgroundLoader;
@@ -33,18 +32,14 @@ Loader {
3332 objectName: "backgroundImage";
3433 source: {
3534 if (cardData && typeof cardData["background"] === "string") return cardData["background"];
36− else if (template && typeof template["card-background"] === "string") return template["card-background"];
37− else return "";
35+ else return "";
3836 }
3937 }
4038 function getColor(index) {
4139 if (cardData && typeof cardData["background"] === "object"
4240 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
4341 return cardData["background"]["elements"][index];
44− } else if (template && typeof template["card-background"] === "object"
45− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
46− return template["card-background"]["elements"][index];
47− } else return undefined;
42+ } else return index === 0 ? "#E9E9E9" : undefined;
4843 }
4944 }
5045 }
tests/plugins/Dash/cardcreator/3.res+1−2
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; }
1918readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
tests/plugins/Dash/cardcreator/4.res+1−2
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817readonly property size artShapeSize: Qt.size(-1, -1);
1918readonly property int headerHeight: row.height;
tests/plugins/Dash/cardcreator/5.res+1−2
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: false;
1716
1817onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; }
1918readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
tests/plugins/Dash/cardcreator/5.tst+1−1
@@ -1,3 +1,3 @@
1−template: {"card-layout":"vertical","card-size":"medium","category-layout":"carousel","collapsed-rows":2,"overlay":true}
1+template: {"non-interactive":true,"card-layout":"vertical","card-size":"medium","category-layout":"carousel","collapsed-rows":2,"overlay":true}
22components: {"art":{"aspect-ratio":1,"field":"art"},"subtitle":{"field":"artist"},"title":{"field":"title"},"attributes":{}}
33result: 5.res
tests/plugins/Dash/cardcreator/6.res+3−8
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817Loader {
1918 id: backgroundLoader;
@@ -33,18 +32,14 @@ Loader {
3332 objectName: "backgroundImage";
3433 source: {
3534 if (cardData && typeof cardData["background"] === "string") return cardData["background"];
36− else if (template && typeof template["card-background"] === "string") return template["card-background"];
37− else return "";
35+ else return "http://assets.ubuntu.com/sites/ubuntu/latest/u/img/logos/logo-ubuntu-grey.png";
3836 }
3937 }
4038 function getColor(index) {
4139 if (cardData && typeof cardData["background"] === "object"
4240 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
4341 return cardData["background"]["elements"][index];
44− } else if (template && typeof template["card-background"] === "object"
45− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
46− return template["card-background"]["elements"][index];
47− } else return undefined;
42+ } else return index === 0 ? undefined : undefined;
4843 }
4944 }
5045 }
tests/plugins/Dash/cardcreator/6.tst+1−1
@@ -1,3 +1,3 @@
1−template: {"card-background":{"elements":["#E9E9E9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
1+template: {"card-background":"http://assets.ubuntu.com/sites/ubuntu/latest/u/img/logos/logo-ubuntu-grey.png","card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
22components: {"art":{"aspect-ratio":1},"background":{"field":"background"},"subtitle":{"field":"author"},"title":{"field":"title"},"emblem":{"field":"source"},"attributes":{}}
33result: 6.res
tests/plugins/Dash/cardcreator/7.res+3−8
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var template;
43 property var components;
54 property var cardData;
65 property var artShapeBorderSource: undefined;
@@ -13,7 +12,7 @@ AbstractButton {
1312 property bool asynchronous: true;
1413 property bool showHeader: true;
1514 implicitWidth: childrenRect.width;
16− enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
15+ enabled: true;
1716
1817Loader {
1918 id: backgroundLoader;
@@ -33,18 +32,14 @@ Loader {
3332 objectName: "backgroundImage";
3433 source: {
3534 if (cardData && typeof cardData["background"] === "string") return cardData["background"];
36− else if (template && typeof template["card-background"] === "string") return template["card-background"];
37− else return "";
35+ else return "";
3836 }
3937 }
4038 function getColor(index) {
4139 if (cardData && typeof cardData["background"] === "object"
4240 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
4341 return cardData["background"]["elements"][index];
44− } else if (template && typeof template["card-background"] === "object"
45− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
46− return template["card-background"]["elements"][index];
47− } else return undefined;
42+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
4843 }
4944 }
5045 }
tests/plugins/Dash/cardcreator/7.tst+1−1
@@ -1,3 +1,3 @@
1−template: {"card-background":{"elements":["#E9E9E9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
1+template: {"card-background":{"elements":["#E9E9E9","#E9AAE9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
22components: {"art":{"aspect-ratio":1},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"},"attributes":{"field":"attributes","max-count":2}}
33result: 7.res
tests/qmltests/Dash/tst_Card.qml−1
@@ -124,7 +124,6 @@ Rectangle {
124124 sourceComponent: cardTool.cardComponent
125125 clip: true
126126 onLoaded: {
127− item.template = Qt.binding(function() { return cardTool.template; });
128127 item.components = Qt.binding(function() { return cardTool.components; });
129128 item.cardData = Qt.binding(function() { return Helpers.mapData(dataArea.text, cardTool.components, dataError); });
130129 item.width = Qt.binding(function() { return cardTool.cardWidth || item.implicitWidth; });
tests/qmltests/Dash/tst_GenericScopeView.qml+21−7
@@ -302,6 +302,7 @@ Item {
302302 }
303303
304304 function closePreview() {
305+ tryCompare(testCase.subPageLoader, "x", 0);
305306 var closePreviewMouseArea = findChild(subPageLoader.item, "pageHeader");
306307 mouseClick(closePreviewMouseArea, units.gu(2), units.gu(2));
307308
@@ -616,27 +617,40 @@ Item {
616617 waitForRendering(category0);
617618
618619 var cardTool = findChild(category0, "cardTool");
619− var cardGrid = category0.item;
620−
621620 cardTool.template["non-interactive"] = true;
621+ cardTool.templateChanged();
622+
623+ var category0 = findChild(categoryListView, "dashCategory0");
624+ waitForRendering(category0);
625+
626+ var cardGrid = category0.item;
622627 compare(cardGrid.cardTool.template["non-interactive"], true);
623628
624629 var item0 = findChild(cardGrid, "delegate0");
625630 waitForRendering(item0);
626− item0.template = cardTool.template;
627− compare(item0.template["non-interactive"], true);
628631 compare(item0.enabled, false);
629632 var touchdown = findChild(item0, "touchdown");
630633
631634 compare(touchdown.visible, false);
632− mouseClick(item0);
635+ mousePress(item0);
633636 compare(touchdown.visible, false);
637+ mouseRelease(item0);
634638
635639 cardTool.template["non-interactive"] = false;
640+ cardTool.templateChanged();
636641 compare(cardGrid.cardTool.template["non-interactive"], false);
637− item0.template = cardTool.template;
638− compare(item0.template["non-interactive"], false);
642+
643+ waitForRendering(category0);
644+ item0 = findChild(cardGrid, "delegate0");
639645 compare(item0.enabled, true);
646+ var touchdown = findChild(item0, "touchdown");
647+
648+ compare(touchdown.visible, false);
649+ mousePress(item0);
650+ compare(touchdown.visible, true);
651+ mouseRelease(item0);
652+ compare(touchdown.visible, false);
653+ closePreview();
640654 }
641655 }
642656 }