summaryrefslogtreecommitdiff
path: root/src/imports/location/qdeclarativegeolocation.cpp
blob: 809537e38d600709d8766797cfe4ed9d249165bb (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
#include "qdeclarativegeolocation_p.h"

QT_USE_NAMESPACE

/*!
    \qmlclass Location

    \brief The Location element holds location data.
    \inherits QObject

    Location cointains many properties holding data of the location like geo coordinates,
    address, etc.

    \ingroup qml-places
*/

QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject* parent)
        : QObject(parent)
{
}

QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src,
        QObject *parent)
        : QObject(parent),
          m_address(src.address()),
          m_coordinate(src.coordinate()),
          m_boundingBox(src.viewport()),
          m_src(src)
{
}

QDeclarativeGeoLocation::~QDeclarativeGeoLocation()
{
}

void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src)
{
    QGeoLocation previous = m_src;
    m_src = src;

    if (previous.address() != m_src.address()) {
        m_address.setAddress(m_src.address());
        emit addressChanged();
    }
    if (previous.coordinate() != m_src.coordinate()) {
        m_coordinate.setCoordinate(m_src.coordinate());
        emit coordinateChanged();
    }
    if (previous.locationId() != m_src.locationId()) {
        emit locationIdChanged();
    }
    if (previous.viewport() != m_src.viewport()) {
        emit viewport();
    }
}

QGeoLocation QDeclarativeGeoLocation::location()
{
    m_src.setAddress(m_address.address());
    m_src.setCoordinate(m_coordinate.coordinate());
    m_src.setViewport(m_boundingBox.box());
    return m_src;
}

/*!
    \qmlproperty string Location::address

    This property holds address of the location.
*/
void QDeclarativeGeoLocation::setAddress(QDeclarativeGeoAddress *address)
{
    if (m_src.address() != address->address()) {
        m_address.setAddress(address->address());
        m_src.setAddress(address->address());
        emit addressChanged();
    }
}

QDeclarativeGeoAddress *QDeclarativeGeoLocation::address()
{
    return &m_address;
}

/*!
    \qmlproperty string Location::coordinate

    This property holds display coordinates of the location.

   Note: this property's changed() signal is currently emitted only if the
   whole element changes, not if only the contents of the element change.
*/
void QDeclarativeGeoLocation::setCoordinate(QDeclarativeCoordinate *coordinate)
{
    if (m_src.coordinate() != coordinate->coordinate()) {
        m_coordinate.setCoordinate(coordinate->coordinate());
        m_src.setCoordinate(coordinate->coordinate());
        emit coordinateChanged();
    }
}

QDeclarativeCoordinate *QDeclarativeGeoLocation::coordinate()
{
    return &m_coordinate;
}

/*!
    \qmlproperty string Location::locationId

    This property holds location id.
*/
void QDeclarativeGeoLocation::setLocationId(const QString &locationId)
{
    if (m_src.locationId() != locationId) {
        m_src.setLocationId(locationId);
        emit locationIdChanged();
    }
}

QString QDeclarativeGeoLocation::locationId() const
{
    return m_src.locationId();
}

/*!
    \qmlproperty BoundingBox Location::viewport

    This property holds bouding box of area on map ocupied by location.

    Note: this property's changed() signal is currently emitted only if the
    whole element changes, not if only the contents of the element change.
*/
void QDeclarativeGeoLocation::setViewport(QDeclarativeGeoBoundingBox *viewport)
{
    if (m_src.viewport() != viewport->box()) {
        m_boundingBox.setBox(viewport->box());
        m_src.setViewport(viewport->box());
        emit viewportChanged();
    }
}

QDeclarativeGeoBoundingBox *QDeclarativeGeoLocation::viewport()
{
    return &m_boundingBox;
}