summaryrefslogtreecommitdiffabout
path: root/kabc/geo.cpp
Unidiff
Diffstat (limited to 'kabc/geo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/geo.cpp116
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/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qdatastream.h>
29
30#include "geo.h"
31
32using namespace KABC;
33
34Geo::Geo()
35 : mLatitude( 91 ), mLongitude( 181 ), mValidLat( false ), mValidLong( false )
36{
37}
38
39Geo::Geo( float latitude, float longitude )
40{
41 setLatitude( latitude );
42 setLongitude( longitude );
43}
44
45void 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
56float Geo::latitude() const
57{
58 return mLatitude;
59}
60
61void 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
72float Geo::longitude() const
73{
74 return mLongitude;
75}
76
77bool Geo::isValid() const
78{
79 return mValidLat && mValidLong;
80}
81
82bool 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
90bool 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
98QString Geo::asString() const
99{
100 return "(" + QString::number(mLatitude) + "," + QString::number(mLongitude) + ")";
101}
102
103QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
104{
105 return s << (float)geo.mLatitude << (float)geo.mLongitude;
106}
107
108QDataStream &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}