Merge lp:~cimi/unity8/fix-1214423 into lp:unity8

Proposed by Andrea Cimitan
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
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

To post a comment you must log in.
Revision history for this message
Michael Zanetti (mzanetti) wrote :

29 + readonly property int starCount: 5

this shouldn't be readonly as it is intended to be configurable

Rest looks good to me.

review: Needs Fixing
Revision history for this message
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:480
http://jenkins.qa.ubuntu.com/job/unity8-ci/1501/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/129/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/123/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/28
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/25
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/25
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/25/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/25
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/120/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/129
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/129/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/123
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/123/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2749/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2800/console
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/538
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/537

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1501/rebuild

review: Needs Fixing (continuous-integration)
lp:~cimi/unity8/fix-1214423 updated
481. By Andrea Cimitan

Use single mouse area, make starCount writable

482. By Andrea Cimitan

renames...

483. By Andrea Cimitan

Use starCount as harmattan

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:482
http://jenkins.qa.ubuntu.com/job/unity8-ci/1504/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/133/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/127/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/31
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/28
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/28
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/28/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/28
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/124/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/133
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/133/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/127
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/127/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2753/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2804/console
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/545
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/546

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1504/rebuild

review: Needs Fixing (continuous-integration)
lp:~cimi/unity8/fix-1214423 updated
484. By Andrea Cimitan

revert previous commit

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:483
http://jenkins.qa.ubuntu.com/job/unity8-ci/1506/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/136/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/130/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/33
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/30
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/30
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/30/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/30
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/127/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/136
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/136/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/130
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/130/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2756/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2807/console
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/552
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/551

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1506/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:484
http://jenkins.qa.ubuntu.com/job/unity8-ci/1507/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/137/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/131/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/34
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/31
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/31
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/31/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/31
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/128/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/137
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/137/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/131
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/131/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2757
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2808/console
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/553
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/554

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1507/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
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

review: Needs Fixing
Revision history for this message
Michael Zanetti (mzanetti) wrote :

width/height are not set properly. this breaks all the places where it is used.

review: Needs Fixing
Revision history for this message
Michał Sawicz (saviq) wrote :

Cimi?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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 }

Subscribers

People subscribed via source and target branches