on xenial help sign in
Make fallback also be fallback for empty preview images
87c306fAlbert Astals Cid
qml/Dash/Previews/PreviewHeader.qml+1−1
@@ -35,7 +35,7 @@ PreviewWidget {
35 Item {
35 Item {
36 id: headerRoot
36 id: headerRoot
37 objectName: "innerPreviewHeader"
37 objectName: "innerPreviewHeader"
38− readonly property url mascot: root.widgetData["mascot"] || ""
38+ readonly property url mascot: root.widgetData["mascot"] || fallback
39 readonly property url fallback: root.widgetData["fallback"] || ""
39 readonly property url fallback: root.widgetData["fallback"] || ""
40 readonly property string title: root.widgetData["title"] || ""
40 readonly property string title: root.widgetData["title"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
qml/Dash/Previews/PreviewImageGallery.qml+2−2
@@ -59,7 +59,7 @@ PreviewWidget {
59 top: parent.top
59 top: parent.top
60 bottom: parent.bottom
60 bottom: parent.bottom
61 }
61 }
62− source: modelData ? modelData : ""
62+ source: modelData || root.widgetData["fallback"] || ""
63 scaleTo: "height"
63 scaleTo: "height"
64 initialWidth: units.gu(13)
64 initialWidth: units.gu(13)
65 pressed: mouseArea.pressed
65 pressed: mouseArea.pressed
@@ -128,7 +128,7 @@ PreviewWidget {
128 bottom: parent.bottom
128 bottom: parent.bottom
129 }
129 }
130 width: overlay.width
130 width: overlay.width
131− source: modelData ? modelData : ""
131+ source: modelData || root.widgetData["fallback"] || ""
132 fillMode: Image.PreserveAspectFit
132 fillMode: Image.PreserveAspectFit
133 sourceSize { width: screenshot.width; height: screenshot.height }
133 sourceSize { width: screenshot.width; height: screenshot.height }
134
134
qml/Dash/Previews/PreviewZoomableImage.qml+2−2
@@ -42,7 +42,7 @@ PreviewWidget {
42 right: parent.right
42 right: parent.right
43 }
43 }
44 scaleTo: "width"
44 scaleTo: "width"
45− source: widgetData["source"]
45+ source: widgetData["source"] || widgetData["fallback"] || ""
46 asynchronous: true
46 asynchronous: true
47 useUbuntuShape: false
47 useUbuntuShape: false
48 pressed: mouseArea.pressed
48 pressed: mouseArea.pressed
@@ -86,7 +86,7 @@ PreviewWidget {
86
86
87 delegate: ZoomableImage {
87 delegate: ZoomableImage {
88 anchors.fill: parent
88 anchors.fill: parent
89− source: widgetData["source"]
89+ source: widgetData["source"] || widgetData["fallback"] || ""
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
91 // If modelData would change after failing to load it would not be
91 // If modelData would change after failing to load it would not be
92 // reloaded since the source binding is destroyed by the source = fallback
92 // reloaded since the source binding is destroyed by the source = fallback
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15
@@ -54,6 +54,14 @@ Rectangle {
54 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
54 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
55 }
55 }
56
56
57+ property var emptyfallbackheaderjson: {
58+ "title": "THE TITLE",
59+ "subtitle": "Something catchy",
60+ "mascot": "",
61+ "fallback": "../graphics/play_button.png",
62+ "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
63+ }
64+
57 PreviewHeader {
65 PreviewHeader {
58 id: previewHeader
66 id: previewHeader
59 widgetData: headerjson
67 widgetData: headerjson
@@ -150,6 +158,13 @@ Rectangle {
150 var mascot = findChild(previewHeader, "mascotShape");
158 var mascot = findChild(previewHeader, "mascotShape");
151 tryCompare(mascot, "visible", true);
159 tryCompare(mascot, "visible", true);
152 tryCompare(mascot.source, "status", Image.Ready);
160 tryCompare(mascot.source, "status", Image.Ready);
161+
162+ previewHeader.widgetData = {};
163+ previewHeader.widgetData = emptyfallbackheaderjson;
164+ tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
165+ var mascot = findChild(previewHeader, "mascotShape");
166+ tryCompare(mascot, "visible", true);
167+ tryCompare(mascot.source, "status", Image.Ready);
153 }
168 }
154 }
169 }
155}
170}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19
@@ -48,6 +48,16 @@ Rectangle {
48 , "fallback": "../../../tests/graphics/clock@18.png"
48 , "fallback": "../../../tests/graphics/clock@18.png"
49 }
49 }
50
50
51+ property var sourcesModelEmptyWithFallback: {
52+ "sources": [
53+ "../../graphics/phone_background.jpg",
54+ "../../graphics/tablet_background.jpg",
55+ "../../../tests/graphics/clock@18.png",
56+ ""
57+ ]
58+ , "fallback": "../../../tests/graphics/clock@18.png"
59+ }
60+
51 PreviewImageGallery {
61 PreviewImageGallery {
52 id: imageGallery
62 id: imageGallery
53 width: parent.width
63 width: parent.width
@@ -123,5 +133,14 @@ Rectangle {
123 image3 = findChild(imageGallery, "previewImage3");
133 image3 = findChild(imageGallery, "previewImage3");
124 tryCompare(image3, "state", "ready");
134 tryCompare(image3, "state", "ready");
125 }
135 }
136+
137+ function test_empty_fallback() {
138+ var image3 = findChild(imageGallery, "previewImage3");
139+ tryCompare(image3, "state", "error");
140+ imageGallery.widgetData = sourcesModel0;
141+ imageGallery.widgetData = sourcesModelEmptyWithFallback;
142+ image3 = findChild(imageGallery, "previewImage3");
143+ tryCompare(image3, "state", "ready");
144+ }
126 }
145 }
127}
146}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12
@@ -39,6 +39,11 @@ Rectangle {
39 "fallback": "../../graphics/phone_background.jpg"
39 "fallback": "../../graphics/phone_background.jpg"
40 }
40 }
41
41
42+ property var widgetData3: {
43+ "source": "",
44+ "fallback": "../../graphics/phone_background.jpg"
45+ }
46+
42 Loader {
47 Loader {
43 id: loader
48 id: loader
44 width: parent.width
49 width: parent.width
@@ -100,5 +105,12 @@ Rectangle {
100 waitForRendering(lazyImage);
105 waitForRendering(lazyImage);
101 tryCompare(lazyImage, "state", "ready");
106 tryCompare(lazyImage, "state", "ready");
102 }
107 }
108+
109+ function test_emptyfallback() {
110+ zoomableImage.widgetData = widgetData3;
111+ waitForRendering(zoomableImage);
112+ waitForRendering(lazyImage);
113+ tryCompare(lazyImage, "state", "ready");
114+ }
103 }
115 }
104}
116}