1/****************************************************************************
2**
3** Copyright (C) 2016 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 "qdeclarativegeomapparameter_p.h"
38
39#include <QByteArray>
40#include <QMetaObject>
41#include <QMetaProperty>
42#include <QObject>
43
44QT_BEGIN_NAMESPACE
45
46namespace {
47class SignalMapper : public QObject
48{
49 Q_OBJECT
50
51 int i;
52public:
53 explicit SignalMapper(int i, QObject *parent = nullptr)
54 : QObject(parent), i(i) {}
55
56public Q_SLOTS:
57 void map() { emit mapped(i); }
58
59Q_SIGNALS:
60 void mapped(int);
61};
62} // unnamed namespace
63
64/*!
65 \qmltype MapParameter
66 \inqmlmodule QtLocation
67 \ingroup qml-QtLocation5-maps
68 \since QtLocation 5.9
69 \deprecated
70
71 This type is deprecated and has been remamed into \l DynamicParameter.
72*/
73
74/*!
75 \qmltype DynamicParameter
76 \instantiates QDeclarativeGeoMapParameter
77 \inqmlmodule QtLocation
78 \ingroup qml-QtLocation5-maps
79 \since Qt Location 5.11
80
81 \brief The DynamicParameter (previously \l MapParameter ) type represents a parameter for a Map element,
82 or other elements used in a Map (such as map items, etc.).
83 This type provides a mean to specify plugin-dependent optional dynamic parameters that allow a plugin to
84 extend the runtime API of the module.
85
86
87 DynamicParameters by default contain only the \l type property, and
88 are highly plugin-dependent.
89 For this reason, additional properties have to be defined inside a
90 DynamicParameter at declaration time, using the QML syntax "property var foo".
91
92 What properties have to be put inside a particular DynamicParameter type for
93 a particular plugin can be found in the documentation of the plugin.
94 \note DynamicParameters are \b optional.
95 By not specifying any of them, the Map, or other container elements, will have the default behavior.
96*/
97
98/*!
99 \qmlproperty string QtLocation::DynamicParameter::type
100
101 Set-once property which holds a string defining the type of the DynamicParameter
102*/
103
104QDeclarativeGeoMapParameter::QDeclarativeGeoMapParameter(QObject *parent)
105: QGeoMapParameter(parent), m_initialPropertyCount(metaObject()->propertyCount()), m_complete(false)
106{
107
108}
109
110QDeclarativeGeoMapParameter::~QDeclarativeGeoMapParameter()
111{
112}
113
114bool QDeclarativeGeoMapParameter::isComponentComplete() const
115{
116 return m_complete;
117}
118
119int QDeclarativeGeoMapParameter::initialPropertyCount() const
120{
121 return m_initialPropertyCount;
122}
123
124void QDeclarativeGeoMapParameter::classBegin()
125{
126}
127
128void QDeclarativeGeoMapParameter::componentComplete()
129{
130 for (int i = m_initialPropertyCount; i < metaObject()->propertyCount(); ++i) {
131 QMetaProperty property = metaObject()->property(index: i);
132
133 if (!property.hasNotifySignal()) {
134 return;
135 }
136
137 SignalMapper *mapper = new SignalMapper(i, this);
138
139 const QByteArray signalName = '2' + property.notifySignal().methodSignature(); // TODO: explain why '2'
140 QObject::connect(sender: this, signal: signalName, receiver: mapper, SLOT(map()));
141 QObject::connect(sender: mapper, SIGNAL(mapped(int)), receiver: this, SLOT(onPropertyUpdated(int)));
142 }
143 m_complete = true;
144 emit completed(this);
145}
146
147void QDeclarativeGeoMapParameter::onPropertyUpdated(int index)
148{
149 emit propertyUpdated(param: this, propertyName: metaObject()->property(index).name());
150}
151
152QT_END_NAMESPACE
153
154#include "qdeclarativegeomapparameter.moc"
155

source code of qtlocation/src/location/declarativemaps/qdeclarativegeomapparameter.cpp