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 "qdeclarativeplaceeditorialmodel_p.h"
38 
39 #include <QtCore/QUrl>
40 #include <QtLocation/QPlaceEditorial>
41 
42 QT_BEGIN_NAMESPACE
43 
44 /*!
45     \qmltype EditorialModel
46     \instantiates QDeclarativePlaceEditorialModel
47     \inqmlmodule QtLocation
48     \ingroup qml-QtLocation5-places
49     \ingroup qml-QtLocation5-places-models
50     \since QtLocation 5.5
51 
52     \brief The EditorialModel type provides a model of place editorials.
53 
54     The EditorialModel is a read-only model used to fetch editorials related to a \l Place.
55     Binding a \l Place via \l EditorialModel::place initiates an initial fetch of editorials.
56     The model performs fetches incrementally and is intended to be used in conjunction
57     with a View such as a \l ListView.  When the View reaches the last of the editorials
58     currently in the model, a fetch is performed to retrieve more if they are available.
59     The View is automatically updated as the editorials are received.  The number of
60     editorials which are fetched at a time is specified by the \l batchSize property.
61     The total number of editorials available can be accessed via the \l totalCount property.
62 
63     The model returns data for the following roles:
64 
65     \table
66         \header
67             \li Role
68             \li Type
69             \li Description
70         \row
71             \li text
72             \li string
73             \li The editorial's textual description of the place.  It can be either rich (HTML based) text or plain text
74                depending upon the provider.
75         \row
76             \li title
77             \li string
78             \li The title of the editorial.
79         \row
80             \li language
81             \li string
82             \li The language that the editorial is written in.
83         \row
84             \li supplier
85             \li \l Supplier
86             \li The supplier of the editorial.
87         \row
88             \li user
89             \li \l {QtLocation::User}{User}
90             \li The user who contributed the editorial.
91         \row
92             \li attribution
93             \li string
94             \li Attribution text which must be displayed when displaying the editorial.
95     \endtable
96 
97     \section1 Example
98 
99     The following example shows how to display editorials for a place:
100 
101     \snippet declarative/places.qml QtQuick import
102     \snippet declarative/maps.qml QtLocation import
103     \codeline
104     \snippet declarative/places.qml EditorialModel
105 
106 */
107 
108 /*!
109     \qmlproperty Place EditorialModel::place
110 
111     This property holds the Place that the editorials are for.
112 */
113 
114 /*!
115     \qmlproperty int EditorialModel::batchSize
116 
117     This property holds the batch size to use when fetching more editorials items.
118 */
119 
120 /*!
121     \qmlproperty int EditorialModel::totalCount
122 
123     This property holds the total number of editorial items for the place.
124 */
125 
QDeclarativePlaceEditorialModel(QObject * parent)126 QDeclarativePlaceEditorialModel::QDeclarativePlaceEditorialModel(QObject *parent)
127 :   QDeclarativePlaceContentModel(QPlaceContent::EditorialType, parent)
128 {
129 }
130 
~QDeclarativePlaceEditorialModel()131 QDeclarativePlaceEditorialModel::~QDeclarativePlaceEditorialModel()
132 {
133 }
134 
135 /*!
136     \internal
137 */
data(const QModelIndex & index,int role) const138 QVariant QDeclarativePlaceEditorialModel::data(const QModelIndex &index, int role) const
139 {
140     if (!index.isValid())
141         return QVariant();
142 
143     if (index.row() >= rowCount(index.parent()) || index.row() < 0)
144         return QVariant();
145 
146     const QPlaceEditorial &description = m_content.value(index.row());
147 
148     switch (role) {
149     case TextRole:
150         return description.text();
151     case TitleRole:
152         return description.title();
153     case LanguageRole:
154         return description.language();
155     }
156 
157     return QDeclarativePlaceContentModel::data(index, role);
158 }
159 
roleNames() const160 QHash<int, QByteArray> QDeclarativePlaceEditorialModel::roleNames() const
161 {
162     QHash<int, QByteArray> roleNames = QDeclarativePlaceContentModel::roleNames();
163     roleNames.insert(TextRole, "text");
164     roleNames.insert(TitleRole, "title");
165     roleNames.insert(LanguageRole, "language");
166     return roleNames;
167 }
168 
169 QT_END_NAMESPACE
170