on xenial help sign in
Reload Preview Zoomable Image source if it gets updated
ad93debAlbert Astals Cid
qml/Dash/Previews/PreviewZoomableImage.qml+13−8
@@ -34,6 +34,8 @@ PreviewWidget {
34
34
35 property Item rootItem: QuickUtils.rootItem(root)
35 property Item rootItem: QuickUtils.rootItem(root)
36
36
37+ readonly property var imageUrl: widgetData["source"] || widgetData["fallback"] || ""
38+
37 LazyImage {
39 LazyImage {
38 id: lazyImage
40 id: lazyImage
39 objectName: "lazyImage"
41 objectName: "lazyImage"
@@ -42,7 +44,7 @@ PreviewWidget {
42 right: parent.right
44 right: parent.right
43 }
45 }
44 scaleTo: "width"
46 scaleTo: "width"
45− source: widgetData["source"] || widgetData["fallback"] || ""
47+ source: root.imageUrl
46 asynchronous: true
48 asynchronous: true
47 useUbuntuShape: false
49 useUbuntuShape: false
48 pressed: mouseArea.pressed
50 pressed: mouseArea.pressed
@@ -59,11 +61,12 @@ PreviewWidget {
59
61
60 Connections {
62 Connections {
61 target: lazyImage.sourceImage
63 target: lazyImage.sourceImage
62− // If modelData would change after failing to load it would not be
63− // reloaded since the source binding is destroyed by the source = fallback
64− // But at the moment the model never changes
65 onStatusChanged: if (lazyImage.sourceImage.status === Image.Error) lazyImage.sourceImage.source = widgetData["fallback"];
64 onStatusChanged: if (lazyImage.sourceImage.status === Image.Error) lazyImage.sourceImage.source = widgetData["fallback"];
66 }
65 }
66+ Connections {
67+ target: root
68+ onImageUrlChanged: lazyImage.sourceImage.source = root.imageUrl;
69+ }
67
70
68 PreviewMediaToolbar {
71 PreviewMediaToolbar {
69 id: toolbar
72 id: toolbar
@@ -86,12 +89,14 @@ PreviewWidget {
86
89
87 delegate: ZoomableImage {
90 delegate: ZoomableImage {
88 anchors.fill: parent
91 anchors.fill: parent
89− source: widgetData["source"] || widgetData["fallback"] || ""
92+ source: root.imageUrl
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
93 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
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
93− // But at the moment the model never changes
94 onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];
94 onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];
95+
96+ Connections {
97+ target: root
98+ onImageUrlChanged: source = root.imageUrl;
99+ }
95 }
100 }
96 }
101 }
97}
102}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+17
@@ -44,6 +44,11 @@ Rectangle {
44 "fallback": "../../graphics/phone_background.jpg"
44 "fallback": "../../graphics/phone_background.jpg"
45 }
45 }
46
46
47+ property var widgetData4: {
48+ "source": "fadsasf",
49+ "fallback": "../../graphics/phone_background.jpg"
50+ }
51+
47 Loader {
52 Loader {
48 id: loader
53 id: loader
49 width: parent.width
54 width: parent.width
@@ -112,5 +117,17 @@ Rectangle {
112 waitForRendering(lazyImage);
117 waitForRendering(lazyImage);
113 tryCompare(lazyImage, "state", "ready");
118 tryCompare(lazyImage, "state", "ready");
114 }
119 }
120+
121+ function test_fallback_then_source() {
122+ zoomableImage.widgetData = widgetData4;
123+ waitForRendering(zoomableImage);
124+ waitForRendering(lazyImage);
125+ tryCompare(lazyImage, "state", "ready");
126+ verify(lazyImage.sourceImage.source.toString().indexOf("phone_background") > -1);
127+ zoomableImage.widgetData["source"] = "../../graphics/tablet_background.jpg"
128+ zoomableImage.widgetDataChanged();
129+ tryCompare(lazyImage, "state", "ready");
130+ verify(lazyImage.sourceImage.source.toString().indexOf("tablet_background") > -1);
131+ }
115 }
132 }
116}
133}