Added coordinates to Messages, added Message type.
[situare] / src / coordinates / geocoordinate.h
index 6ac8d3f..ec5ed3a 100644 (file)
@@ -56,13 +56,25 @@ public:
     *
     * @param coordinate Scene coordinate
     */
-    GeoCoordinate(SceneCoordinate &coordinate);
+    GeoCoordinate(const SceneCoordinate &coordinate);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public:
     /**
+    * @brief Distance to other coordinate
+    *
+    * This calculation returns the great-circle distance between the two coordinates, with an
+    * assumption that the Earth is spherical. Calculation is done using haversine formula. Altitude
+    * is not used in the calculation.
+    *
+    * @param other Coordinate where the distance is calculated from this coordinate
+    * @returns Distance to other coordinate (in meters)
+    */
+    qreal distanceTo(const GeoCoordinate &other) const;
+
+    /**
     * @brief Check if coordinate is (0.0, 0.0)
     *
     * @returns True if both latitude and longitude are 0.0, otherwise false
@@ -72,11 +84,12 @@ public:
     /**
     * @brief Check if coordinate is valid.
     *
-    * Latitude must be -90..90 and longitude must be -180..180 for valid coordinate.
+    * Latitude and longitude values must be set, latitude must be -90..90 and longitude must
+    * be -180..180 for valid coordinate.
     *
     * @return true if coordinate is valid, false otherwise
     */
-    bool isValid();
+    bool isValid() const;
 
     /**
     * @brief Returns the latitude value
@@ -114,15 +127,64 @@ private:
      */
     void convertFrom(const SceneCoordinate &coordinate);
 
+    /**
+    * @brief Register meta type and stream operators for using the class with QVariant and QSetting
+    *
+    * Registering is done only once at the first time the GeoCoordinate object is constructed.
+    */
+    void registerMetaType();
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    double m_latitude;      ///< Latitude value
-    double m_longitude;     ///< Longitude value
+    /**
+    * @enum ValidityFlag
+    *
+    * @brief Flag values for coordinate validity
+    */
+    enum ValidityFlag {
+        NoCoordinatesSet = 0x0,
+        LatitudeSet = 0x1,
+        LongitudeSet = 0x2
+    };
+
+    static bool m_metaTypeIsRegistered;     ///< Is the meta type already registered?
+    double m_latitude;                      ///< Latitude value
+    double m_longitude;                     ///< Longitude value
+    int m_validityFlags;                    ///< Coordinate validity flags
+
+/*******************************************************************************
+ * OPERATORS
+ ******************************************************************************/
+public:
+    /**
+    * @brief Subtract operator
+    *
+    * @returns Returns a GeoCoordinate object that is formed by subtracting coordinate2 from
+    *          coordinate1. Each component is subtracted separately.
+    */
+    friend const GeoCoordinate operator-(const GeoCoordinate &coordinate1,
+                                         const GeoCoordinate &coordinate2);
+
+    /**
+    * @brief Output operator
+    *
+    * @param out Output stream
+    * @param coordinate Coordinate object which is written to the stream
+    */
+    friend QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate);
+
+    /**
+    * @brief Input operator
+    *
+    * @param in Input stream
+    * @param coordinate Object where the values from the stream are saved
+    */
+    friend QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate);
 };
 
-QDebug operator<<(QDebug dbg, const GeoCoordinate &c);
+QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate);
 
 Q_DECLARE_METATYPE(GeoCoordinate)