File indexing completed on 2024-05-05 03:49:16

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2019 Torsten Rahn <rahn@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_DECLARATIVE_GEOITEM_H
0007 #define MARBLE_DECLARATIVE_GEOITEM_H
0008 
0009 #include "GeoDataCoordinates.h"
0010 #include <QQuickItem>
0011 #include <QObject>
0012 #include <QtQml>
0013 
0014 /**
0015   * Binds a QML item to a specific geodetic location in screen coordinates.
0016   *
0017   */
0018 namespace Marble
0019 {
0020     class MarbleQuickItem;
0021 
0022     class GeoItem : public QQuickItem
0023     {
0024         Q_OBJECT
0025 
0026         Q_PROPERTY( Marble::MarbleQuickItem* map READ map WRITE setMap NOTIFY mapChanged )
0027 
0028         Q_PROPERTY( qreal longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged )
0029         Q_PROPERTY( qreal latitude  READ latitude  WRITE setLatitude  NOTIFY latitudeChanged )
0030         Q_PROPERTY( qreal altitude  READ altitude  WRITE setAltitude  NOTIFY altitudeChanged )
0031         // Determines whether the item is on the visible side of the globe
0032         Q_PROPERTY( bool observable READ observable NOTIFY observableChanged )
0033         // We shadow QQuickItem's visible property in order to take the observable into account
0034         Q_PROPERTY( bool visible READ visObservable WRITE setVisObservable NOTIFY visObservableChanged )
0035 
0036         Q_PROPERTY( qreal x READ readonlyX NOTIFY readonlyXChanged )
0037         Q_PROPERTY( qreal y READ readonlyY NOTIFY readonlyYChanged )
0038 
0039     public:
0040         /** Constructor */
0041         explicit GeoItem( QQuickItem *parent = nullptr );
0042 
0043 
0044         Q_INVOKABLE bool moveToScreenCoordinates(qreal x, qreal y);
0045 
0046         /** Provides access to the longitude (degree) of the coordinate */
0047         qreal longitude() const;
0048 
0049         /** Change the longitude of the coordinate */
0050         void setLongitude( qreal lon );
0051 
0052         /** Provides access to the latitude (degree) of the coordinate */
0053         qreal latitude() const;
0054 
0055         /** Change the latitude of the coordinate */
0056         void setLatitude( qreal lat );
0057 
0058         /** Provides access to the altitude (meters) of the coordinate */
0059         qreal altitude() const;
0060 
0061         /** Change the altitude of the coordinate */
0062         void setAltitude( qreal alt );
0063 
0064         /** Return all coordinates at once */
0065         Marble::GeoDataCoordinates coordinates() const;
0066 
0067         /** Change all coordinates at once */
0068         void setCoordinates( const Marble::GeoDataCoordinates &coordinates );
0069 
0070         /** Query the Marble map backend that this item uses for screen position determination */
0071         MarbleQuickItem* map() const;
0072 
0073         /** Hook up the GeoItem with Marble's map backend */
0074         void setMap(MarbleQuickItem* map);
0075 
0076         /** Return whether the item is visible or hidden on the backside of the globe. */
0077         bool observable() const;
0078 
0079         /** "Shadowed" version for the visible property to take observable into account. */
0080         bool visObservable() const;
0081         /** "Shadowed" version for the visible() property to take observable into account. */
0082         void setVisObservable(bool visible);
0083 
0084         /** "Shadowed" version for the x property to disable writing to the property. */
0085         qreal readonlyX() const
0086         {
0087             return x();
0088         }
0089 
0090         /** "Shadowed" version for the y property to disable writing to the property. */
0091         qreal readonlyY() const
0092         {
0093             return y();
0094         }
0095 
0096     Q_SIGNALS:
0097         void longitudeChanged();
0098         void latitudeChanged();
0099         void altitudeChanged();
0100 
0101         void mapChanged(MarbleQuickItem* map);
0102 
0103         void observableChanged(bool observable);
0104 
0105         void visObservableChanged(bool visible);
0106 
0107         void readonlyXChanged(qreal x);
0108         void readonlyYChanged(qreal y);
0109 
0110     private:
0111         Marble::GeoDataCoordinates m_coordinate;
0112         MarbleQuickItem* m_map;
0113         bool m_observable;
0114         bool m_visible;
0115         qreal m_x;
0116         qreal m_y;
0117 
0118         void updateScreenPosition();
0119         void setMapToParentOnInit();
0120     };
0121 }
0122 
0123 #endif // MARBLE_DECLARATIVE_GEOITEM_H