on xenial help sign in
Make fallback also be fallback for empty preview images
commit87c306fee2ce6e5bcf75168afa680bfee5c49449 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 8 Jan 2016, 15:19 (11 years ago) parenta47644a
6 files changed+51−5
qml/Dash/Previews/PreviewHeader.qml+1−1 qml/Dash/Previews/PreviewImageGallery.qml+2−2 qml/Dash/Previews/PreviewZoomableImage.qml+2−2 tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15 tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12
qml/Dash/Previews/PreviewHeader.qml+1−1
@@ -35,7 +35,7 @@ PreviewWidget {
3535 Item {
3636 id: headerRoot
3737 objectName: "innerPreviewHeader"
38− readonly property url mascot: root.widgetData["mascot"] || ""
38+ readonly property url mascot: root.widgetData["mascot"] || fallback
3939 readonly property url fallback: root.widgetData["fallback"] || ""
4040 readonly property string title: root.widgetData["title"] || ""
4141 readonly property string subtitle: root.widgetData["subtitle"] || ""
qml/Dash/Previews/PreviewImageGallery.qml+2−2
@@ -59,7 +59,7 @@ PreviewWidget {
5959 top: parent.top
6060 bottom: parent.bottom
6161 }
62− source: modelData ? modelData : ""
62+ source: modelData || root.widgetData["fallback"] || ""
6363 scaleTo: "height"
6464 initialWidth: units.gu(13)
6565 pressed: mouseArea.pressed
@@ -128,7 +128,7 @@ PreviewWidget {
128128 bottom: parent.bottom
129129 }
130130 width: overlay.width
131− source: modelData ? modelData : ""
131+ source: modelData || root.widgetData["fallback"] || ""
132132 fillMode: Image.PreserveAspectFit
133133 sourceSize { width: screenshot.width; height: screenshot.height }
134134
qml/Dash/Previews/PreviewZoomableImage.qml+2−2
@@ -42,7 +42,7 @@ PreviewWidget {
4242 right: parent.right
4343 }
4444 scaleTo: "width"
45− source: widgetData["source"]
45+ source: widgetData["source"] || widgetData["fallback"] || ""
4646 asynchronous: true
4747 useUbuntuShape: false
4848 pressed: mouseArea.pressed
@@ -86,7 +86,7 @@ PreviewWidget {
8686
8787 delegate: ZoomableImage {
8888 anchors.fill: parent
89− source: widgetData["source"]
89+ source: widgetData["source"] || widgetData["fallback"] || ""
9090 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
9191 // If modelData would change after failing to load it would not be
9292 // reloaded since the source binding is destroyed by the source = fallback
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15
@@ -54,6 +54,14 @@ Rectangle {
5454 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
5555 }
5656
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+
5765 PreviewHeader {
5866 id: previewHeader
5967 widgetData: headerjson
@@ -150,6 +158,13 @@ Rectangle {
150158 var mascot = findChild(previewHeader, "mascotShape");
151159 tryCompare(mascot, "visible", true);
152160 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);
153168 }
154169 }
155170}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19
@@ -48,6 +48,16 @@ Rectangle {
4848 , "fallback": "../../../tests/graphics/clock@18.png"
4949 }
5050
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+
5161 PreviewImageGallery {
5262 id: imageGallery
5363 width: parent.width
@@ -123,5 +133,14 @@ Rectangle {
123133 image3 = findChild(imageGallery, "previewImage3");
124134 tryCompare(image3, "state", "ready");
125135 }
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+ }
126145 }
127146}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12
@@ -39,6 +39,11 @@ Rectangle {
3939 "fallback": "../../graphics/phone_background.jpg"
4040 }
4141
42+ property var widgetData3: {
43+ "source": "",
44+ "fallback": "../../graphics/phone_background.jpg"
45+ }
46+
4247 Loader {
4348 id: loader
4449 width: parent.width
@@ -100,5 +105,12 @@ Rectangle {
100105 waitForRendering(lazyImage);
101106 tryCompare(lazyImage, "state", "ready");
102107 }
108+
109+ function test_emptyfallback() {
110+ zoomableImage.widgetData = widgetData3;
111+ waitForRendering(zoomableImage);
112+ waitForRendering(lazyImage);
113+ tryCompare(lazyImage, "state", "ready");
114+ }
103115 }
104116}