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 "qdeclarativeplaceattribute_p.h" |
38 | |
39 | QT_BEGIN_NAMESPACE |
40 | |
41 | /*! |
42 | \qmltype ExtendedAttributes |
43 | \instantiates QQmlPropertyMap |
44 | \inqmlmodule QtLocation |
45 | \ingroup qml-QtLocation5-places |
46 | \ingroup qml-QtLocation5-places-data |
47 | \since QtLocation 5.5 |
48 | |
49 | \brief The ExtendedAttributes type holds additional data about a \l Place. |
50 | |
51 | The ExtendedAttributes type is a map of \l {PlaceAttribute}{PlaceAttributes}. To access |
52 | attributes in the map use the \l keys() method to get the list of keys stored in the map and |
53 | use the \c {[]} operator to access the \l PlaceAttribute items. |
54 | |
55 | The following are standard keys that are defined by the API. \l Plugin |
56 | implementations are free to define additional keys. Custom keys should |
57 | be qualified by a unique prefix to avoid clashes. |
58 | \table |
59 | \header |
60 | \li key |
61 | \li description |
62 | \row |
63 | \li openingHours |
64 | \li The trading hours of the place |
65 | \row |
66 | \li payment |
67 | \li The types of payment the place accepts, for example visa, mastercard. |
68 | \row |
69 | \li x_provider |
70 | \li The name of the provider that a place is sourced from |
71 | \row |
72 | \li x_id_<provider> (for example x_id_here) |
73 | \li An alternative identifier which identifies the place from the |
74 | perspective of the specified provider. |
75 | \endtable |
76 | |
77 | Some plugins may not support attributes at all, others may only support a |
78 | certain set, others still may support a dynamically changing set of attributes |
79 | over time or even allow attributes to be arbitrarily defined by the client |
80 | application. The attributes could also vary on a place by place basis, |
81 | for example one place may have opening hours while another does not. |
82 | Consult the \l {Plugin References and Parameters}{plugin |
83 | references} for details. |
84 | |
85 | Some attributes may not be intended to be readable by end users, the label field |
86 | of such attributes is empty to indicate this fact. |
87 | |
88 | \note ExtendedAttributes instances are only ever used in the context of \l {Place}s. It is not |
89 | possible to create an ExtendedAttributes instance directly or re-assign a \l {Place}'s |
90 | ExtendedAttributes property. Modification of ExtendedAttributes can only be accomplished |
91 | via Javascript. |
92 | |
93 | The following example shows how to access all \l {PlaceAttribute}{PlaceAttributes} and print |
94 | them to the console: |
95 | |
96 | \snippet declarative/maps.qml QtLocation import |
97 | \codeline |
98 | \snippet declarative/places.qml ExtendedAttributes read |
99 | |
100 | The following example shows how to assign and modify an attribute: |
101 | \snippet declarative/places.qml ExtendedAttributes write |
102 | |
103 | \sa PlaceAttribute, QQmlPropertyMap |
104 | */ |
105 | |
106 | /*! |
107 | \qmlmethod variant ExtendedAttributes::keys() |
108 | |
109 | Returns an array of place attribute keys currently stored in the map. |
110 | */ |
111 | |
112 | /*! |
113 | \qmlsignal void ExtendedAttributes::valueChanged(string key, variant value) |
114 | |
115 | This signal is emitted when the set of attributes changes. \a key is the key |
116 | corresponding to the \a value that was changed. |
117 | |
118 | The corresponding handler is \c onValueChanged. |
119 | */ |
120 | |
121 | /*! |
122 | \qmltype PlaceAttribute |
123 | \instantiates QDeclarativePlaceAttribute |
124 | \inqmlmodule QtLocation |
125 | \ingroup qml-QtLocation5-places |
126 | \ingroup qml-QtLocation5-places-data |
127 | \since QtLocation 5.5 |
128 | |
129 | \brief The PlaceAttribute type holds generic place attribute information. |
130 | |
131 | A place attribute stores an additional piece of information about a \l Place that is not |
132 | otherwise exposed through the \l Place type. A PlaceAttribute is a textual piece of data, |
133 | accessible through the \l text property, and a \l label. Both the \l text and \l label |
134 | properties are intended to be displayed to the user. PlaceAttributes are stored in an |
135 | \l ExtendedAttributes map with a unique key. |
136 | |
137 | The following example shows how to display all attributes in a list: |
138 | |
139 | \snippet declarative/places.qml QtQuick import |
140 | \snippet declarative/maps.qml QtLocation import |
141 | \codeline |
142 | \snippet declarative/places.qml ExtendedAttributes |
143 | |
144 | The following example shows how to assign and modify an attribute: |
145 | \snippet declarative/places.qml ExtendedAttributes write |
146 | */ |
147 | |
148 | QDeclarativePlaceAttribute::QDeclarativePlaceAttribute(QObject *parent) |
149 | : QObject(parent) |
150 | { |
151 | } |
152 | |
153 | QDeclarativePlaceAttribute::QDeclarativePlaceAttribute(const QPlaceAttribute &src, QObject *parent) |
154 | : QObject(parent),m_attribute(src) |
155 | { |
156 | } |
157 | |
158 | QDeclarativePlaceAttribute::~QDeclarativePlaceAttribute() |
159 | { |
160 | } |
161 | |
162 | /*! |
163 | \qmlproperty QPlaceAttribute PlaceAttribute::attribute |
164 | |
165 | For details on how to use this property to interface between C++ and QML see |
166 | "\l {PlaceAttribute - QPlaceAttribute} {Interfaces between C++ and QML Code}". |
167 | */ |
168 | void QDeclarativePlaceAttribute::setAttribute(const QPlaceAttribute &src) |
169 | { |
170 | QPlaceAttribute prevAttribute = m_attribute; |
171 | m_attribute = src; |
172 | |
173 | if (m_attribute.label() != prevAttribute.label()) |
174 | emit labelChanged(); |
175 | if (m_attribute.text() != prevAttribute.text()) |
176 | emit textChanged(); |
177 | } |
178 | |
179 | QPlaceAttribute QDeclarativePlaceAttribute::attribute() const |
180 | { |
181 | return m_attribute; |
182 | } |
183 | |
184 | /*! |
185 | \qmlproperty string PlaceAttribute::label |
186 | |
187 | This property holds the attribute label which is a user visible string |
188 | describing the attribute. |
189 | */ |
190 | void QDeclarativePlaceAttribute::setLabel(const QString &label) |
191 | { |
192 | if (m_attribute.label() != label) { |
193 | m_attribute.setLabel(label); |
194 | emit labelChanged(); |
195 | } |
196 | } |
197 | |
198 | QString QDeclarativePlaceAttribute::label() const |
199 | { |
200 | return m_attribute.label(); |
201 | } |
202 | |
203 | /*! |
204 | \qmlproperty string PlaceAttribute::text |
205 | |
206 | This property holds the attribute text which can be used to show additional information about the place. |
207 | */ |
208 | void QDeclarativePlaceAttribute::setText(const QString &text) |
209 | { |
210 | if (m_attribute.text() != text) { |
211 | m_attribute.setText(text); |
212 | emit textChanged(); |
213 | } |
214 | } |
215 | |
216 | QString QDeclarativePlaceAttribute::text() const |
217 | { |
218 | return m_attribute.text(); |
219 | } |
220 | |
221 | QT_END_NAMESPACE |
222 | |