*
* @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
/**
* @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
*/
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)