on xenial help sign in
Adds PreviewRatingDisplay
commitd23d5ffe19c89479b7d307df446a1a18f675cf94 authorAndrea Cimitan <andrea.cimitan@canonical.com> dateFri 28 Feb 2014, 10:47 (13 years ago) parent05d8ae898bd6e9
5 files changed+216
qml/Dash/Previews/PreviewRatingDisplay.qml+101 qml/Dash/Previews/PreviewWidgetFactory.qml+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml+112 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
qml/Dash/Previews/PreviewRatingDisplay.qmlnew file+101
@@ -0,0 +1,101 @@
1+/*
2+ * Copyright (C) 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 Ubuntu.Components 0.1
19+import "../../Components"
20+
21+/*! \brief Preview widget for rating display.
22+
23+ The widget can show a rating widget and a field showing a comment.
24+ The icons used in the rating widget can be customised with
25+ widgetData["rating-icon-empty"], widgetData["rating-icon-full"]
26+ and widgetData["rating-icon-half"].
27+
28+ This widget shows reviews contained in widgetData["reviews"], each of which should be of the form:
29+
30+ \code{.json}
31+ {
32+ "rating": null,
33+ "review": null,
34+ "author": null
35+ }
36+ \endcode
37+ */
38+
39+PreviewWidget {
40+ id: root
41+ height: childrenRect.height
42+
43+ Column {
44+ anchors { left: parent.left; right: parent.right; }
45+ visible: reviewsRepeater.count > 0
46+
47+ Repeater {
48+ id: reviewsRepeater
49+ objectName: "reviewsRepeater"
50+ model: root.widgetData["reviews"]
51+
52+ delegate: Column {
53+ id: reviewItem
54+ objectName: "reviewItem" + index
55+ anchors { left: parent.left; right: parent.right;}
56+ spacing: units.gu(1)
57+
58+ Rating {
59+ id: rating
60+ objectName: "rating"
61+ size: 5
62+ value: modelData["rating"] || -1
63+ visible: value >= 0
64+
65+ property var urlIconEmpty: widgetData["rating-icon-empty"]
66+ property var urlIconFull: widgetData["rating-icon-full"]
67+ property var urlIconHalf: widgetData["rating-icon-half"]
68+ }
69+
70+ Label {
71+ id: authorLabel
72+ objectName: "authorLabel"
73+ anchors { left: parent.left; right: parent.right }
74+ color: Theme.palette.selected.backgroundText
75+ opacity: .8
76+ text: modelData["author"] || ""
77+ visible: text !== ""
78+ wrapMode: Text.Wrap
79+ }
80+
81+ Label {
82+ id: reviewLabel
83+ objectName: "reviewLabel"
84+ anchors { left: parent.left; right: parent.right }
85+ color: Theme.palette.selected.backgroundText
86+ opacity: .8
87+ text: modelData["review"] || ""
88+ visible: text !== ""
89+ wrapMode: Text.Wrap
90+ }
91+
92+ Item {
93+ id: spacing
94+ anchors { left: parent.left; right: parent.right }
95+ height: units.gu(2)
96+ visible: rating.visible || authorLabel.visible || reviewLabel.visible
97+ }
98+ }
99+ }
100+ }
101+}
qml/Dash/Previews/PreviewWidgetFactory.qml+1
@@ -49,6 +49,7 @@ Loader {
4949 case "image": return "PreviewZoomableImage.qml"
5050 case "progress": return "PreviewProgress.qml";
5151 case "rating-input": return "PreviewRatingInput.qml";
52+ case "reviews": return "PreviewRatingDisplay.qml";
5253 case "text": return "PreviewTextSummary.qml";
5354 case "video": return "PreviewVideoPlayback.qml";
5455 default: return "";
tests/qmltests/CMakeLists.txt+1
@@ -62,6 +62,7 @@ add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_I
6262add_qml_test(Dash/Previews PreviewHeader IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6363add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6464add_qml_test(Dash/Previews PreviewProgress IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
65+add_qml_test(Dash/Previews PreviewRatingDisplay IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6566add_qml_test(Dash/Previews PreviewRatingInput IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6667add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6768add_qml_test(Dash/Previews PreviewVideoPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qmlnew file+112
@@ -0,0 +1,112 @@
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 reviewsModel0: {
30+ "reviews": [ ]
31+ }
32+
33+ property var reviewsModel1: {
34+ "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
35+ { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
36+ }
37+
38+ property var reviewsModel2: {
39+ "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
40+ { author: "Another dude", rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
41+ { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
42+ }
43+
44+ property var reviewsModelMixed: {
45+ "reviews": [ { author: "Some dude", review: "Very cool app" },
46+ { author: "" },
47+ { rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
48+ { author: "Yet Another dude", rating: 5 }, ]
49+ }
50+
51+ PreviewRatingDisplay {
52+ id: previewRatingDisplay
53+ anchors.left: parent.left
54+ anchors.right: parent.right
55+ widgetData: reviewsModelMixed
56+ }
57+
58+ UT.UnityTestCase {
59+ name: "PreviewRatingDisplayTest"
60+ when: windowShown
61+
62+ function test_reviews_data() {
63+ return [
64+ {tag: "0 reviews", reviewsModel: reviewsModel0},
65+ {tag: "1 review", reviewsModel: reviewsModel1},
66+ {tag: "3 reviews", reviewsModel: reviewsModel2},
67+ {tag: "3 mixed reviews", reviewsModel: reviewsModelMixed}
68+ ];
69+ }
70+
71+ function test_reviews(data) {
72+ previewRatingDisplay.widgetData = data.reviewsModel;
73+
74+ var reviewsRepeater = findChild(previewRatingDisplay, "reviewsRepeater");
75+ compare(reviewsRepeater.count, data.reviewsModel["reviews"].length);
76+
77+ for (var i = 0; i < data.reviewsModel["reviews"].length; ++i) {
78+ var reviewItem = findChild(previewRatingDisplay, "reviewItem" + i);
79+
80+ var rating = findChild(reviewItem, "rating");
81+ if (data.reviewsModel["reviews"][i]["rating"] >= 0) {
82+ compare(rating.visible, true);
83+ compare(rating.value, data.reviewsModel["reviews"][i]["rating"]);
84+ } else {
85+ compare(rating.visible, false);
86+ }
87+
88+ var authorLabel = findChild(reviewItem, "authorLabel");
89+ if (data.reviewsModel["reviews"][i]["author"] &&
90+ data.reviewsModel["reviews"][i]["author"] !== "") {
91+ compare(authorLabel.visible, true);
92+ compare(authorLabel.text, data.reviewsModel["reviews"][i]["author"]);
93+ } else {
94+ compare(authorLabel.visible, false);
95+ }
96+
97+ var reviewLabel = findChild(reviewItem, "reviewLabel");
98+ if (data.reviewsModel["reviews"][i]["review"] &&
99+ data.reviewsModel["reviews"][i]["review"] !== "") {
100+ compare(reviewLabel.visible, true);
101+ compare(reviewLabel.text, data.reviewsModel["reviews"][i]["review"]);
102+ } else {
103+ compare(reviewLabel.visible, false);
104+ }
105+
106+ if (!rating.visible && !authorLabel.visible && !reviewLabel.visible) {
107+ verify(reviewItem.height === 0);
108+ }
109+ }
110+ }
111+ }
112+}
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
@@ -82,6 +82,7 @@ Rectangle {
8282 { tag: "Image", type: "image", source: "PreviewZoomableImage.qml" },
8383 { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
8484 { tag: "Rating Input", type: "rating-input", source: "PreviewRatingInput.qml" },
85+ { tag: "Rating Display", type: "reviews", source: "PreviewRatingDisplay.qml" },
8586 { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
8687 { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },
8788 ];