on xenial help sign in
Reload source if it gets updated
commit45b6297aa2ce54c943ea00c6513544c8cb769f88 authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 4 Apr 2016, 11:01 (11 years ago) parent8656344
2 files changed+30−8
qml/Dash/Previews/PreviewZoomableImage.qml+13−8 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+17
qml/Dash/Previews/PreviewZoomableImage.qml+13−8
@@ -34,6 +34,8 @@ PreviewWidget {
3434
3535 property Item rootItem: QuickUtils.rootItem(root)
3636
37+ readonly property var imageUrl: widgetData["source"] || widgetData["fallback"] || ""
38+
3739 LazyImage {
3840 id: lazyImage
3941 objectName: "lazyImage"
@@ -42,7 +44,7 @@ PreviewWidget {
4244 right: parent.right
4345 }
4446 scaleTo: "width"
45− source: widgetData["source"] || widgetData["fallback"] || ""
47+ source: root.imageUrl
4648 asynchronous: true
4749 useUbuntuShape: false
4850 pressed: mouseArea.pressed
@@ -59,11 +61,12 @@ PreviewWidget {
5961
6062 Connections {
6163 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
6564 onStatusChanged: if (lazyImage.sourceImage.status === Image.Error) lazyImage.sourceImage.source = widgetData["fallback"];
6665 }
66+ Connections {
67+ target: root
68+ onImageUrlChanged: lazyImage.sourceImage.source = root.imageUrl;
69+ }
6770
6871 PreviewMediaToolbar {
6972 id: toolbar
@@ -86,12 +89,14 @@ PreviewWidget {
8689
8790 delegate: ZoomableImage {
8891 anchors.fill: parent
89− source: widgetData["source"] || widgetData["fallback"] || ""
92+ source: root.imageUrl
9093 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
9494 onStatusChanged: if (status === Image.Error) source = widgetData["fallback"];
95+
96+ Connections {
97+ target: root
98+ onImageUrlChanged: source = root.imageUrl;
99+ }
95100 }
96101 }
97102}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+17
@@ -44,6 +44,11 @@ Rectangle {
4444 "fallback": "../../graphics/phone_background.jpg"
4545 }
4646
47+ property var widgetData4: {
48+ "source": "fadsasf",
49+ "fallback": "../../graphics/phone_background.jpg"
50+ }
51+
4752 Loader {
4853 id: loader
4954 width: parent.width
@@ -112,5 +117,17 @@ Rectangle {
112117 waitForRendering(lazyImage);
113118 tryCompare(lazyImage, "state", "ready");
114119 }
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+ }
115132 }
116133}