Changeset View
Changeset View
Standalone View
Standalone View
src/lib/marble/declarative/GeoItem.cpp
- This file was added.
1 | // | ||||
---|---|---|---|---|---|
2 | // This file is part of the Marble Virtual Globe. | ||||
3 | // | ||||
4 | // This program is free software licensed under the GNU LGPL. You can | ||||
5 | // find a copy of this license in LICENSE.txt in the top directory of | ||||
6 | // the source code. | ||||
7 | // | ||||
8 | // Copyright 2019 Torsten Rahn <rahn@kde.org> | ||||
9 | // | ||||
10 | | ||||
11 | #include "GeoItem.h" | ||||
12 | #include "MarbleQuickItem.h" | ||||
13 | #include "Coordinate.h" | ||||
14 | | ||||
15 | #include "MarbleGlobal.h" | ||||
16 | | ||||
17 | using Marble::GeoDataCoordinates; | ||||
18 | using Marble::EARTH_RADIUS; | ||||
19 | using Marble::DEG2RAD; | ||||
20 | | ||||
21 | namespace Marble | ||||
22 | { | ||||
23 | GeoItem::GeoItem(QQuickItem *parent ) : | ||||
24 | QQuickItem( parent ), | ||||
25 | m_map(nullptr), | ||||
26 | m_observable(false), | ||||
27 | m_visible(true) | ||||
28 | { | ||||
29 | } | ||||
30 | | ||||
31 | qreal GeoItem::longitude() const | ||||
32 | { | ||||
33 | return m_coordinate.longitude( GeoDataCoordinates::Degree ); | ||||
34 | } | ||||
35 | | ||||
36 | void GeoItem::setLongitude( qreal lon ) | ||||
37 | { | ||||
38 | m_coordinate.setLongitude( lon, GeoDataCoordinates::Degree ); | ||||
39 | updatePosition(); | ||||
40 | emit longitudeChanged(); | ||||
41 | } | ||||
42 | | ||||
43 | qreal GeoItem::latitude() const | ||||
44 | { | ||||
45 | return m_coordinate.latitude( GeoDataCoordinates::Degree ); | ||||
46 | } | ||||
47 | | ||||
48 | void GeoItem::setLatitude( qreal lat ) | ||||
49 | { | ||||
50 | m_coordinate.setLatitude( lat, GeoDataCoordinates::Degree ); | ||||
51 | updatePosition(); | ||||
52 | emit latitudeChanged(); | ||||
53 | } | ||||
54 | | ||||
55 | qreal GeoItem::altitude() const | ||||
56 | { | ||||
57 | return m_coordinate.altitude(); | ||||
58 | } | ||||
59 | | ||||
60 | void GeoItem::setAltitude( qreal alt ) | ||||
61 | { | ||||
62 | m_coordinate.setAltitude( alt ); | ||||
63 | updatePosition(); | ||||
64 | emit altitudeChanged(); | ||||
65 | } | ||||
66 | | ||||
67 | GeoDataCoordinates GeoItem::coordinates() const | ||||
68 | { | ||||
69 | return m_coordinate; | ||||
70 | } | ||||
71 | | ||||
72 | void GeoItem::setCoordinates( const GeoDataCoordinates &coordinates ) | ||||
73 | { | ||||
74 | m_coordinate = coordinates; | ||||
75 | updatePosition(); | ||||
76 | } | ||||
77 | | ||||
78 | MarbleQuickItem *GeoItem::map() const | ||||
79 | { | ||||
80 | return m_map; | ||||
81 | } | ||||
82 | | ||||
83 | void GeoItem::setMap(MarbleQuickItem *map) | ||||
84 | { | ||||
85 | if (m_map == map) | ||||
86 | return; | ||||
87 | | ||||
88 | m_map = map; | ||||
89 | | ||||
90 | connect(m_map, &MarbleQuickItem::visibleLatLonAltBoxChanged, this, [=]() { updatePosition(); }); | ||||
91 | emit mapChanged(m_map); | ||||
92 | } | ||||
93 | | ||||
94 | void GeoItem::updatePosition() { | ||||
95 | if (m_map) { | ||||
96 | QPointF relativePoint = m_map->screenCoordinatesFromGeoDataCoordinates(m_coordinate); | ||||
97 | bool observable = !relativePoint.isNull(); | ||||
98 | if (observable != m_observable) { | ||||
99 | m_observable = observable; | ||||
100 | QQuickItem::setVisible(m_visible && m_observable); | ||||
101 | emit observableChanged(m_observable); | ||||
102 | } | ||||
103 | else { | ||||
104 | setPosition(QPointF(0.0,0.0)); | ||||
105 | QPointF screenPoint = mapFromItem(m_map, relativePoint); | ||||
106 | setPosition(screenPoint); | ||||
107 | emit readonlyXChanged(readonlyX()) ; | ||||
108 | emit readonlyYChanged(readonlyY()) ; | ||||
109 | } | ||||
110 | } | ||||
111 | } | ||||
112 | | ||||
113 | bool GeoItem::observable() const | ||||
114 | { | ||||
115 | return m_observable; | ||||
116 | } | ||||
117 | | ||||
118 | bool GeoItem::visObservable() const | ||||
119 | { | ||||
120 | return m_visible; | ||||
121 | } | ||||
122 | | ||||
123 | void GeoItem::setVisObservable(bool visible) | ||||
124 | { | ||||
125 | if (m_visible == visible) | ||||
126 | return; | ||||
127 | | ||||
128 | m_visible = visible; | ||||
129 | QQuickItem::setVisible(m_visible && m_observable); | ||||
130 | emit visObservableChanged(m_visible); | ||||
131 | } | ||||
132 | } | ||||
133 | | ||||
134 | #include "moc_GeoItem.cpp" |