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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_DECLARATIVE_COORDINATE_H
0007 #define MARBLE_DECLARATIVE_COORDINATE_H
0008 
0009 #include "GeoDataCoordinates.h"
0010 #include <QObject>
0011 #include <QtQml>
0012 
0013 /**
0014   * Represents a coordinate with the properties of a name and coordinates
0015   *
0016   * @todo: Introduce GeoDataCoordinates
0017   */
0018 class Coordinate : public QObject
0019 {
0020     Q_OBJECT
0021 
0022     Q_PROPERTY( qreal longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged )
0023     Q_PROPERTY( qreal latitude  READ latitude  WRITE setLatitude  NOTIFY latitudeChanged )
0024     Q_PROPERTY( qreal altitude  READ altitude  WRITE setAltitude  NOTIFY altitudeChanged )
0025 
0026     Q_PROPERTY( Notation defaultNotation READ defaultNotation WRITE setDefaultNotation NOTIFY defaultNotationChanged )
0027 
0028 public:
0029     enum Notation{
0030         Decimal, ///< "Decimal" notation (base-10)
0031         DMS,     ///< "Sexagesimal DMS" notation (base-60)
0032         DM,      ///< "Sexagesimal DM" notation (base-60)
0033         UTM,
0034         Astro    /// < "RA and DEC" notation (used for astronomical sky coordinates)
0035     };
0036     Q_ENUM(Notation)
0037 
0038     /** Constructor */
0039     explicit Coordinate( qreal lon = 0.0, qreal lat = 0.0, qreal altitude = 0.0, QObject *parent = nullptr );
0040     explicit Coordinate( const Marble::GeoDataCoordinates & coordinates );
0041 
0042     /** Provides access to the longitude (degree) of the coordinate */
0043     qreal longitude() const;
0044 
0045     /** Change the longitude of the coordinate */
0046     void setLongitude( qreal lon );
0047 
0048     /** Provides access to the latitude (degree) of the coordinate */
0049     qreal latitude() const;
0050 
0051     /** Change the latitude of the coordinate */
0052     void setLatitude( qreal lat );
0053 
0054     /** Provides access to the altitude (meters) of the coordinate */
0055     qreal altitude() const;
0056 
0057     /** Change the altitude of the coordinate */
0058     void setAltitude( qreal alt );
0059 
0060     /** Change the altitude of the coordinate */
0061     Marble::GeoDataCoordinates coordinates() const;
0062 
0063     /** Change all coordinates at once */
0064     void setCoordinates( const Marble::GeoDataCoordinates &coordinates );
0065 
0066     Q_INVOKABLE QString toGeoString( Coordinate::Notation notation = Coordinate::DMS, int precision = -1 ) const;
0067 
0068     /** Distance (in meter) to the given coordinate */
0069     Q_INVOKABLE qreal distance( qreal longitude, qreal latitude ) const;
0070 
0071     /** Bearing (in degree) to the given coordinate */
0072     Q_INVOKABLE qreal bearing( qreal longitude, qreal latitude ) const;
0073 
0074     bool operator == ( const Coordinate &other ) const;
0075 
0076     bool operator != ( const Coordinate &other ) const;
0077 
0078     Notation defaultNotation();
0079     void setDefaultNotation(Notation defaultNotation);
0080 
0081 Q_SIGNALS:
0082     void longitudeChanged();
0083     void latitudeChanged();
0084     void altitudeChanged();
0085 
0086     void defaultNotationChanged(Notation defaultNotation);
0087 
0088 private:
0089     Marble::GeoDataCoordinates m_coordinate;
0090     Notation m_defaultNotation;
0091 };
0092 
0093 QML_DECLARE_TYPE( Coordinate )
0094 
0095 #endif // MARBLE_DECLARATIVE_COORDINATE_H