1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #include "qdeclarativereviewmodel_p.h" |
38 | #include "qdeclarativesupplier_p.h" |
39 | |
40 | #include <QtCore/QDateTime> |
41 | #include <QtLocation/QPlaceReview> |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | /*! |
46 | \qmltype ReviewModel |
47 | \instantiates QDeclarativeReviewModel |
48 | \inqmlmodule QtLocation |
49 | \ingroup qml-QtLocation5-places |
50 | \ingroup qml-QtLocation5-places-models |
51 | \since QtLocation 5.5 |
52 | |
53 | \brief Provides access to reviews of a \l Place. |
54 | |
55 | The ReviewModel is a read-only model used to fetch reviews about a \l Place. The model |
56 | incrementally fetches. The number of reviews which are fetched at a time is specified |
57 | by the \l batchSize property. The total number of reviews available can be accessed via the |
58 | \l totalCount property. |
59 | |
60 | To use the ReviewModel we need a view and a delegate. In this snippet we |
61 | see the setting up of a ListView with a ReviewModel model and a delegate. |
62 | |
63 | \snippet places/views/ReviewView.qml ReviewModel delegate |
64 | |
65 | The model returns data for the following roles: |
66 | |
67 | \table |
68 | \header |
69 | \li Role |
70 | \li Type |
71 | \li Description |
72 | \row |
73 | \li dateTime |
74 | \li datetime |
75 | \li The date and time that the review was posted. |
76 | \row |
77 | \li text |
78 | \li string |
79 | \li The review's textual description of the place. It can be either rich (HTML based) text or plain text |
80 | depending on the provider. |
81 | \row |
82 | \li language |
83 | \li string |
84 | \li The language that the review is written in. |
85 | \row |
86 | \li rating |
87 | \li real |
88 | \li The rating that the reviewer gave to the place. |
89 | \row |
90 | \li reviewId |
91 | \li string |
92 | \li The identifier of the review. |
93 | \row |
94 | \li title |
95 | \li string |
96 | \li The title of the review. |
97 | \row |
98 | \li supplier |
99 | \li \l Supplier |
100 | \li The supplier of the review. |
101 | \row |
102 | \li user |
103 | \li \l {QtLocation::User}{User} |
104 | \li The user who contributed the review. |
105 | \row |
106 | \li attribution |
107 | \li string |
108 | \li Attribution text which must be displayed when displaying the review. |
109 | \endtable |
110 | */ |
111 | |
112 | /*! |
113 | \qmlproperty Place QtLocation::ReviewModel::place |
114 | |
115 | This property holds the Place that the reviews are for. |
116 | */ |
117 | |
118 | /*! |
119 | \qmlproperty int QtLocation::ReviewModel::batchSize |
120 | |
121 | This property holds the batch size to use when fetching more reviews. |
122 | */ |
123 | |
124 | /*! |
125 | \qmlproperty int QtLocation::ReviewModel::totalCount |
126 | |
127 | This property holds the total number of reviews for the place. |
128 | */ |
129 | |
130 | QDeclarativeReviewModel::QDeclarativeReviewModel(QObject *parent) |
131 | : QDeclarativePlaceContentModel(QPlaceContent::ReviewType, parent) |
132 | { |
133 | } |
134 | |
135 | QDeclarativeReviewModel::~QDeclarativeReviewModel() |
136 | { |
137 | qDeleteAll(c: m_suppliers); |
138 | } |
139 | |
140 | /*! |
141 | \internal |
142 | */ |
143 | QVariant QDeclarativeReviewModel::data(const QModelIndex &index, int role) const |
144 | { |
145 | if (!index.isValid()) |
146 | return QVariant(); |
147 | |
148 | if (index.row() >= rowCount(parent: index.parent()) || index.row() < 0) |
149 | return QVariant(); |
150 | |
151 | const QPlaceReview &review = m_content.value(akey: index.row()); |
152 | |
153 | switch (role) { |
154 | case DateTimeRole: |
155 | return review.dateTime(); |
156 | case TextRole: |
157 | return review.text(); |
158 | case LanguageRole: |
159 | return review.language(); |
160 | case RatingRole: |
161 | return review.rating(); |
162 | case ReviewIdRole: |
163 | return review.reviewId(); |
164 | case TitleRole: |
165 | return review.title(); |
166 | } |
167 | |
168 | return QDeclarativePlaceContentModel::data(index, role); |
169 | } |
170 | |
171 | QHash<int, QByteArray> QDeclarativeReviewModel::roleNames() const |
172 | { |
173 | QHash<int, QByteArray> roles = QDeclarativePlaceContentModel::roleNames(); |
174 | roles.insert(akey: DateTimeRole, avalue: "dateTime" ); |
175 | roles.insert(akey: TextRole, avalue: "text" ); |
176 | roles.insert(akey: LanguageRole, avalue: "language" ); |
177 | roles.insert(akey: RatingRole, avalue: "rating" ); |
178 | roles.insert(akey: ReviewIdRole, avalue: "reviewId" ); |
179 | roles.insert(akey: TitleRole, avalue: "title" ); |
180 | return roles; |
181 | } |
182 | |
183 | QT_END_NAMESPACE |
184 | |