summaryrefslogtreecommitdiffstats
path: root/src/imports/location/declarativeplaces/qdeclarativecontactdetail.cpp
blob: ef30c5d96deaa0ca0950cd0cbaabea295b26b8b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativecontactdetail_p.h"

/*!
    \qmltype ContactDetails
    \instantiates QDeclarativeContactDetails
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-places
    \ingroup qml-QtLocation5-places-data
    \since Qt Location 5.0

    \brief The ContactDetails type holds contact details for a \l Place.

    The ContactDetails type is a map of \l {QtLocation5::ContactDetail}{ContactDetail} objects.
    To access contact details in the map use the \l keys() method to get the list of keys stored in
    the map and then use the \c {[]} operator to access the
    \l {QtLocation5::ContactDetail}{ContactDetail} items.

    The following keys are defined in the API.  \l Plugin implementations are free to define
    additional keys.

    \list
        \li phone
        \li fax
        \li email
        \li website
    \endlist

    ContactDetails instances are only ever used in the context of \l {Place}{Places}.  It is not possible
    to create a ContactDetails instance directly or re-assign ContactDetails instances to \l {Place}{Places}.
    Modification of ContactDetails can only be accomplished via Javascript.

    \section1 Examples

    The following example shows how to access all \l {QtLocation5::ContactDetail}{ContactDetails}
    and print them to the console:

    \snippet declarative/places.qml QtLocation import
    \codeline
    \snippet declarative/places.qml ContactDetails read

    The returned list of contact details is an \l {QObjectList-based model}{object list} and so can be used directly as a data model.  For example, the
    following demonstrates how to display a list of contact phone numbers in a list view:

    \snippet declarative/places.qml QtQuick import
    \snippet declarative/places.qml QtLocation import
    \codeline
    \snippet declarative/places.qml ContactDetails phoneList

    The following example demonstrates how to assign a single phone number to a place in JavaScript:
    \snippet declarative/places.qml  ContactDetails write single

    The following demonstrates how to assign multiple phone numbers to a place in JavaScript:
    \snippet declarative/places.qml  ContactDetails write multiple
*/

/*!
    \qmlmethod variant ContactDetails::keys()

    Returns an array of contact detail keys currently stored in the map.
*/
QDeclarativeContactDetails::QDeclarativeContactDetails(QObject *parent)
    : QQmlPropertyMap(parent)
{
}

QVariant QDeclarativeContactDetails::updateValue(const QString &, const QVariant &input)
{
    if (input.userType() == QMetaType::QObjectStar) {
        QDeclarativeContactDetail *detail =
                        qobject_cast<QDeclarativeContactDetail *>(input.value<QObject *>());
        if (detail) {
            QVariantList varList;
            varList.append(input);
            return varList;
        }
    }

    return input;
}

/*!
    \qmltype ContactDetail
    \instantiates QDeclarativeContactDetail
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-places
    \ingroup qml-QtLocation5-places-data
    \since Qt Location 5.0

    \brief The ContactDetail type holds a contact detail such as a phone number or a website
           address.

    The ContactDetail provides a single detail on how one could contact a \l Place.  The
    ContactDetail consists of a \l label, which is a localized string describing the contact
    method, and a \l value representing the actual contact detail.

    \section1 Examples

    The following example demonstrates how to assign a single phone number to a place in JavaScript:
    \snippet declarative/places.qml  ContactDetails write single

    The following demonstrates how to assign multiple phone numbers to a place in JavaScript:
    \snippet declarative/places.qml  ContactDetails write multiple

    Note, due to limitations of the QQmlPropertyMap, it is not possible
    to declaratively specify the contact details in QML, it can only be accomplished
    via JavaScript.
*/
QDeclarativeContactDetail::QDeclarativeContactDetail(QObject *parent)
    : QObject(parent)
{
}

QDeclarativeContactDetail::QDeclarativeContactDetail(const QPlaceContactDetail &src, QObject *parent)
    : QObject(parent), m_contactDetail(src)
{
}

QDeclarativeContactDetail::~QDeclarativeContactDetail()
{
}

/*!
    \qmlproperty QPlaceContactDetail QtLocation5::ContactDetail::contactDetail

    For details on how to use this property to interface between C++ and QML see
    "\l {location-cpp-qml.html#contact_detail} {Interfaces between C++ and QML Code}".
*/
void QDeclarativeContactDetail::setContactDetail(const QPlaceContactDetail &src)
{
    QPlaceContactDetail prevContactDetail = m_contactDetail;
    m_contactDetail = src;

    if (m_contactDetail.label() != prevContactDetail.label())
        emit labelChanged();
    if (m_contactDetail.value() != prevContactDetail.value())
        emit valueChanged();
}

QPlaceContactDetail QDeclarativeContactDetail::contactDetail() const
{
    return m_contactDetail;
}

/*!
    \qmlproperty string QtLocation5::ContactDetail::label

    This property holds a label describing the contact detail.

    The label can potentially be localized. The language is dependent on the entity that sets it,
    typically this is the \l {Plugin}.  The \l {Plugin::locales} property defines
    what language is used.
*/
QString QDeclarativeContactDetail::label() const
{
    return m_contactDetail.label();
}

void QDeclarativeContactDetail::setLabel(const QString &label)
{
    if (m_contactDetail.label() != label) {
        m_contactDetail.setLabel(label);
        emit labelChanged();
    }
}

/*!
    \qmlproperty string QtLocation5::ContactDetail::value

    This property holds the value of the contact detail which may be a phone number, an email
    address, a website url and so on.
*/
QString QDeclarativeContactDetail::value() const
{
    return m_contactDetail.value();
}

void QDeclarativeContactDetail::setValue(const QString &value)
{
    if (m_contactDetail.value() != value) {
        m_contactDetail.setValue(value);
        emit valueChanged();
    }
}