7 #include "MarbleQuickItem.h"
8 #include "Coordinate.h"
10 #include "MarbleGlobal.h"
13 using Marble::EARTH_RADIUS;
14 using Marble::DEG2RAD;
29 bool GeoItem::moveToScreenCoordinates(qreal x, qreal y)
31 bool valid = m_map->screenCoordinatesToGeoDataCoordinates(
QPoint(x,y), m_coordinate);
33 updateScreenPosition();
34 emit longitudeChanged();
35 emit latitudeChanged();
40 qreal GeoItem::longitude()
const
42 return m_coordinate.longitude( GeoDataCoordinates::Degree );
45 void GeoItem::setLongitude( qreal lon )
47 if (m_coordinate.longitude(GeoDataCoordinates::Degree) != lon) {
48 m_coordinate.setLongitude( lon, GeoDataCoordinates::Degree );
49 updateScreenPosition();
50 emit longitudeChanged();
54 qreal GeoItem::latitude()
const
56 return m_coordinate.latitude( GeoDataCoordinates::Degree );
59 void GeoItem::setLatitude( qreal lat )
61 if (m_coordinate.latitude(GeoDataCoordinates::Degree) != lat) {
62 m_coordinate.setLatitude( lat, GeoDataCoordinates::Degree );
63 updateScreenPosition();
64 emit latitudeChanged();
68 qreal GeoItem::altitude()
const
70 return m_coordinate.altitude();
73 void GeoItem::setAltitude( qreal alt )
75 if (m_coordinate.altitude() != alt) {
76 m_coordinate.setAltitude( alt );
77 updateScreenPosition();
78 emit altitudeChanged();
89 if (m_coordinate != coordinates) {
90 m_coordinate = coordinates;
91 updateScreenPosition();
95 MarbleQuickItem *GeoItem::map()
const
100 void GeoItem::setMap(MarbleQuickItem *map)
107 connect(m_map, &MarbleQuickItem::geoItemUpdateRequested,
this, &GeoItem::updateScreenPosition);
108 emit mapChanged(m_map);
111 void GeoItem::updateScreenPosition() {
113 QPointF relativePoint = m_map->screenCoordinatesFromGeoDataCoordinates(m_coordinate);
114 bool observable = !relativePoint.
isNull();
115 if (observable != m_observable) {
116 m_observable = observable;
117 emit observableChanged(m_observable);
119 if (!m_coordinate.isValid()) {
120 setPosition(
QPointF(-childrenRect().width(), -childrenRect().height()));
122 else if (observable) {
124 QPointF screenPoint = mapFromItem(m_map, relativePoint);
125 screenPoint -=
QPointF(width()/2.0, height()/2.0);
126 setPosition(screenPoint);
127 emit readonlyXChanged(readonlyX()) ;
128 emit readonlyYChanged(readonlyY()) ;
134 void GeoItem::setMapToParentOnInit()
136 MarbleQuickItem * visualParent = qobject_cast<MarbleQuickItem*>(parentItem());
139 setMap(visualParent);
143 bool GeoItem::observable()
const
148 bool GeoItem::visObservable()
const
153 void GeoItem::setVisObservable(
bool visible)
155 if (m_visible == visible)
160 emit visObservableChanged(m_visible);
164 #include "moc_GeoItem.cpp"