on xenial help sign in
Update the icon also to the original one if that's what the scope wants
da3aeabAlbert Astals Cid
qml/Dash/Previews/PreviewIconActions.qml+15
@@ -32,10 +32,20 @@ PreviewWidget {
32 id: row
32 id: row
33 readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
33 readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
34 width: parent.width
34 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+ }
35
44
36 spacing: units.gu(2)
45 spacing: units.gu(2)
37
46
38 Repeater {
47 Repeater {
48+ id: repeater
39 model: row.actions
49 model: row.actions
40
50
41 AbstractButton {
51 AbstractButton {
@@ -43,6 +53,11 @@ PreviewWidget {
43 height: label.height
53 height: label.height
44 width: childrenRect.width
54 width: childrenRect.width
45
55
56+ readonly property var iconUrl: modelData.icon;
57+ function updateIcon() {
58+ icon.source = iconUrl;
59+ }
60+
46 Image {
61 Image {
47 id: icon
62 id: icon
48 height: parent.height
63 height: parent.height
tests/qmltests/Dash/Previews/tst_PreviewIconActions.qml+14−4
@@ -69,9 +69,12 @@ Rectangle {
69 Timer {
69 Timer {
70 id: timer
70 id: timer
71 property int index: -1
71 property int index: -1
72+ property bool changeIcon: true
72 interval: 500
73 interval: 500
73 onTriggered: {
74 onTriggered: {
75+ if (changeIcon) {
74− actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
76+ actionDataActions.actions[index].icon = Qt.resolvedUrl("../../UnityLogo.png");
77+ }
75 preview.widgetDataChanged();
78 preview.widgetDataChanged();
76 index = -1;
79 index = -1;
77 }
80 }
@@ -89,12 +92,14 @@ Rectangle {
89
92
90 function test_checkButtonWithTemporary_data() {
93 function test_checkButtonWithTemporary_data() {
91 return [
94 return [
92− {tag: "with temporary", temporaryIcon: "emblem", index: 0},
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},
93− {tag: "without temporary", temporaryIcon: undefined, index: 2},
97+ {tag: "without temporary", temporaryIcon: undefined, index: 2, changeIcon: true},
94 ];
98 ];
95 }
99 }
96
100
97 function test_checkButtonWithTemporary(data) {
101 function test_checkButtonWithTemporary(data) {
102+ waitForRendering(preview);
98 spy.target = preview;
103 spy.target = preview;
99
104
100 var buttonId = actionDataActions.actions[data.index].id;
105 var buttonId = actionDataActions.actions[data.index].id;
@@ -108,6 +113,7 @@ Rectangle {
108
113
109 compare(image.source, buttonIcon);
114 compare(image.source, buttonIcon);
110 compare(label.text, buttonLabel);
115 compare(label.text, buttonLabel);
116+ timer.changeIcon = data.changeIcon;
111 mouseClick(button);
117 mouseClick(button);
112 compare(spy.count, 1);
118 compare(spy.count, 1);
113 compare(spy.signalArguments[0][1], buttonId);
119 compare(spy.signalArguments[0][1], buttonId);
@@ -119,7 +125,11 @@ Rectangle {
119 tryCompareFunction(function() {
125 tryCompareFunction(function() {
120 var button = findChild(root, "button" + buttonId);
126 var button = findChild(root, "button" + buttonId);
121 var image = findChildsByType(button, "QQuickImage")[0];
127 var image = findChildsByType(button, "QQuickImage")[0];
128+ if (data.changeIcon) {
122− return image.source && image.source.toString().indexOf("UnityLogo") > -1;
129+ return image.source && image.source.toString().indexOf("UnityLogo") > -1;
130+ } else {
131+ return image.source && image.source == buttonIcon;
132+ }
123 }, true);
133 }, true);
124 }
134 }
125 }
135 }