on xenial help sign in
Implement "rating-edit" preview widget Fixes: #1318144

Approved by: Andrea Cimitan, Pawel Stolowski

commitaf49443a8fa185bf4b72b6e7de0b64163837cd9d authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 18 May 2015, 23:04 (11 years ago) parent12fdb5fb0ea733
7 files changed+244−44
qml/Dash/Previews/PreviewRatingDisplay.qml+9−44 qml/Dash/Previews/PreviewRatingEdit.qml+80 qml/Dash/Previews/PreviewRatingInput.qml+3 qml/Dash/Previews/PreviewRatingSingleDisplay.qml+70 qml/Dash/Previews/PreviewWidgetFactory.qml+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewRatingEdit.qml+80
qml/Dash/Previews/PreviewRatingDisplay.qml+9−44
@@ -49,53 +49,18 @@ PreviewWidget {
4949 objectName: "reviewsRepeater"
5050 model: root.widgetData["reviews"]
5151
52− delegate: Column {
53− id: reviewItem
52+ delegate: PreviewRatingSingleDisplay {
5453 objectName: "reviewItem" + index
55− anchors { left: parent.left; right: parent.right;}
56− spacing: units.gu(1)
5754
58− Rating {
59− id: rating
60− objectName: "rating"
61− size: 5
62− value: modelData["rating"] || -1
63− visible: value >= 0
64− interactive: false
55+ anchors { left: parent.left; right: parent.right; }
6556
66− property var urlIconEmpty: widgetData["rating-icon-empty"]
67− property var urlIconFull: widgetData["rating-icon-full"]
68− property var urlIconHalf: widgetData["rating-icon-half"]
69− }
70−
71− Label {
72− id: authorLabel
73− objectName: "authorLabel"
74− anchors { left: parent.left; right: parent.right }
75− color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
76− opacity: .8
77− text: modelData["author"] || ""
78− visible: text !== ""
79− wrapMode: Text.Wrap
80− }
81−
82− Label {
83− id: reviewLabel
84− objectName: "reviewLabel"
85− anchors { left: parent.left; right: parent.right }
86− color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
87− opacity: .8
88− text: modelData["review"] || ""
89− visible: text !== ""
90− wrapMode: Text.Wrap
91− }
92−
93− Item {
94− id: spacing
95− anchors { left: parent.left; right: parent.right }
96− height: units.gu(2)
97− visible: rating.visible || authorLabel.visible || reviewLabel.visible
98− }
57+ rating: modelData["rating"] || -1
58+ author: modelData["author"] || ""
59+ review: modelData["review"] || ""
60+ urlIconEmpty: widgetData["rating-icon-empty"]
61+ urlIconFull: widgetData["rating-icon-full"]
62+ urlIconHalf: widgetData["rating-icon-half"]
63+ labelColor: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
9964 }
10065 }
10166 }
qml/Dash/Previews/PreviewRatingEdit.qmlnew file+80
@@ -0,0 +1,80 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 0.1
19+import "../../Components"
20+
21+/*! \brief Preview widget for editable rating.
22+
23+ Shows a single display rating that can be switched by the user to edit mode
24+ and then behaves as a rating display widget
25+
26+ The display part uses widgetData["author"], widgetData["review"] and widgetData["rating"].
27+
28+ The edit part uses the same fields as the "rating-input" widget
29+*/
30+
31+PreviewWidget {
32+ id: root
33+ implicitHeight: display.visible ? display.implicitHeight : input.implicitHeight
34+
35+ Button {
36+ id: editIcon
37+ objectName: "editButton"
38+
39+ iconName: "edit"
40+ width: height
41+ anchors.right: parent.right
42+ visible: display.visible
43+ onClicked: display.visible = false
44+ }
45+
46+ PreviewRatingSingleDisplay {
47+ id: display
48+ objectName: "display"
49+
50+ anchors.left: parent.left
51+ anchors.right: editIcon.left
52+
53+ rating: widgetData["rating"] || -1
54+ author: widgetData["author"] || ""
55+ review: widgetData["review"] || ""
56+ urlIconEmpty: widgetData["rating-icon-empty"]
57+ urlIconFull: widgetData["rating-icon-full"]
58+ urlIconHalf: widgetData["rating-icon-half"]
59+ labelColor: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
60+ }
61+
62+ PreviewRatingInput {
63+ id: input
64+ objectName: "input"
65+
66+ visible: !display.visible
67+ width: parent.width
68+
69+ widgetId: root.widgetId
70+ widgetData: root.widgetData
71+ isCurrentPreview: root.isCurrentPreview
72+ scopeStyle: root.scopeStyle
73+
74+ ratingValue: widgetData["rating"]
75+ reviewText: widgetData["review"]
76+
77+ onTriggered: root.triggered(widgetId, actionId, data);
78+ }
79+
80+}
qml/Dash/Previews/PreviewRatingInput.qml+3
@@ -48,6 +48,9 @@ PreviewWidget {
4848 }
4949 }
5050
51+ property alias ratingValue: rating.value
52+ property alias reviewText: reviewTextArea.text
53+
5154 function submit() {
5255 // checks rating-input requirements
5356 if (((widgetData["required"] === "both" ||
qml/Dash/Previews/PreviewRatingSingleDisplay.qmlnew file+70
@@ -0,0 +1,70 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 0.1
19+import "../../Components"
20+
21+Column {
22+ id: reviewItem
23+ spacing: units.gu(1)
24+
25+ property alias rating: ratingItem.value
26+ property alias author: authorLabel.text
27+ property alias review: reviewLabel.text
28+ property alias urlIconEmpty: ratingItem.urlIconEmpty
29+ property alias urlIconFull: ratingItem.urlIconFull
30+ property alias urlIconHalf: ratingItem.urlIconHalf
31+ property alias labelColor: authorLabel.color
32+
33+ Rating {
34+ id: ratingItem
35+ objectName: "rating"
36+ size: 5
37+ visible: value >= 0
38+ interactive: false
39+
40+ property var urlIconEmpty
41+ property var urlIconFull
42+ property var urlIconHalf
43+ }
44+
45+ Label {
46+ id: authorLabel
47+ objectName: "authorLabel"
48+ anchors { left: parent.left; right: parent.right }
49+ opacity: .8
50+ visible: text !== ""
51+ wrapMode: Text.Wrap
52+ }
53+
54+ Label {
55+ id: reviewLabel
56+ objectName: "reviewLabel"
57+ anchors { left: parent.left; right: parent.right }
58+ color: authorLabel.color
59+ opacity: .8
60+ visible: text !== ""
61+ wrapMode: Text.Wrap
62+ }
63+
64+ Item {
65+ id: spacing
66+ anchors { left: parent.left; right: parent.right }
67+ height: units.gu(2)
68+ visible: rating.visible || authorLabel.visible || reviewLabel.visible
69+ }
70+}
qml/Dash/Previews/PreviewWidgetFactory.qml+1
@@ -57,6 +57,7 @@ Loader {
5757 case "progress": return "PreviewProgress.qml";
5858 case "payments": return "PreviewPayments.qml";
5959 case "rating-input": return "PreviewRatingInput.qml";
60+ case "rating-edit": return "PreviewRatingEdit.qml";
6061 case "reviews": return "PreviewRatingDisplay.qml";
6162 case "table": return "PreviewTable.qml";
6263 case "text": return "PreviewTextSummary.qml";
tests/qmltests/CMakeLists.txt+1
@@ -49,6 +49,7 @@ add_qml_test(Dash/Previews PreviewImageGallery)
4949add_qml_test(Dash/Previews PreviewPayments)
5050add_qml_test(Dash/Previews PreviewProgress)
5151add_qml_test(Dash/Previews PreviewRatingDisplay)
52+add_qml_test(Dash/Previews PreviewRatingEdit)
5253add_qml_test(Dash/Previews PreviewRatingInput)
5354add_qml_test(Dash/Previews PreviewTable)
5455add_qml_test(Dash/Previews PreviewTextSummary)
tests/qmltests/Dash/Previews/tst_PreviewRatingEdit.qmlnew file+80
@@ -0,0 +1,80 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Ubuntu.Components 0.1
20+import "../../../../qml/Dash/Previews"
21+import Unity.Test 0.1 as UT
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(80)
27+ color: Theme.palette.selected.background
28+
29+ property var widgetData0: { "visible": "both", "required": "both", author: "Some dude", rating: 4.5, review: "Very cool app" }
30+
31+ PreviewRatingEdit {
32+ id: previewRatingEdit
33+ anchors.left: parent.left
34+ anchors.right: parent.right
35+ widgetData: widgetData0
36+ widgetId: "previewRatingInput"
37+ }
38+
39+ SignalSpy {
40+ id: spy
41+ signalName: "triggered"
42+ }
43+
44+ UT.UnityTestCase {
45+ name: "PreviewRatingEditTest"
46+ when: windowShown
47+
48+ function test_switch_and_trigger(data) {
49+ spy.target = previewRatingEdit;
50+
51+ var authorLabel = findChild(previewRatingEdit, "authorLabel");
52+ var reviewTextArea = findChild(previewRatingEdit, "reviewTextArea");
53+ var inputRating = findChild(findChild(previewRatingEdit, "input"), "rating");
54+ verify(authorLabel.visible)
55+ verify(!reviewTextArea.visible)
56+
57+ var editButton = findChild(previewRatingEdit, "editButton");
58+ mouseClick(editButton);
59+ verify(!authorLabel.visible)
60+ verify(reviewTextArea.visible)
61+
62+ compare(reviewTextArea.text, "Very cool app");
63+ compare(inputRating.value, 4.5);
64+
65+ reviewTextArea.text = "Ho Ho";
66+ inputRating.value = 3;
67+
68+ var submitButton = findChild(previewRatingEdit, "submitButton")
69+ mouseClick(submitButton);
70+
71+ compare(spy.count, 1);
72+ var args = spy.signalArguments[0];
73+ compare(args[0], previewRatingEdit.widgetId);
74+ compare(args[1], "rated");
75+ compare(args[2]["rating"], 3);
76+ compare(args[2]["review"], "Ho Ho");
77+ verify(args[2]["author"] !== undefined); // Just verifying it exists now
78+ }
79+ }
80+}