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

We can resolve it on compile time Approved by: Andrea Cimitan

commit73b509adeeb2fc1562c2cd4720e2eafcc57a7b37 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 12 Feb 2016, 00:11 (11 years ago) parent76c1fc3dc0885d
20 files changed+33−51
plugins/Dash/CardCreator.js+19−14 qml/Dash/CardCarousel.qml−1 qml/Dash/CardGrid.qml−1 qml/Dash/CardHorizontalList.qml−1 qml/Dash/CardTool.qml−1 qml/Dash/CardVerticalJournal.qml−1 tests/plugins/Dash/cardcreator/1.res+3−5 tests/plugins/Dash/cardcreator/10.res−1 tests/plugins/Dash/cardcreator/11.res+3−5 tests/plugins/Dash/cardcreator/2.res−1 tests/plugins/Dash/cardcreator/3.res+3−5 tests/plugins/Dash/cardcreator/4.res−1 tests/plugins/Dash/cardcreator/5.res+3−5 tests/plugins/Dash/cardcreator/5.tst+1−1 tests/plugins/Dash/cardcreator/6.res−1 tests/plugins/Dash/cardcreator/7.res−1 tests/plugins/Dash/cardcreator/8.res+1−2 tests/plugins/Dash/cardcreator/9.res−1 tests/qmltests/Dash/tst_Card.qml−1 tests/qmltests/Dash/tst_CardBenchmark.qml−2
plugins/Dash/CardCreator.js+19−14
@@ -61,8 +61,10 @@ var kBackgroundLoaderCode = 'Loader {\n\
6161// %1 is used as anchors of artShapeHolder
6262// %2 is used as image width
6363// %3 is used as image height
64−// %4 is injected as code to artImage
65−// %5 is used as image fallback
64+// %4 is used for artShapeSource.hideSource and inner Loader visible
65+// %5 is used as aspect ratio fallback
66+// %6 is injected as code to artImage
67+// %7 is used as image fallback
6668var kArtShapeHolderCode = 'Item { \n\
6769 id: artShapeHolder; \n\
6870 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
@@ -71,14 +73,13 @@ var kArtShapeHolderCode = 'Item { \n\
7173 Loader { \n\
7274 id: artShapeLoader; \n\
7375 objectName: "artShapeLoader"; \n\
74− readonly property string cardArt: cardData && cardData["art"] || %5; \n\
76+ readonly property string cardArt: cardData && cardData["art"] || %7; \n\
7577 active: cardArt != ""; \n\
7678 asynchronous: root.asynchronous; \n\
7779 visible: status == Loader.Ready; \n\
7880 sourceComponent: Item { \n\
7981 id: artShape; \n\
8082 objectName: "artShape"; \n\
81− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
8283 visible: image.status == Image.Ready; \n\
8384 readonly property alias image: artImage; \n\
8485 ShaderEffectSource { \n\
@@ -87,11 +88,11 @@ var kArtShapeHolderCode = 'Item { \n\
8788 anchors.centerIn: parent; \n\
8889 width: 1; \n\
8990 height: 1; \n\
90− hideSource: doShapeItem; \n\
91+ hideSource: %4; \n\
9192 } \n\
9293 Loader { \n\
9394 anchors.fill: parent; \n\
94− visible: artShape.doShapeItem; \n\
95+ visible: %4; \n\
9596 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
9697 Component { \n\
9798 id: artShapeShapeComponent; \n\
@@ -115,7 +116,7 @@ var kArtShapeHolderCode = 'Item { \n\
115116 } \n\
116117 } \n\
117118 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
118− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
119+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %5; \n\
119120 Component.onCompleted: { updateWidthHeightBindings(); } \n\
120121 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
121122 function updateWidthHeightBindings() { \n\
@@ -134,7 +135,7 @@ var kArtShapeHolderCode = 'Item { \n\
134135 asynchronous: root.asynchronous; \n\
135136 width: %2; \n\
136137 height: %3; \n\
137− %4 \n\
138+ %6 \n\
138139 } \n\
139140 } \n\
140141 } \n\
@@ -395,7 +396,6 @@ function cardString(template, components) {
395396
396397 code = 'AbstractButton { \n\
397398 id: root; \n\
398− property var components; \n\
399399 property var cardData; \n\
400400 property string artShapeStyle: "inset"; \n\
401401 property string backgroundShapeStyle: "inset"; \n\
@@ -413,7 +413,8 @@ function cardString(template, components) {
413413
414414 var hasArt = components["art"] && components["art"]["field"] || false;
415415 var hasSummary = components["summary"] || false;
416− var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
416+ var isConciergeMode = components["art"] && components["art"]["conciergeMode"] || false;
417+ var artAndSummary = hasArt && hasSummary && !isConciergeMode;
417418 var isHorizontal = template["card-layout"] === "horizontal";
418419 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
419420 (hasSummary && (template["card-background"] || components["background"]));
@@ -483,17 +484,21 @@ function cardString(template, components) {
483484 heightCode = 'width / artShape.aspect';
484485 }
485486
487+ var aspectRatio = components["art"] && components["art"]["aspect-ratio"] || 1;
488+ if (isNaN(aspectRatio)) {
489+ aspectRatio = 1;
490+ }
486491 var fallback = components["art"] && components["art"]["fallback"] || "";
487492 fallback = encodeURI(fallback);
488493 var fallbackStatusCode = "";
489494 var fallbackURICode = '""';
490495 if (fallback !== "") {
491− // fallbackStatusCode has %5 in it because we want to substitute it for fallbackURICode
492− // which in kArtShapeHolderCode is %5
493− fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %5;';
496+ // fallbackStatusCode has %6 in it because we want to substitute it for fallbackURICode
497+ // which in kArtShapeHolderCode is %7
498+ fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %7;';
494499 fallbackURICode = 'decodeURI("%1")'.arg(fallback);
495500 }
496− code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(fallbackStatusCode).arg(fallbackURICode);
501+ code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(isConciergeMode ? "false" : "true").arg(aspectRatio).arg(fallbackStatusCode).arg(fallbackURICode);
497502 } else {
498503 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
499504 }
qml/Dash/CardCarousel.qml−1
@@ -64,7 +64,6 @@ DashRenderer {
6464 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
6565 item.height = Qt.binding(function() { return cardTool.cardHeight; });
6666 item.cardData = Qt.binding(function() { return model; });
67− item.components = Qt.binding(function() { return cardTool.components; });
6867 item.fontScale = Qt.binding(function() { return carousel.fontScale; });
6968 item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
7069 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
qml/Dash/CardGrid.qml−1
@@ -70,7 +70,6 @@ DashRenderer {
7070 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
7171 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
7272 item.cardData = Qt.binding(function() { return model; });
73− item.components = Qt.binding(function() { return cardTool.components; });
7473 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7574 item.scopeStyle = root.scopeStyle;
7675 item.artShapeStyle = root.artShapeStyle;
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.components = Qt.binding(function() { return cardTool.components; });
5756 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
5857 item.scopeStyle = root.scopeStyle;
5958 }
qml/Dash/CardTool.qml−1
@@ -220,7 +220,6 @@ Item {
220220 onLoaded: {
221221 item.objectName = "cardToolCard";
222222 item.asynchronous = false;
223− item.components = Qt.binding(function() { return cardTool.components; });
224223 item.width = Qt.binding(function() { return cardTool.cardWidth !== -1 ? cardTool.cardWidth : item.implicitWidth; });
225224 item.height = Qt.binding(function() { return cardTool.cardHeight !== -1 ? cardTool.cardHeight : item.implicitHeight; });
226225 }
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.components = Qt.binding(function() { return cardTool.components; });
7675 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7776 item.scopeStyle = root.scopeStyle;
7877 }
tests/plugins/Dash/cardcreator/1.res+3−5
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
@@ -31,7 +30,6 @@ Item {
3130 sourceComponent: Item {
3231 id: artShape;
3332 objectName: "artShape";
34− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3533 visible: image.status == Image.Ready;
3634 readonly property alias image: artImage;
3735 ShaderEffectSource {
@@ -40,11 +38,11 @@ Item {
4038 anchors.centerIn: parent;
4139 width: 1;
4240 height: 1;
43− hideSource: doShapeItem;
41+ hideSource: true;
4442 }
4543 Loader {
4644 anchors.fill: parent;
47− visible: artShape.doShapeItem;
45+ visible: true;
4846 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4947 Component {
5048 id: artShapeShapeComponent;
@@ -68,7 +66,7 @@ Item {
6866 }
6967 }
7068 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
71− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1.6;
7270 Component.onCompleted: { updateWidthHeightBindings(); }
7371 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7472 function updateWidthHeightBindings() {
tests/plugins/Dash/cardcreator/10.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/plugins/Dash/cardcreator/11.res+3−5
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
@@ -69,7 +68,6 @@ Item {
6968 sourceComponent: Item {
7069 id: artShape;
7170 objectName: "artShape";
72− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
7371 visible: image.status == Image.Ready;
7472 readonly property alias image: artImage;
7573 ShaderEffectSource {
@@ -78,11 +76,11 @@ Item {
7876 anchors.centerIn: parent;
7977 width: 1;
8078 height: 1;
81− hideSource: doShapeItem;
79+ hideSource: true;
8280 }
8381 Loader {
8482 anchors.fill: parent;
85− visible: artShape.doShapeItem;
83+ visible: true;
8684 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
8785 Component {
8886 id: artShapeShapeComponent;
@@ -106,7 +104,7 @@ Item {
106104 }
107105 }
108106 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
109− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
107+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
110108 Component.onCompleted: { updateWidthHeightBindings(); }
111109 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
112110 function updateWidthHeightBindings() {
tests/plugins/Dash/cardcreator/2.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/plugins/Dash/cardcreator/3.res+3−5
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
@@ -31,7 +30,6 @@ Item {
3130 sourceComponent: Item {
3231 id: artShape;
3332 objectName: "artShape";
34− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3533 visible: image.status == Image.Ready;
3634 readonly property alias image: artImage;
3735 ShaderEffectSource {
@@ -40,11 +38,11 @@ Item {
4038 anchors.centerIn: parent;
4139 width: 1;
4240 height: 1;
43− hideSource: doShapeItem;
41+ hideSource: true;
4442 }
4543 Loader {
4644 anchors.fill: parent;
47− visible: artShape.doShapeItem;
45+ visible: true;
4846 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4947 Component {
5048 id: artShapeShapeComponent;
@@ -68,7 +66,7 @@ Item {
6866 }
6967 }
7068 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
71− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 0.75;
7270 Component.onCompleted: { updateWidthHeightBindings(); }
7371 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7472 function updateWidthHeightBindings() {
tests/plugins/Dash/cardcreator/4.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/plugins/Dash/cardcreator/5.res+3−5
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
@@ -31,7 +30,6 @@ Item {
3130 sourceComponent: Item {
3231 id: artShape;
3332 objectName: "artShape";
34− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3533 visible: image.status == Image.Ready;
3634 readonly property alias image: artImage;
3735 ShaderEffectSource {
@@ -40,11 +38,11 @@ Item {
4038 anchors.centerIn: parent;
4139 width: 1;
4240 height: 1;
43− hideSource: doShapeItem;
41+ hideSource: false;
4442 }
4543 Loader {
4644 anchors.fill: parent;
47− visible: artShape.doShapeItem;
45+ visible: false;
4846 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4947 Component {
5048 id: artShapeShapeComponent;
@@ -68,7 +66,7 @@ Item {
6866 }
6967 }
7068 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
71− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
7270 Component.onCompleted: { updateWidthHeightBindings(); }
7371 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7472 function updateWidthHeightBindings() {
tests/plugins/Dash/cardcreator/5.tst+1−1
@@ -1,3 +1,3 @@
11template: {"non-interactive":true,"card-layout":"vertical","card-size":"medium","category-layout":"carousel","collapsed-rows":2,"overlay":true}
2−components: {"art":{"aspect-ratio":1,"field":"art"},"subtitle":{"field":"artist"},"title":{"field":"title"},"attributes":{}}
2+components: {"art":{"aspect-ratio":1,"field":"art","conciergeMode":true},"subtitle":{"field":"artist"},"title":{"field":"title"},"attributes":{}}
33result: 5.res
tests/plugins/Dash/cardcreator/6.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/plugins/Dash/cardcreator/7.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/plugins/Dash/cardcreator/8.res+1−2
@@ -1,7 +1,6 @@
11AbstractButton {
22 id: root;
3− property var components;
4− property var cardData;
3+ property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
76 property real fontScale: 1.0;
tests/plugins/Dash/cardcreator/9.res−1
@@ -1,6 +1,5 @@
11AbstractButton {
22 id: root;
3− property var components;
43 property var cardData;
54 property string artShapeStyle: "inset";
65 property string backgroundShapeStyle: "inset";
tests/qmltests/Dash/tst_Card.qml−1
@@ -130,7 +130,6 @@ Rectangle {
130130 sourceComponent: cardTool.cardComponent
131131 clip: true
132132 onLoaded: {
133− item.components = Qt.binding(function() { return cardTool.components; });
134133 item.cardData = Qt.binding(function() { return Helpers.mapData(dataArea.text, cardTool.components, dataError); });
135134 item.width = Qt.binding(function() { return cardTool.cardWidth || item.implicitWidth; });
136135 item.height = Qt.binding(function() { return cardTool.cardHeight || item.implicitHeight; });
tests/qmltests/Dash/tst_CardBenchmark.qml−2
@@ -61,8 +61,6 @@ Rectangle {
6161 item.width = Qt.binding(function() { return cardTool.cardWidth || implicitWidth; });
6262 item.height = Qt.binding(function() { return cardTool.cardHeight || implicitHeight; });
6363 item.cardData = Qt.binding(function() { return Helpers.mapData(root.cardData, cardTool.components); });
64− item.template = Qt.binding(function() { return cardTool.template; });
65− item.components = Qt.binding(function() { return cardTool.components; });
6664 }
6765 }
6866 }