Changeset View
Changeset View
Standalone View
Standalone View
src/lib/marble/declarative/GeoItem.h
- 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 | #ifndef MARBLE_DECLARATIVE_GEOITEM_H | ||||
12 | #define MARBLE_DECLARATIVE_GEOITEM_H | ||||
13 | | ||||
14 | #include "GeoDataCoordinates.h" | ||||
15 | #include <QQuickItem> | ||||
16 | #include <QObject> | ||||
17 | #include <QtQml> | ||||
18 | | ||||
19 | /** | ||||
20 | * Binds a QML item to a specific geodetic location in screen coordinates. | ||||
21 | * | ||||
22 | */ | ||||
23 | namespace Marble | ||||
24 | { | ||||
25 | class MarbleQuickItem; | ||||
26 | | ||||
27 | class GeoItem : public QQuickItem | ||||
28 | { | ||||
29 | Q_OBJECT | ||||
30 | | ||||
31 | Q_PROPERTY( Marble::MarbleQuickItem* map READ map WRITE setMap NOTIFY mapChanged ) | ||||
32 | | ||||
33 | Q_PROPERTY( qreal longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged ) | ||||
34 | Q_PROPERTY( qreal latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged ) | ||||
35 | Q_PROPERTY( qreal altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged ) | ||||
36 | // Determines whether the item is on the visible side of the globe | ||||
37 | Q_PROPERTY( bool observable READ observable NOTIFY observableChanged ) | ||||
38 | // We shadow QQuickItem's visible property in order to take the observable into account | ||||
39 | Q_PROPERTY( bool visible READ visObservable WRITE setVisObservable NOTIFY visObservableChanged ) | ||||
40 | | ||||
41 | Q_PROPERTY( qreal x READ readonlyX NOTIFY readonlyXChanged ) | ||||
42 | Q_PROPERTY( qreal y READ readonlyY NOTIFY readonlyYChanged ) | ||||
43 | | ||||
44 | public: | ||||
45 | /** Constructor */ | ||||
46 | explicit GeoItem( QQuickItem *parent = nullptr ); | ||||
47 | | ||||
48 | /** Provides access to the longitude (degree) of the coordinate */ | ||||
49 | qreal longitude() const; | ||||
50 | | ||||
51 | /** Change the longitude of the coordinate */ | ||||
52 | void setLongitude( qreal lon ); | ||||
53 | | ||||
54 | /** Provides access to the latitude (degree) of the coordinate */ | ||||
55 | qreal latitude() const; | ||||
56 | | ||||
57 | /** Change the latitude of the coordinate */ | ||||
58 | void setLatitude( qreal lat ); | ||||
59 | | ||||
60 | /** Provides access to the altitude (meters) of the coordinate */ | ||||
61 | qreal altitude() const; | ||||
62 | | ||||
63 | /** Change the altitude of the coordinate */ | ||||
64 | void setAltitude( qreal alt ); | ||||
65 | | ||||
66 | /** Return all coordinates at once */ | ||||
67 | Marble::GeoDataCoordinates coordinates() const; | ||||
68 | | ||||
69 | /** Change all coordinates at once */ | ||||
70 | void setCoordinates( const Marble::GeoDataCoordinates &coordinates ); | ||||
71 | | ||||
72 | /** Query the Marble map backend that this item uses for screen position determination */ | ||||
73 | MarbleQuickItem* map() const; | ||||
74 | | ||||
75 | /** Hook up the GeoItem with Marble's map backend */ | ||||
76 | void setMap(MarbleQuickItem* map); | ||||
77 | | ||||
78 | /** Return whether the item is visible or hidden on the backside of the globe. */ | ||||
79 | bool observable() const; | ||||
80 | | ||||
81 | /** "Shadowed" version for the visible property to take observable into account. */ | ||||
82 | bool visObservable() const; | ||||
83 | /** "Shadowed" version for the visible() property to take observable into account. */ | ||||
84 | void setVisObservable(bool visible); | ||||
85 | | ||||
86 | /** "Shadowed" version for the x property to disable writing to the property. */ | ||||
87 | qreal readonlyX() const | ||||
88 | { | ||||
89 | return x(); | ||||
90 | } | ||||
91 | | ||||
92 | /** "Shadowed" version for the y property to disable writing to the property. */ | ||||
93 | qreal readonlyY() const | ||||
94 | { | ||||
95 | return y(); | ||||
96 | } | ||||
97 | | ||||
98 | Q_SIGNALS: | ||||
99 | void longitudeChanged(); | ||||
100 | void latitudeChanged(); | ||||
101 | void altitudeChanged(); | ||||
102 | | ||||
103 | void mapChanged(MarbleQuickItem* map); | ||||
104 | | ||||
105 | void observableChanged(bool observable); | ||||
106 | | ||||
107 | void visObservableChanged(bool visible); | ||||
108 | | ||||
109 | void readonlyXChanged(qreal x); | ||||
110 | void readonlyYChanged(qreal y); | ||||
111 | | ||||
112 | private: | ||||
113 | Marble::GeoDataCoordinates m_coordinate; | ||||
114 | MarbleQuickItem* m_map; | ||||
115 | bool m_observable; | ||||
116 | bool m_visible; | ||||
117 | qreal m_x; | ||||
118 | qreal m_y; | ||||
119 | | ||||
120 | void updatePosition(); | ||||
121 | }; | ||||
122 | } | ||||
123 | | ||||
124 | #endif // MARBLE_DECLARATIVE_GEOITEM_H |