Merge lp:~cimi/unity8/fix-1214423 into lp:unity8
- fix-1214423
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 724 | ||||
Proposed branch: | lp:~cimi/unity8/fix-1214423 | ||||
Merge into: | lp:unity8 | ||||
Diff against target: |
217 lines (+116/-55) 3 files modified
Components/RatingStars.qml (+45/-16) tests/qmltests/CMakeLists.txt (+1/-1) tests/qmltests/Components/tst_RatingStars.qml (+70/-38) |
||||
To merge this branch: | bzr merge lp:~cimi/unity8/fix-1214423 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Zanetti (community) | Needs Fixing | ||
Michał Sawicz | Needs Fixing | ||
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Review via email: mp+192868@code.launchpad.net |
Commit message
Adds interactive property to RatingStars, accepts user interaction, adds tests
Description of the change
Adds interactive property to RatingStars, accepts user interaction, adds tests
Gerry Boland (gerboland) wrote : | # |
Could you not use 1 MouseArea, instead of having one for each star image?
+ Math.max(0, Math.min(starCount * rating / maximumRating, maximumRating))
Using clamp from the SDK would be easier to read.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:480
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 481. By Andrea Cimitan
-
Use single mouse area, make starCount writable
- 482. By Andrea Cimitan
-
renames...
- 483. By Andrea Cimitan
-
Use starCount as harmattan
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:482
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 484. By Andrea Cimitan
-
revert previous commit
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:483
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:484
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Michał Sawicz (saviq) wrote : | # |
Please add a test that ensures that non-interactive stars... are non-interactive :)
Think we should move this to the SDK?
Longer-term we'll need:
* support custom icon urls
* support dragging (not just tapping) to select rating
Michael Zanetti (mzanetti) wrote : | # |
width/height are not set properly. this breaks all the places where it is used.
Michał Sawicz (saviq) wrote : | # |
Cimi?
Preview Diff
1 | === modified file 'Components/RatingStars.qml' |
2 | --- Components/RatingStars.qml 2013-06-05 22:03:08 +0000 |
3 | +++ Components/RatingStars.qml 2013-10-28 16:55:24 +0000 |
4 | @@ -15,27 +15,56 @@ |
5 | */ |
6 | |
7 | import QtQuick 2.0 |
8 | +import Ubuntu.Components 0.1 |
9 | |
10 | -Row { |
11 | +Item { |
12 | id: root |
13 | + |
14 | + /*! |
15 | + True if it accepts user input. |
16 | + */ |
17 | + property bool interactive: true |
18 | + |
19 | + /*! |
20 | + Current rating. |
21 | + */ |
22 | property int rating |
23 | + |
24 | + /*! |
25 | + Maximum rating. |
26 | + */ |
27 | property int maximumRating: 5 |
28 | - property int starCount: 5 |
29 | - height: childrenRect.height |
30 | - width: childrenRect.width |
31 | - |
32 | - readonly property int effectiveRating: Math.max(0, Math.min(root.starCount * root.rating / root.maximumRating, root.maximumRating)) |
33 | - |
34 | - Repeater { |
35 | - model: root.effectiveRating |
36 | - Image { |
37 | - source: "graphics/icon_star_on.png" |
38 | + |
39 | + /*! |
40 | + Number of rating stars. |
41 | + */ |
42 | + property int starsCount: 5 |
43 | + |
44 | + readonly property int effectiveRating: MathUtils.clamp(starsCount * rating / maximumRating, 0, maximumRating) |
45 | + |
46 | + Row { |
47 | + id: row |
48 | + anchors.centerIn: parent |
49 | + height: childrenRect.height |
50 | + width: childrenRect.width |
51 | + |
52 | + Repeater { |
53 | + id: repeater |
54 | + |
55 | + property int averageDelegateWidth: row.width / root.starsCount |
56 | + |
57 | + model: root.starsCount |
58 | + |
59 | + Image { |
60 | + objectName: "ratingStar" + index |
61 | + source: index < root.effectiveRating ? "graphics/icon_star_on.png" : "graphics/icon_star_off.png" |
62 | + } |
63 | } |
64 | } |
65 | - Repeater { |
66 | - model: root.starCount - root.effectiveRating |
67 | - Image { |
68 | - source: "graphics/icon_star_off.png" |
69 | - } |
70 | + |
71 | + MouseArea { |
72 | + anchors.fill: row |
73 | + enabled: root.interactive |
74 | + onClicked: root.rating = Math.ceil(mouse.x / repeater.averageDelegateWidth) * root.maximumRating / root.starsCount |
75 | } |
76 | } |
77 | |
78 | === modified file 'tests/qmltests/CMakeLists.txt' |
79 | --- tests/qmltests/CMakeLists.txt 2013-10-11 12:14:33 +0000 |
80 | +++ tests/qmltests/CMakeLists.txt 2013-10-28 16:55:24 +0000 |
81 | @@ -15,7 +15,6 @@ |
82 | add_qml_test(Components Carousel) |
83 | add_qml_test(Components MathLocal) |
84 | add_qml_test(Components OpenEffect) |
85 | -add_qml_test(Components RatingStars) |
86 | add_qml_test(Components TimeLocal) |
87 | add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) |
88 | add_qml_test(Panel IndicatorItem) |
89 | @@ -32,6 +31,7 @@ |
90 | add_qml_test(Components EdgeDemoOverlay) |
91 | add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) |
92 | add_qml_test(Components LazyImage) |
93 | +add_qml_test(Components RatingStars) |
94 | add_qml_test(Components ResponsiveFlowView) |
95 | add_qml_test(Components ResponsiveGridView) |
96 | add_qml_test(Components Revealer) |
97 | |
98 | === modified file 'tests/qmltests/Components/tst_RatingStars.qml' |
99 | --- tests/qmltests/Components/tst_RatingStars.qml 2013-06-05 22:03:08 +0000 |
100 | +++ tests/qmltests/Components/tst_RatingStars.qml 2013-10-28 16:55:24 +0000 |
101 | @@ -17,46 +17,78 @@ |
102 | import QtQuick 2.0 |
103 | import QtTest 1.0 |
104 | import "../../../Components" |
105 | - |
106 | -TestCase { |
107 | - name: "RatingStars" |
108 | - |
109 | - property int maximumRating: 5 |
110 | - property int rating: 3 |
111 | - property alias effectiveRating: ratingStars.effectiveRating |
112 | +import Ubuntu.Components 0.1 |
113 | +import Unity.Test 0.1 as UT |
114 | + |
115 | +Rectangle { |
116 | + id: root |
117 | + width: units.gu(20) |
118 | + height: units.gu(10) |
119 | + color: "black" |
120 | |
121 | RatingStars { |
122 | id: ratingStars |
123 | - maximumRating: parent.maximumRating |
124 | - rating: parent.rating |
125 | - } |
126 | - |
127 | - function test_rating_init() { |
128 | - compare(effectiveRating, rating, "EffectiveRating not initialized properly") |
129 | - } |
130 | - |
131 | - function test_rating_negative() { |
132 | - rating = -3 |
133 | - compare(effectiveRating, 0, "EffectiveRating not calculated correctly") |
134 | - } |
135 | - |
136 | - function test_rating_set_ok() { |
137 | - rating = 2 |
138 | - compare(effectiveRating, rating, "EffectiveRating not calculated correctly") |
139 | - } |
140 | - |
141 | - function test_rating_set_too_big() { |
142 | - rating = 200 |
143 | - compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly") |
144 | - } |
145 | - |
146 | - function test_rating_set_min() { |
147 | - rating = 0 |
148 | - compare(effectiveRating, 0, "EffectiveRating not calculated correctly") |
149 | - } |
150 | - |
151 | - function test_rating_set_max() { |
152 | - rating = maximumRating |
153 | - compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly") |
154 | + anchors.centerIn: parent |
155 | + maximumRating: 5 |
156 | + rating: 3 |
157 | + } |
158 | + |
159 | + UT.UnityTestCase { |
160 | + name: "RatingStars" |
161 | + when: windowShown |
162 | + |
163 | + function init() { |
164 | + ratingStars.maximumRating = 5 |
165 | + ratingStars.rating = 3 |
166 | + } |
167 | + |
168 | + function test_interactive_rating_data() { |
169 | + return [ |
170 | + {tag: "first star without interactive", interactive: false, maximumRating: 5, index: 0, rating: 3}, |
171 | + {tag: "first star", interactive: true, maximumRating: 5, index: 0, rating: 1}, |
172 | + {tag: "second star with big maximumRating", interactive: true, maximumRating: 100, index: 1, rating: 40}, |
173 | + {tag: "last star", interactive: true, maximumRating: 5, index: 4, rating: 5}, |
174 | + ]; |
175 | + } |
176 | + |
177 | + function test_interactive_rating(data) { |
178 | + ratingStars.interactive = data.interactive |
179 | + ratingStars.maximumRating = data.maximumRating |
180 | + |
181 | + var ratingStar = findChild(ratingStars, "ratingStar"+data.index) |
182 | + mouseClick(ratingStar, ratingStar.width / 2, ratingStar.height / 2) |
183 | + compare(ratingStars.rating, data.rating) |
184 | + |
185 | + ratingStars.interactive = false |
186 | + } |
187 | + |
188 | + function test_rating_init() { |
189 | + compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not initialized properly") |
190 | + } |
191 | + |
192 | + function test_rating_negative() { |
193 | + ratingStars.rating = -3 |
194 | + compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly") |
195 | + } |
196 | + |
197 | + function test_rating_set_ok() { |
198 | + ratingStars.rating = 2 |
199 | + compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not calculated correctly") |
200 | + } |
201 | + |
202 | + function test_rating_set_too_big() { |
203 | + ratingStars.rating = 200 |
204 | + compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly") |
205 | + } |
206 | + |
207 | + function test_rating_set_min() { |
208 | + ratingStars.rating = 0 |
209 | + compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly") |
210 | + } |
211 | + |
212 | + function test_rating_set_max() { |
213 | + ratingStars.rating = ratingStars.maximumRating |
214 | + compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly") |
215 | + } |
216 | } |
217 | } |
29 + readonly property int starCount: 5
this shouldn't be readonly as it is intended to be configurable
Rest looks good to me.