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 | 15 | */ | 15 | */ |
6 | 16 | 16 | ||
7 | 17 | import QtQuick 2.0 | 17 | import QtQuick 2.0 |
8 | 18 | import Ubuntu.Components 0.1 | ||
9 | 18 | 19 | ||
11 | 19 | Row { | 20 | Item { |
12 | 20 | id: root | 21 | id: root |
13 | 22 | |||
14 | 23 | /*! | ||
15 | 24 | True if it accepts user input. | ||
16 | 25 | */ | ||
17 | 26 | property bool interactive: true | ||
18 | 27 | |||
19 | 28 | /*! | ||
20 | 29 | Current rating. | ||
21 | 30 | */ | ||
22 | 21 | property int rating | 31 | property int rating |
23 | 32 | |||
24 | 33 | /*! | ||
25 | 34 | Maximum rating. | ||
26 | 35 | */ | ||
27 | 22 | property int maximumRating: 5 | 36 | property int maximumRating: 5 |
38 | 23 | property int starCount: 5 | 37 | |
39 | 24 | height: childrenRect.height | 38 | /*! |
40 | 25 | width: childrenRect.width | 39 | Number of rating stars. |
41 | 26 | 40 | */ | |
42 | 27 | readonly property int effectiveRating: Math.max(0, Math.min(root.starCount * root.rating / root.maximumRating, root.maximumRating)) | 41 | property int starsCount: 5 |
43 | 28 | 42 | ||
44 | 29 | Repeater { | 43 | readonly property int effectiveRating: MathUtils.clamp(starsCount * rating / maximumRating, 0, maximumRating) |
45 | 30 | model: root.effectiveRating | 44 | |
46 | 31 | Image { | 45 | Row { |
47 | 32 | source: "graphics/icon_star_on.png" | 46 | id: row |
48 | 47 | anchors.centerIn: parent | ||
49 | 48 | height: childrenRect.height | ||
50 | 49 | width: childrenRect.width | ||
51 | 50 | |||
52 | 51 | Repeater { | ||
53 | 52 | id: repeater | ||
54 | 53 | |||
55 | 54 | property int averageDelegateWidth: row.width / root.starsCount | ||
56 | 55 | |||
57 | 56 | model: root.starsCount | ||
58 | 57 | |||
59 | 58 | Image { | ||
60 | 59 | objectName: "ratingStar" + index | ||
61 | 60 | source: index < root.effectiveRating ? "graphics/icon_star_on.png" : "graphics/icon_star_off.png" | ||
62 | 61 | } | ||
63 | 33 | } | 62 | } |
64 | 34 | } | 63 | } |
70 | 35 | Repeater { | 64 | |
71 | 36 | model: root.starCount - root.effectiveRating | 65 | MouseArea { |
72 | 37 | Image { | 66 | anchors.fill: row |
73 | 38 | source: "graphics/icon_star_off.png" | 67 | enabled: root.interactive |
74 | 39 | } | 68 | onClicked: root.rating = Math.ceil(mouse.x / repeater.averageDelegateWidth) * root.maximumRating / root.starsCount |
75 | 40 | } | 69 | } |
76 | 41 | } | 70 | } |
77 | 42 | 71 | ||
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 | 15 | add_qml_test(Components Carousel) | 15 | add_qml_test(Components Carousel) |
83 | 16 | add_qml_test(Components MathLocal) | 16 | add_qml_test(Components MathLocal) |
84 | 17 | add_qml_test(Components OpenEffect) | 17 | add_qml_test(Components OpenEffect) |
85 | 18 | add_qml_test(Components RatingStars) | ||
86 | 19 | add_qml_test(Components TimeLocal) | 18 | add_qml_test(Components TimeLocal) |
87 | 20 | add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) | 19 | add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) |
88 | 21 | add_qml_test(Panel IndicatorItem) | 20 | add_qml_test(Panel IndicatorItem) |
89 | @@ -32,6 +31,7 @@ | |||
90 | 32 | add_qml_test(Components EdgeDemoOverlay) | 31 | add_qml_test(Components EdgeDemoOverlay) |
91 | 33 | add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) | 32 | add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins) |
92 | 34 | add_qml_test(Components LazyImage) | 33 | add_qml_test(Components LazyImage) |
93 | 34 | add_qml_test(Components RatingStars) | ||
94 | 35 | add_qml_test(Components ResponsiveFlowView) | 35 | add_qml_test(Components ResponsiveFlowView) |
95 | 36 | add_qml_test(Components ResponsiveGridView) | 36 | add_qml_test(Components ResponsiveGridView) |
96 | 37 | add_qml_test(Components Revealer) | 37 | add_qml_test(Components Revealer) |
97 | 38 | 38 | ||
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 | 17 | import QtQuick 2.0 | 17 | import QtQuick 2.0 |
103 | 18 | import QtTest 1.0 | 18 | import QtTest 1.0 |
104 | 19 | import "../../../Components" | 19 | import "../../../Components" |
112 | 20 | 20 | import Ubuntu.Components 0.1 | |
113 | 21 | TestCase { | 21 | import Unity.Test 0.1 as UT |
114 | 22 | name: "RatingStars" | 22 | |
115 | 23 | 23 | Rectangle { | |
116 | 24 | property int maximumRating: 5 | 24 | id: root |
117 | 25 | property int rating: 3 | 25 | width: units.gu(20) |
118 | 26 | property alias effectiveRating: ratingStars.effectiveRating | 26 | height: units.gu(10) |
119 | 27 | color: "black" | ||
120 | 27 | 28 | ||
121 | 28 | RatingStars { | 29 | RatingStars { |
122 | 29 | id: ratingStars | 30 | id: ratingStars |
154 | 30 | maximumRating: parent.maximumRating | 31 | anchors.centerIn: parent |
155 | 31 | rating: parent.rating | 32 | maximumRating: 5 |
156 | 32 | } | 33 | rating: 3 |
157 | 33 | 34 | } | |
158 | 34 | function test_rating_init() { | 35 | |
159 | 35 | compare(effectiveRating, rating, "EffectiveRating not initialized properly") | 36 | UT.UnityTestCase { |
160 | 36 | } | 37 | name: "RatingStars" |
161 | 37 | 38 | when: windowShown | |
162 | 38 | function test_rating_negative() { | 39 | |
163 | 39 | rating = -3 | 40 | function init() { |
164 | 40 | compare(effectiveRating, 0, "EffectiveRating not calculated correctly") | 41 | ratingStars.maximumRating = 5 |
165 | 41 | } | 42 | ratingStars.rating = 3 |
166 | 42 | 43 | } | |
167 | 43 | function test_rating_set_ok() { | 44 | |
168 | 44 | rating = 2 | 45 | function test_interactive_rating_data() { |
169 | 45 | compare(effectiveRating, rating, "EffectiveRating not calculated correctly") | 46 | return [ |
170 | 46 | } | 47 | {tag: "first star without interactive", interactive: false, maximumRating: 5, index: 0, rating: 3}, |
171 | 47 | 48 | {tag: "first star", interactive: true, maximumRating: 5, index: 0, rating: 1}, | |
172 | 48 | function test_rating_set_too_big() { | 49 | {tag: "second star with big maximumRating", interactive: true, maximumRating: 100, index: 1, rating: 40}, |
173 | 49 | rating = 200 | 50 | {tag: "last star", interactive: true, maximumRating: 5, index: 4, rating: 5}, |
174 | 50 | compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly") | 51 | ]; |
175 | 51 | } | 52 | } |
176 | 52 | 53 | ||
177 | 53 | function test_rating_set_min() { | 54 | function test_interactive_rating(data) { |
178 | 54 | rating = 0 | 55 | ratingStars.interactive = data.interactive |
179 | 55 | compare(effectiveRating, 0, "EffectiveRating not calculated correctly") | 56 | ratingStars.maximumRating = data.maximumRating |
180 | 56 | } | 57 | |
181 | 57 | 58 | var ratingStar = findChild(ratingStars, "ratingStar"+data.index) | |
182 | 58 | function test_rating_set_max() { | 59 | mouseClick(ratingStar, ratingStar.width / 2, ratingStar.height / 2) |
183 | 59 | rating = maximumRating | 60 | compare(ratingStars.rating, data.rating) |
184 | 60 | compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly") | 61 | |
185 | 62 | ratingStars.interactive = false | ||
186 | 63 | } | ||
187 | 64 | |||
188 | 65 | function test_rating_init() { | ||
189 | 66 | compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not initialized properly") | ||
190 | 67 | } | ||
191 | 68 | |||
192 | 69 | function test_rating_negative() { | ||
193 | 70 | ratingStars.rating = -3 | ||
194 | 71 | compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly") | ||
195 | 72 | } | ||
196 | 73 | |||
197 | 74 | function test_rating_set_ok() { | ||
198 | 75 | ratingStars.rating = 2 | ||
199 | 76 | compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not calculated correctly") | ||
200 | 77 | } | ||
201 | 78 | |||
202 | 79 | function test_rating_set_too_big() { | ||
203 | 80 | ratingStars.rating = 200 | ||
204 | 81 | compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly") | ||
205 | 82 | } | ||
206 | 83 | |||
207 | 84 | function test_rating_set_min() { | ||
208 | 85 | ratingStars.rating = 0 | ||
209 | 86 | compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly") | ||
210 | 87 | } | ||
211 | 88 | |||
212 | 89 | function test_rating_set_max() { | ||
213 | 90 | ratingStars.rating = ratingStars.maximumRating | ||
214 | 91 | compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly") | ||
215 | 92 | } | ||
216 | 61 | } | 93 | } |
217 | 62 | } | 94 | } |
29 + readonly property int starCount: 5
this shouldn't be readonly as it is intended to be configurable
Rest looks good to me.