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
=== modified file 'Components/RatingStars.qml'
--- Components/RatingStars.qml 2013-06-05 22:03:08 +0000
+++ Components/RatingStars.qml 2013-10-28 16:55:24 +0000
@@ -15,27 +15,56 @@
15 */15 */
1616
17import QtQuick 2.017import QtQuick 2.0
18import Ubuntu.Components 0.1
1819
19Row {20Item {
20 id: root21 id: root
22
23 /*!
24 True if it accepts user input.
25 */
26 property bool interactive: true
27
28 /*!
29 Current rating.
30 */
21 property int rating31 property int rating
32
33 /*!
34 Maximum rating.
35 */
22 property int maximumRating: 536 property int maximumRating: 5
23 property int starCount: 537
24 height: childrenRect.height38 /*!
25 width: childrenRect.width39 Number of rating stars.
2640 */
27 readonly property int effectiveRating: Math.max(0, Math.min(root.starCount * root.rating / root.maximumRating, root.maximumRating))41 property int starsCount: 5
2842
29 Repeater {43 readonly property int effectiveRating: MathUtils.clamp(starsCount * rating / maximumRating, 0, maximumRating)
30 model: root.effectiveRating44
31 Image {45 Row {
32 source: "graphics/icon_star_on.png"46 id: row
47 anchors.centerIn: parent
48 height: childrenRect.height
49 width: childrenRect.width
50
51 Repeater {
52 id: repeater
53
54 property int averageDelegateWidth: row.width / root.starsCount
55
56 model: root.starsCount
57
58 Image {
59 objectName: "ratingStar" + index
60 source: index < root.effectiveRating ? "graphics/icon_star_on.png" : "graphics/icon_star_off.png"
61 }
33 }62 }
34 }63 }
35 Repeater {64
36 model: root.starCount - root.effectiveRating65 MouseArea {
37 Image {66 anchors.fill: row
38 source: "graphics/icon_star_off.png"67 enabled: root.interactive
39 }68 onClicked: root.rating = Math.ceil(mouse.x / repeater.averageDelegateWidth) * root.maximumRating / root.starsCount
40 }69 }
41}70}
4271
=== modified file 'tests/qmltests/CMakeLists.txt'
--- tests/qmltests/CMakeLists.txt 2013-10-11 12:14:33 +0000
+++ tests/qmltests/CMakeLists.txt 2013-10-28 16:55:24 +0000
@@ -15,7 +15,6 @@
15add_qml_test(Components Carousel)15add_qml_test(Components Carousel)
16add_qml_test(Components MathLocal)16add_qml_test(Components MathLocal)
17add_qml_test(Components OpenEffect)17add_qml_test(Components OpenEffect)
18add_qml_test(Components RatingStars)
19add_qml_test(Components TimeLocal)18add_qml_test(Components TimeLocal)
20add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)19add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
21add_qml_test(Panel IndicatorItem)20add_qml_test(Panel IndicatorItem)
@@ -32,6 +31,7 @@
32add_qml_test(Components EdgeDemoOverlay)31add_qml_test(Components EdgeDemoOverlay)
33add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)32add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
34add_qml_test(Components LazyImage)33add_qml_test(Components LazyImage)
34add_qml_test(Components RatingStars)
35add_qml_test(Components ResponsiveFlowView)35add_qml_test(Components ResponsiveFlowView)
36add_qml_test(Components ResponsiveGridView)36add_qml_test(Components ResponsiveGridView)
37add_qml_test(Components Revealer)37add_qml_test(Components Revealer)
3838
=== modified file 'tests/qmltests/Components/tst_RatingStars.qml'
--- tests/qmltests/Components/tst_RatingStars.qml 2013-06-05 22:03:08 +0000
+++ tests/qmltests/Components/tst_RatingStars.qml 2013-10-28 16:55:24 +0000
@@ -17,46 +17,78 @@
17import QtQuick 2.017import QtQuick 2.0
18import QtTest 1.018import QtTest 1.0
19import "../../../Components"19import "../../../Components"
2020import Ubuntu.Components 0.1
21TestCase {21import Unity.Test 0.1 as UT
22 name: "RatingStars"22
2323Rectangle {
24 property int maximumRating: 524 id: root
25 property int rating: 325 width: units.gu(20)
26 property alias effectiveRating: ratingStars.effectiveRating26 height: units.gu(10)
27 color: "black"
2728
28 RatingStars {29 RatingStars {
29 id: ratingStars30 id: ratingStars
30 maximumRating: parent.maximumRating31 anchors.centerIn: parent
31 rating: parent.rating32 maximumRating: 5
32 }33 rating: 3
3334 }
34 function test_rating_init() {35
35 compare(effectiveRating, rating, "EffectiveRating not initialized properly")36 UT.UnityTestCase {
36 }37 name: "RatingStars"
3738 when: windowShown
38 function test_rating_negative() {39
39 rating = -340 function init() {
40 compare(effectiveRating, 0, "EffectiveRating not calculated correctly")41 ratingStars.maximumRating = 5
41 }42 ratingStars.rating = 3
4243 }
43 function test_rating_set_ok() {44
44 rating = 245 function test_interactive_rating_data() {
45 compare(effectiveRating, rating, "EffectiveRating not calculated correctly")46 return [
46 }47 {tag: "first star without interactive", interactive: false, maximumRating: 5, index: 0, rating: 3},
4748 {tag: "first star", interactive: true, maximumRating: 5, index: 0, rating: 1},
48 function test_rating_set_too_big() {49 {tag: "second star with big maximumRating", interactive: true, maximumRating: 100, index: 1, rating: 40},
49 rating = 20050 {tag: "last star", interactive: true, maximumRating: 5, index: 4, rating: 5},
50 compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly")51 ];
51 }52 }
5253
53 function test_rating_set_min() {54 function test_interactive_rating(data) {
54 rating = 055 ratingStars.interactive = data.interactive
55 compare(effectiveRating, 0, "EffectiveRating not calculated correctly")56 ratingStars.maximumRating = data.maximumRating
56 }57
5758 var ratingStar = findChild(ratingStars, "ratingStar"+data.index)
58 function test_rating_set_max() {59 mouseClick(ratingStar, ratingStar.width / 2, ratingStar.height / 2)
59 rating = maximumRating60 compare(ratingStars.rating, data.rating)
60 compare(effectiveRating, maximumRating, "EffectiveRating not calculated correctly")61
62 ratingStars.interactive = false
63 }
64
65 function test_rating_init() {
66 compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not initialized properly")
67 }
68
69 function test_rating_negative() {
70 ratingStars.rating = -3
71 compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly")
72 }
73
74 function test_rating_set_ok() {
75 ratingStars.rating = 2
76 compare(ratingStars.effectiveRating, ratingStars.rating, "EffectiveRating not calculated correctly")
77 }
78
79 function test_rating_set_too_big() {
80 ratingStars.rating = 200
81 compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly")
82 }
83
84 function test_rating_set_min() {
85 ratingStars.rating = 0
86 compare(ratingStars.effectiveRating, 0, "EffectiveRating not calculated correctly")
87 }
88
89 function test_rating_set_max() {
90 ratingStars.rating = ratingStars.maximumRating
91 compare(ratingStars.effectiveRating, ratingStars.maximumRating, "EffectiveRating not calculated correctly")
92 }
61 }93 }
62}94}

Subscribers

People subscribed via source and target branches