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

source code of qtlocation/src/location/declarativeplaces/qdeclarativeplaceimagemodel.cpp