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 "qdeclarativesupplier_p.h"
38 
39 #include <QtCore/QUrl>
40 
41 QT_BEGIN_NAMESPACE
42 
43 /*!
44     \qmltype Supplier
45     \instantiates QDeclarativeSupplier
46     \inqmlmodule QtLocation
47     \ingroup qml-QtLocation5-places
48     \ingroup qml-QtLocation5-places-data
49     \since QtLocation 5.5
50 
51     \brief Holds data regarding the supplier of a place, a place's image, review, or editorial.
52 
53     Each instance represents a set of data about a supplier, which can include
54     supplier's name, url and icon.  The supplier is typically a business or organization.
55 
56     Note: The Places API only supports suppliers as 'retrieve-only' objects.  Submitting
57     suppliers to a provider is not a supported use case.
58 
59     \sa ImageModel, ReviewModel, EditorialModel
60 
61     \section1 Example
62 
63     The following example shows how to create and display a supplier in QML:
64 
65     \snippet declarative/places.qml QtQuick import
66     \snippet declarative/maps.qml QtLocation import
67     \codeline
68     \snippet declarative/places.qml Supplier
69 */
70 
QDeclarativeSupplier(QObject * parent)71 QDeclarativeSupplier::QDeclarativeSupplier(QObject *parent)
72     : QObject(parent), m_icon(0)
73 {
74 }
75 
QDeclarativeSupplier(const QPlaceSupplier & src,QDeclarativeGeoServiceProvider * plugin,QObject * parent)76 QDeclarativeSupplier::QDeclarativeSupplier(const QPlaceSupplier &src,
77                                            QDeclarativeGeoServiceProvider *plugin,
78                                            QObject *parent)
79     : QObject(parent),
80       m_src(src),
81       m_icon(0)
82 {
83     setSupplier(src, plugin);
84 }
85 
~QDeclarativeSupplier()86 QDeclarativeSupplier::~QDeclarativeSupplier()
87 {
88 }
89 
90 /*!
91     \internal
92 */
componentComplete()93 void QDeclarativeSupplier::componentComplete()
94 {
95     // delayed instantiation of QObject based properties.
96     if (!m_icon)
97         m_icon = new QDeclarativePlaceIcon(this);
98 }
99 
100 /*!
101     \qmlproperty QPlaceSupplier Supplier::supplier
102 
103     For details on how to use this property to interface between C++ and QML see
104     "\l {Supplier - QPlaceSupplier} {Interfaces between C++ and QML Code}".
105 */
setSupplier(const QPlaceSupplier & src,QDeclarativeGeoServiceProvider * plugin)106 void QDeclarativeSupplier::setSupplier(const QPlaceSupplier &src, QDeclarativeGeoServiceProvider *plugin)
107 {
108     QPlaceSupplier previous = m_src;
109     m_src = src;
110 
111    if (previous.name() != m_src.name())
112         emit nameChanged();
113 
114     if (previous.supplierId() != m_src.supplierId())
115         emit supplierIdChanged();
116 
117     if (previous.url() != m_src.url())
118         emit urlChanged();
119 
120     if (m_icon && m_icon->parent() == this) {
121         m_icon->setPlugin(plugin);
122         m_icon->setIcon(m_src.icon());
123     } else if (!m_icon || m_icon->parent() != this) {
124         m_icon = new QDeclarativePlaceIcon(m_src.icon(), plugin, this);
125         emit iconChanged();
126     }
127 }
128 
supplier()129 QPlaceSupplier QDeclarativeSupplier::supplier()
130 {
131     m_src.setIcon(m_icon ? m_icon->icon() : QPlaceIcon());
132     return m_src;
133 }
134 
135 /*!
136     \qmlproperty string Supplier::supplierId
137 
138     This property holds the identifier of the supplier.  The identifier is unique
139     to the Plugin backend which provided the supplier and is generally
140     not suitable for displaying to the user.
141 */
142 
setSupplierId(const QString & supplierId)143 void QDeclarativeSupplier::setSupplierId(const QString &supplierId)
144 {
145     if (m_src.supplierId() != supplierId) {
146         m_src.setSupplierId(supplierId);
147         emit supplierIdChanged();
148     }
149 }
150 
supplierId() const151 QString QDeclarativeSupplier::supplierId() const
152 {
153     return m_src.supplierId();
154 }
155 
156 /*!
157     \qmlproperty string Supplier::name
158 
159     This property holds the name of the supplier which can be displayed
160     to the user.
161 
162     The name can potentially be localized.  The language is dependent on the
163     entity that sets it, typically this is the \l Plugin.  The \l {Plugin::locales}
164     property defines what language is used.
165 */
166 
setName(const QString & name)167 void QDeclarativeSupplier::setName(const QString &name)
168 {
169     if (m_src.name() != name) {
170         m_src.setName(name);
171         emit nameChanged();
172     }
173 }
174 
name() const175 QString QDeclarativeSupplier::name() const
176 {
177     return m_src.name();
178 }
179 
180 /*!
181     \qmlproperty url Supplier::url
182 
183     This property holds the URL of the supplier's website.
184 */
185 
setUrl(const QUrl & url)186 void QDeclarativeSupplier::setUrl(const QUrl &url)
187 {
188     if (m_src.url() != url) {
189         m_src.setUrl(url);
190         emit urlChanged();
191     }
192 }
193 
url() const194 QUrl QDeclarativeSupplier::url() const
195 {
196     return m_src.url();
197 }
198 
199 /*!
200     \qmlproperty PlaceIcon Supplier::icon
201 
202     This property holds the icon of the supplier.
203 */
icon() const204 QDeclarativePlaceIcon *QDeclarativeSupplier::icon() const
205 {
206     return m_icon;
207 }
208 
setIcon(QDeclarativePlaceIcon * icon)209 void QDeclarativeSupplier::setIcon(QDeclarativePlaceIcon *icon)
210 {
211     if (m_icon == icon)
212         return;
213 
214     if (m_icon && m_icon->parent() == this)
215         delete m_icon;
216 
217     m_icon = icon;
218     emit iconChanged();
219 }
220 
221 QT_END_NAMESPACE
222