summaryrefslogtreecommitdiff
path: root/src/imports/location/declarativeplaces/qdeclarativecontactdetail.cpp
blob: aa055e111bb47b998e048c45d41fc621ccae5a4b (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
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativecontactdetail_p.h"

/*!
    \qmlclass ContactDetails QDeclarativePropertyMap
    \inqmlmodule QtLocation 5
    \ingroup qml-QtLocation5-places
    \since QtLocation 5.0

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

    The ContactDetails element 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
        \o phone
        \o fax
        \o email
        \o website
    \endlist

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

    \snippet snippets/declarative/places.qml QtLocation import
    \codeline
    \snippet snippets/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 snippets/declarative/places.qml QtQuick import
    \snippet snippets/declarative/places.qml QtLocation import
    \codeline
    \snippet snippets/declarative/places.qml ContactDetails phoneList

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

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

    Note, due to limitations of the QDeclarativePropertyMap, it is not possible
    to declaratively specify the contact details in QML, it can only be accomplished
    via javascript.
*/

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

    Returns an array of contact detail keys currently stored in the map.
*/

/*!
    \qmlclass ContactDetail QDeclarativeContactDetail
    \inqmlmodule QtLocation 5
    \ingroup qml-QtLocation5-places
    \since QtLocation 5.0

    \brief The ContactDetail element 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.
*/
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

    This property is used to provide an interface between C++ and QML code.  First a pointer to a
    ContactDetail object must be obtained from C++, then use the
    \l {QObject::property()}{property()} and \l {QObject::setProperty()}{setProperty()} functions
    to get and set the \c contactDetail property.

    The following gets the QPlaceContactDetail representing this object from C++:

    \snippet snippets/cpp/cppqml.cpp ContactDetail get

    The following sets the properties of this object based on a QPlaceContactDetail object from
    C++:

    \snippet snippets/cpp/cppqml.cpp ContactDetail set
*/
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 localized label describing the contact detail.
*/
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 etc.
*/
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();
    }
}