author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/geo.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | kabc/geo.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/kabc/geo.cpp b/kabc/geo.cpp new file mode 100644 index 0000000..33597b7 --- a/dev/null +++ b/kabc/geo.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <qdatastream.h> | ||
29 | |||
30 | #include "geo.h" | ||
31 | |||
32 | using namespace KABC; | ||
33 | |||
34 | Geo::Geo() | ||
35 | : mLatitude( 91 ), mLongitude( 181 ), mValidLat( false ), mValidLong( false ) | ||
36 | { | ||
37 | } | ||
38 | |||
39 | Geo::Geo( float latitude, float longitude ) | ||
40 | { | ||
41 | setLatitude( latitude ); | ||
42 | setLongitude( longitude ); | ||
43 | } | ||
44 | |||
45 | void Geo::setLatitude( float latitude ) | ||
46 | { | ||
47 | if ( latitude >= -90 && latitude <= 90 ) { | ||
48 | mLatitude = latitude; | ||
49 | mValidLat = true; | ||
50 | } else { | ||
51 | mLatitude = 91; | ||
52 | mValidLat = false; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | float Geo::latitude() const | ||
57 | { | ||
58 | return mLatitude; | ||
59 | } | ||
60 | |||
61 | void Geo::setLongitude( float longitude) | ||
62 | { | ||
63 | if ( longitude >= -180 && longitude <= 180 ) { | ||
64 | mLongitude = longitude; | ||
65 | mValidLong = true; | ||
66 | } else { | ||
67 | mLongitude = 181; | ||
68 | mValidLong = false; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | float Geo::longitude() const | ||
73 | { | ||
74 | return mLongitude; | ||
75 | } | ||
76 | |||
77 | bool Geo::isValid() const | ||
78 | { | ||
79 | return mValidLat && mValidLong; | ||
80 | } | ||
81 | |||
82 | bool Geo::operator==( const Geo &g ) const | ||
83 | { | ||
84 | if ( !g.isValid() && !isValid() ) return true; | ||
85 | if ( !g.isValid() || !isValid() ) return false; | ||
86 | if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return true; | ||
87 | return false; | ||
88 | } | ||
89 | |||
90 | bool Geo::operator!=( const Geo &g ) const | ||
91 | { | ||
92 | if ( !g.isValid() && !isValid() ) return false; | ||
93 | if ( !g.isValid() || !isValid() ) return true; | ||
94 | if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return false; | ||
95 | return true; | ||
96 | } | ||
97 | |||
98 | QString Geo::asString() const | ||
99 | { | ||
100 | return "(" + QString::number(mLatitude) + "," + QString::number(mLongitude) + ")"; | ||
101 | } | ||
102 | |||
103 | QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo ) | ||
104 | { | ||
105 | return s << (float)geo.mLatitude << (float)geo.mLongitude; | ||
106 | } | ||
107 | |||
108 | QDataStream &KABC::operator>>( QDataStream &s, Geo &geo ) | ||
109 | { | ||
110 | s >> geo.mLatitude >> geo.mLongitude; | ||
111 | |||
112 | geo.mValidLat = true; | ||
113 | geo.mValidLong = true; | ||
114 | |||
115 | return s; | ||
116 | } | ||