on xenial help sign in
Update the icon also to the original one if that's what the scope wants

Approved by: Andrea Cimitan

commitda3aeab96c318defbbb941dd5f7b44162023e194 authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 4 May 2016, 18:08 (10 years ago) parent80c6df447d1d95
2 files changed+29−4
qml/Dash/Previews/PreviewIconActions.qml+15 tests/qmltests/Dash/Previews/tst_PreviewIconActions.qml+14−4
qml/Dash/Previews/PreviewIconActions.qml+15
@@ -32,10 +32,20 @@ PreviewWidget {
3232 id: row
3333 readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
3434 width: parent.width
35+ onActionsChanged: {
36+ // Rewire the source since it may have been unwired on onClicked
37+ // but the icon didn't change i.e. the scope updated the results
38+ // and the icon needs to go back to the one it was originally
39+ for (var i = 0; i < repeater.count; ++i) {
40+ var button = repeater.itemAt(i);
41+ button.updateIcon();
42+ }
43+ }
3544
3645 spacing: units.gu(2)
3746
3847 Repeater {
48+ id: repeater
3949 model: row.actions
4050
4151 AbstractButton {
@@ -43,6 +53,11 @@ PreviewWidget {
4353 height: label.height
4454 width: childrenRect.width
4555
56+ readonly property var iconUrl: modelData.icon;
57+ function updateIcon() {
58+ icon.source = iconUrl;
59+ }
60+
4661 Image {
4762 id: icon
4863 height: parent.height
tests/qmltests/Dash/Previews/tst_PreviewIconActions.qml+14−4
@@ -69,9 +69,12 @@ Rectangle {
6969 Timer {
7070 id: timer
7171 property int index: -1
72+ property bool changeIcon: true
7273 interval: 500
7374 onTriggered: {
74− actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
75+ if (changeIcon) {
76+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
77+ }
7578 preview.widgetDataChanged();
7679 index = -1;
7780 }
@@ -89,12 +92,14 @@ Rectangle {
8992
9093 function test_checkButtonWithTemporary_data() {
9194 return [
92− {tag: "with temporary", temporaryIcon: "emblem", index: 0},
93− {tag: "without temporary", temporaryIcon: undefined, index: 2},
95+ {tag: "with temporary change icon", temporaryIcon: "emblem", index: 0, changeIcon: true},
96+ {tag: "with temporary no change icon", temporaryIcon: "emblem", index: 1, changeIcon: false},
97+ {tag: "without temporary", temporaryIcon: undefined, index: 2, changeIcon: true},
9498 ];
9599 }
96100
97101 function test_checkButtonWithTemporary(data) {
102+ waitForRendering(preview);
98103 spy.target = preview;
99104
100105 var buttonId = actionDataActions.actions[data.index].id;
@@ -108,6 +113,7 @@ Rectangle {
108113
109114 compare(image.source, buttonIcon);
110115 compare(label.text, buttonLabel);
116+ timer.changeIcon = data.changeIcon;
111117 mouseClick(button);
112118 compare(spy.count, 1);
113119 compare(spy.signalArguments[0][1], buttonId);
@@ -119,7 +125,11 @@ Rectangle {
119125 tryCompareFunction(function() {
120126 var button = findChild(root, "button" + buttonId);
121127 var image = findChildsByType(button, "QQuickImage")[0];
122− return image.source && image.source.toString().indexOf("UnityLogo") > -1;
128+ if (data.changeIcon) {
129+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
130+ } else {
131+ return image.source && image.source == buttonIcon;
132+ }
123133 }, true);
124134 }
125135 }