Re-factored the source to use the new coordinate classes
[situare] / src / coordinates / geocoordinate.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Jussi Laitinen - jussi.laitinen@ixonos.com
6         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23
24 #ifndef GEOCOORDINATE_H
25 #define GEOCOORDINATE_H
26
27 #include <QDebug>
28 #include <QMetaType>
29
30 class SceneCoordinate;
31
32 /**
33 * @brief Geographic coordinate
34 *
35 * @author Jussi Laitinen - jussi.laitinen@ixonos.com
36 * @author Sami Rämö - sami.ramo@ixonos.com
37 */
38 class GeoCoordinate
39 {
40 public:
41     /**
42     * @brief Constructs a null coordinate
43     */
44     GeoCoordinate();
45
46     /**
47     * @brief Constructs a coordinate with given latitude and longitude values
48     *
49     * @param latitude Latitude value
50     * @param longitude Longitude value
51     */
52     GeoCoordinate(double latitude, double longitude);
53
54     /**
55     * @brief Constructs a coordinate with values converted from the given SceneCoordinate
56     *
57     * @param coordinate Scene coordinate
58     */
59     GeoCoordinate(const SceneCoordinate &coordinate);
60
61 /*******************************************************************************
62  * MEMBER FUNCTIONS AND SLOTS
63  ******************************************************************************/
64 public:
65     /**
66     * @brief Check if coordinate is (0.0, 0.0)
67     *
68     * @returns True if both latitude and longitude are 0.0, otherwise false
69     */
70     bool isNull() const;
71
72     /**
73     * @brief Check if coordinate is valid.
74     *
75     * Latitude must be -90..90 and longitude must be -180..180 for valid coordinate.
76     *
77     * @return true if coordinate is valid, false otherwise
78     */
79     bool isValid();
80
81     /**
82     * @brief Returns the latitude value
83     *
84     * @returns latitude
85     */
86     double latitude() const;
87
88     /**
89     * @brief Returns the longitude value
90     *
91     * @returns longitude
92     */
93     double longitude() const;
94
95     /**
96     * @brief Sets the latitude
97     *
98     * @param latitude Latitude value
99     */
100     void setLatitude(double latitude);
101
102     /**
103     * @brief Sets the longitude
104     *
105     * @param longitude Longitude value
106     */
107     void setLongitude(double longitude);
108
109 private:
110     /**
111      * @brief Convert values from SceneCoordinate
112      *
113      * @param coordinate Scene coordinate
114      */
115     void convertFrom(const SceneCoordinate &coordinate);
116
117 /*******************************************************************************
118  * DATA MEMBERS
119  ******************************************************************************/
120 private:
121     double m_latitude;      ///< Latitude value
122     double m_longitude;     ///< Longitude value
123
124 /*******************************************************************************
125  * OPERATORS
126  ******************************************************************************/
127 public:
128     friend QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate);
129     friend QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate);
130 };
131
132 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate);
133
134 Q_DECLARE_METATYPE(GeoCoordinate)
135
136 #endif // GEOCOORDINATE_H