geo.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdatastream.h>
00022
00023 #include "geo.h"
00024
00025 using namespace KABC;
00026
00027 Geo::Geo() :
00028 mLatitude( 0 ), mLongitude( 0 ), mValidLat( false ), mValidLong( false )
00029 {
00030 }
00031
00032 Geo::Geo( float latitude, float longitude ) :
00033 mLatitude( latitude ), mLongitude( longitude ),
00034 mValidLat( true ), mValidLong( true )
00035 {
00036 }
00037
00038 void Geo::setLatitude( float latitude )
00039 {
00040 mLatitude = latitude;
00041 mValidLat = true;
00042 }
00043
00044 float Geo::latitude() const
00045 {
00046 return mLatitude;
00047 }
00048
00049 void Geo::setLongitude( float longitude)
00050 {
00051 mLongitude = longitude;
00052 mValidLong = true;
00053 }
00054
00055 float Geo::longitude() const
00056 {
00057 return mLongitude;
00058 }
00059
00060 bool Geo::isValid() const
00061 {
00062 return mValidLat && mValidLong;
00063 }
00064
00065 bool Geo::operator==( const Geo &g ) const
00066 {
00067 if ( !g.isValid() && !isValid() ) return true;
00068 if ( !g.isValid() || !isValid() ) return false;
00069 if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return true;
00070 return false;
00071 }
00072
00073 bool Geo::operator!=( const Geo &g ) const
00074 {
00075 if ( !g.isValid() && !isValid() ) return false;
00076 if ( !g.isValid() || !isValid() ) return true;
00077 if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return false;
00078 return true;
00079 }
00080
00081 QString Geo::asString() const
00082 {
00083 return "(" + QString::number(mLatitude) + "," + QString::number(mLongitude) + ")";
00084 }
00085
00086 QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
00087 {
00088 return s << (float)geo.mLatitude << (float)geo.mLongitude;
00089 }
00090
00091 QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
00092 {
00093 s >> geo.mLatitude >> geo.mLongitude;
00094
00095 geo.mValidLat = true;
00096 geo.mValidLong = true;
00097
00098 return s;
00099 }
This file is part of the documentation for kdelibs Version 3.1.5.