Added missing comments
[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 and longitude values must be set, latitude must be -90..90 and longitude must
76     * be -180..180 for valid coordinate.
77     *
78     * @return true if coordinate is valid, false otherwise
79     */
80     bool isValid();
81
82     /**
83     * @brief Returns the latitude value
84     *
85     * @returns latitude
86     */
87     double latitude() const;
88
89     /**
90     * @brief Returns the longitude value
91     *
92     * @returns longitude
93     */
94     double longitude() const;
95
96     /**
97     * @brief Sets the latitude
98     *
99     * @param latitude Latitude value
100     */
101     void setLatitude(double latitude);
102
103     /**
104     * @brief Sets the longitude
105     *
106     * @param longitude Longitude value
107     */
108     void setLongitude(double longitude);
109
110 private:
111     /**
112      * @brief Convert values from SceneCoordinate
113      *
114      * @param coordinate Scene coordinate
115      */
116     void convertFrom(const SceneCoordinate &coordinate);
117
118     /**
119     * @brief Register meta type and stream operators for using the class with QVariant and QSetting
120     *
121     * Registering is done only once at the first time the GeoCoordinate object is constructed.
122     */
123     void registerMetaType();
124
125 /*******************************************************************************
126  * DATA MEMBERS
127  ******************************************************************************/
128 private:
129     /**
130     * @enum ValidityFlag
131     *
132     * @brief Flag values for coordinate validity
133     */
134     enum ValidityFlag {
135         NoCoordinatesSet = 0x0,
136         LatitudeSet = 0x1,
137         LongitudeSet = 0x2
138     };
139
140     static bool m_metaTypeIsRegistered;     ///< Is the meta type already registered?
141     double m_latitude;                      ///< Latitude value
142     double m_longitude;                     ///< Longitude value
143     int m_validityFlags;                    ///< Coordinate validity flags
144
145 /*******************************************************************************
146  * OPERATORS
147  ******************************************************************************/
148 public:
149     /**
150     * @brief Output operator
151     *
152     * @param out Output stream
153     * @param coordinate Coordinate object which is written to the stream
154     */
155     friend QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate);
156
157     /**
158     * @brief Input operator
159     *
160     * @param in Input stream
161     * @param coordinate Object where the values from the stream are saved
162     */
163     friend QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate);
164 };
165
166 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate);
167
168 Q_DECLARE_METATYPE(GeoCoordinate)
169
170 #endif // GEOCOORDINATE_H