on xenial help sign in
No need to use components in card creator generated code

We can resolve it on compile time

commit3ae55a48e05e2de48a0a53fd8ff9a398fa4e1248 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 28 Jan 2016, 15:11 (11 years ago) parentce7627c
18 files changed+25−40
plugins/Dash/CardCreator.js+14−9 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/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+14−9
@@ -61,7 +61,9 @@ 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
64+// %4 is used as aspect ratio fallback
65+// %5 is used for artShapeSource.hideSource and inner Loader visible
66+// %6 is injected as code to artImage
6567var kArtShapeHolderCode = 'Item { \n\
6668 id: artShapeHolder; \n\
6769 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
@@ -76,7 +78,6 @@ var kArtShapeHolderCode = 'Item { \n\
7678 sourceComponent: Item { \n\
7779 id: artShape; \n\
7880 objectName: "artShape"; \n\
79− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
8081 visible: image.status == Image.Ready; \n\
8182 readonly property alias image: artImage; \n\
8283 ShaderEffectSource { \n\
@@ -85,11 +86,11 @@ var kArtShapeHolderCode = 'Item { \n\
8586 anchors.centerIn: parent; \n\
8687 width: 1; \n\
8788 height: 1; \n\
88− hideSource: doShapeItem; \n\
89+ hideSource: %5; \n\
8990 } \n\
9091 Loader { \n\
9192 anchors.fill: parent; \n\
92− visible: artShape.doShapeItem; \n\
93+ visible: %5; \n\
9394 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
9495 Component { \n\
9596 id: artShapeShapeComponent; \n\
@@ -113,7 +114,7 @@ var kArtShapeHolderCode = 'Item { \n\
113114 } \n\
114115 } \n\
115116 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
116− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
117+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %4; \n\
117118 Component.onCompleted: { updateWidthHeightBindings(); } \n\
118119 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
119120 function updateWidthHeightBindings() { \n\
@@ -132,7 +133,7 @@ var kArtShapeHolderCode = 'Item { \n\
132133 asynchronous: root.asynchronous; \n\
133134 width: %2; \n\
134135 height: %3; \n\
135− %4 \n\
136+ %6 \n\
136137 } \n\
137138 } \n\
138139 } \n\
@@ -398,7 +399,6 @@ function cardString(template, components) {
398399
399400 code = 'AbstractButton { \n\
400401 id: root; \n\
401− property var components; \n\
402402 property var cardData; \n\
403403 property string artShapeStyle: "inset"; \n\
404404 property string backgroundShapeStyle: "inset"; \n\
@@ -416,7 +416,8 @@ function cardString(template, components) {
416416
417417 var hasArt = components["art"] && components["art"]["field"] || false;
418418 var hasSummary = components["summary"] || false;
419− var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
419+ var isConciergeMode = components["art"] && components["art"]["conciergeMode"] || false;
420+ var artAndSummary = hasArt && hasSummary && !isConciergeMode;
420421 var isHorizontal = template["card-layout"] === "horizontal";
421422 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
422423 (hasSummary && (template["card-background"] || components["background"]));
@@ -478,12 +479,16 @@ function cardString(template, components) {
478479 heightCode = 'width / artShape.aspect';
479480 }
480481
482+ var aspectRatio = components["art"] && components["art"]["aspect-ratio"] || 1;
483+ if (typeof aspectRatio !== "number") {
484+ aspectRatio = 1;
485+ }
481486 var fallback = components["art"] && components["art"]["fallback"] || "";
482487 var fallbackCode = "";
483488 if (fallback !== "") {
484489 fallbackCode += 'onStatusChanged: if (status === Image.Error) source = "%1";'.arg(fallback);
485490 }
486− code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(fallbackCode);
491+ code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(aspectRatio).arg(isConciergeMode ? "false" : "true").arg(fallbackCode);
487492 } else {
488493 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
489494 }
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
@@ -68,7 +68,6 @@ DashRenderer {
6868 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
6969 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
7070 item.cardData = Qt.binding(function() { return model; });
71− item.components = Qt.binding(function() { return cardTool.components; });
7271 item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7372 item.scopeStyle = root.scopeStyle;
7473 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";
@@ -30,7 +29,6 @@ Item {
3029 sourceComponent: Item {
3130 id: artShape;
3231 objectName: "artShape";
33− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3432 visible: image.status == Image.Ready;
3533 readonly property alias image: artImage;
3634 ShaderEffectSource {
@@ -39,11 +37,11 @@ Item {
3937 anchors.centerIn: parent;
4038 width: 1;
4139 height: 1;
42− hideSource: doShapeItem;
40+ hideSource: true;
4341 }
4442 Loader {
4543 anchors.fill: parent;
46− visible: artShape.doShapeItem;
44+ visible: true;
4745 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4846 Component {
4947 id: artShapeShapeComponent;
@@ -67,7 +65,7 @@ Item {
6765 }
6866 }
6967 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
70− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1.6;
7169 Component.onCompleted: { updateWidthHeightBindings(); }
7270 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7371 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";
@@ -30,7 +29,6 @@ Item {
3029 sourceComponent: Item {
3130 id: artShape;
3231 objectName: "artShape";
33− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3432 visible: image.status == Image.Ready;
3533 readonly property alias image: artImage;
3634 ShaderEffectSource {
@@ -39,11 +37,11 @@ Item {
3937 anchors.centerIn: parent;
4038 width: 1;
4139 height: 1;
42− hideSource: doShapeItem;
40+ hideSource: true;
4341 }
4442 Loader {
4543 anchors.fill: parent;
46− visible: artShape.doShapeItem;
44+ visible: true;
4745 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4846 Component {
4947 id: artShapeShapeComponent;
@@ -67,7 +65,7 @@ Item {
6765 }
6866 }
6967 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
70− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 0.75;
7169 Component.onCompleted: { updateWidthHeightBindings(); }
7270 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7371 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";
@@ -30,7 +29,6 @@ Item {
3029 sourceComponent: Item {
3130 id: artShape;
3231 objectName: "artShape";
33− readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
3432 visible: image.status == Image.Ready;
3533 readonly property alias image: artImage;
3634 ShaderEffectSource {
@@ -39,11 +37,11 @@ Item {
3937 anchors.centerIn: parent;
4038 width: 1;
4139 height: 1;
42− hideSource: doShapeItem;
40+ hideSource: false;
4341 }
4442 Loader {
4543 anchors.fill: parent;
46− visible: artShape.doShapeItem;
44+ visible: false;
4745 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
4846 Component {
4947 id: artShapeShapeComponent;
@@ -67,7 +65,7 @@ Item {
6765 }
6866 }
6967 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
70− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
7169 Component.onCompleted: { updateWidthHeightBindings(); }
7270 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
7371 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 }