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( 91 ), mLongitude( 181 ), mValidLat( false ), mValidLong( false )
00029 {
00030 }
00031
00032 Geo::Geo(
float latitude,
float longitude )
00033 {
00034
setLatitude( latitude );
00035
setLongitude( longitude );
00036 }
00037
00038 void Geo::setLatitude(
float latitude )
00039 {
00040
if ( latitude >= -90 && latitude <= 90 ) {
00041 mLatitude = latitude;
00042 mValidLat =
true;
00043 }
else {
00044 mLatitude = 91;
00045 mValidLat =
false;
00046 }
00047 }
00048
00049 float Geo::latitude()
const
00050
{
00051
return mLatitude;
00052 }
00053
00054 void Geo::setLongitude(
float longitude)
00055 {
00056
if ( longitude >= -180 && longitude <= 180 ) {
00057 mLongitude = longitude;
00058 mValidLong =
true;
00059 }
else {
00060 mLongitude = 181;
00061 mValidLong =
false;
00062 }
00063 }
00064
00065 float Geo::longitude()
const
00066
{
00067
return mLongitude;
00068 }
00069
00070 bool Geo::isValid()
const
00071
{
00072
return mValidLat && mValidLong;
00073 }
00074
00075
bool Geo::operator==(
const Geo &g )
const
00076
{
00077
if ( !g.
isValid() && !
isValid() )
return true;
00078
if ( !g.
isValid() || !
isValid() )
return false;
00079
if ( g.
mLatitude == mLatitude && g.
mLongitude == mLongitude )
return true;
00080
return false;
00081 }
00082
00083
bool Geo::operator!=(
const Geo &g )
const
00084
{
00085
if ( !g.
isValid() && !
isValid() )
return false;
00086
if ( !g.
isValid() || !
isValid() )
return true;
00087
if ( g.
mLatitude == mLatitude && g.
mLongitude == mLongitude )
return false;
00088
return true;
00089 }
00090
00091 QString Geo::asString()
const
00092
{
00093
return "(" + QString::number(mLatitude) +
"," + QString::number(mLongitude) +
")";
00094 }
00095
00096
QDataStream &KABC::operator<<(
QDataStream &s,
const Geo &geo )
00097 {
00098
return s << (
float)geo.
mLatitude << (
float)geo.
mLongitude;
00099 }
00100
00101
QDataStream &KABC::operator>>(
QDataStream &s,
Geo &geo )
00102 {
00103 s >> geo.
mLatitude >> geo.
mLongitude;
00104
00105 geo.
mValidLat =
true;
00106 geo.
mValidLong =
true;
00107
00108
return s;
00109 }
This file is part of the documentation for kabc Library Version 3.4.0.