1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 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 "qdeclarativepluginparameter_p.h"
38 
39 QT_BEGIN_NAMESPACE
40 
41 /*!
42     \qmltype PluginParameter
43     //! \instantiates QDeclarativePluginParameter
44     \inqmlmodule QtPositioning
45     \ingroup qml-QtPositioning5-common
46     \since QtPositioning 5.14
47 
48     \brief The PluginParameter type describes a parameter for a plugin, either
49     geoservice \l Plugin, or position plugin.
50 
51     The PluginParameter object is used to provide a parameter of some kind
52     to a plugin. Typically these parameters contain details like an application
53     token for access to a service, or a proxy server to use for network access,
54     or the serial port to which a serial GPS receiver is connected.
55 
56     To set such a parameter, declare a PluginParameter inside an element that accepts
57     plugin parameters as configuration objects, such as a \l Plugin object, or a
58     \l PositionSource object, and give it \l{name} and \l{value} properties. A list of valid
59     parameter names for each plugin is available from the
60     \l {Qt Location#Plugin References and Parameters}{plugin reference pages} for geoservice plugins,
61     and \l {Qt Positioning plugins#Default plugins} for position plugins.
62 
63     \section2 Example Usage
64 
65     The following example shows an instantiation of the \l {Qt Location HERE Plugin}{HERE} plugin
66     with a mapping API \e app_id and \e token pair specific to the application.
67 
68     \code
69     Plugin {
70         name: "here"
71         PluginParameter { name: "here.app_id"; value: "EXAMPLE_API_ID" }
72         PluginParameter { name: "here.token"; value: "EXAMPLE_TOKEN_123" }
73     }
74     \endcode
75 */
76 
77 /*!
78     \qmlproperty string PluginParameter::name
79 
80     This property holds the name of the plugin parameter as a single formatted string.
81     This property is a write-once property.
82 */
83 
84 /*!
85     \qmlproperty QVariant PluginParameter::value
86 
87     This property holds the value of the plugin parameter which support different types of values (variant).
88     This property is a write-once property.
89 */
90 
QDeclarativePluginParameter(QObject * parent)91 QDeclarativePluginParameter::QDeclarativePluginParameter(QObject *parent)
92     : QObject(parent) {}
93 
~QDeclarativePluginParameter()94 QDeclarativePluginParameter::~QDeclarativePluginParameter() {}
95 
setName(const QString & name)96 void QDeclarativePluginParameter::setName(const QString &name)
97 {
98     if (!name_.isEmpty() || name.isEmpty())
99         return;
100 
101     name_ = name;
102 
103     emit nameChanged(name_);
104     if (value_.isValid())
105         emit initialized();
106 }
107 
name() const108 QString QDeclarativePluginParameter::name() const
109 {
110     return name_;
111 }
112 
setValue(const QVariant & value)113 void QDeclarativePluginParameter::setValue(const QVariant &value)
114 {
115     if (value_.isValid() || !value.isValid() || value.isNull())
116         return;
117 
118     value_ = value;
119 
120     emit valueChanged(value_);
121     if (!name_.isEmpty())
122         emit initialized();
123 }
124 
value() const125 QVariant QDeclarativePluginParameter::value() const
126 {
127     return value_;
128 }
129 
isInitialized() const130 bool QDeclarativePluginParameter::isInitialized() const
131 {
132     return !name_.isEmpty() && value_.isValid();
133 }
134 
135 QT_END_NAMESPACE
136