• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kabc

geo.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "geo.h"
00022 
00023 #include <QtCore/QDataStream>
00024 #include <QtCore/QSharedData>
00025 
00026 using namespace KABC;
00027 
00028 class Geo::Private : public QSharedData
00029 {
00030   public:
00031     Private()
00032       : mLatitude( 91 ), mLongitude( 181 ),
00033         mValidLatitude( false ), mValidLongitude( false )
00034     {
00035     }
00036 
00037     Private( const Private &other )
00038       : QSharedData( other )
00039     {
00040       mLatitude = other.mLatitude;
00041       mLongitude = other.mLongitude;
00042       mValid = other.mValid;
00043       mValidLatitude = other.mValidLatitude;
00044       mValidLongitude = other.mValidLongitude;
00045     }
00046 
00047     float mLatitude;
00048     float mLongitude;
00049 
00050     bool mValid;
00051     bool mValidLatitude;
00052     bool mValidLongitude;
00053 };
00054 
00055 Geo::Geo()
00056   : d( new Private )
00057 {
00058 }
00059 
00060 Geo::Geo( float latitude, float longitude )
00061   : d( new Private )
00062 {
00063   setLatitude( latitude );
00064   setLongitude( longitude );
00065 }
00066 
00067 Geo::Geo( const Geo &other )
00068   : d( other.d )
00069 {
00070 }
00071 
00072 Geo::~Geo()
00073 {
00074 }
00075 
00076 void Geo::setLatitude( float latitude )
00077 {
00078   if ( latitude >= -90 && latitude <= 90 ) {
00079     d->mLatitude = latitude;
00080     d->mValidLatitude = true;
00081   } else {
00082     d->mLatitude = 91;
00083     d->mValidLatitude = false;
00084   }
00085 }
00086 
00087 float Geo::latitude() const
00088 {
00089   return d->mLatitude;
00090 }
00091 
00092 void Geo::setLongitude( float longitude )
00093 {
00094   if ( longitude >= -180 && longitude <= 180 ) {
00095     d->mLongitude = longitude;
00096     d->mValidLongitude = true;
00097   } else {
00098     d->mLongitude = 181;
00099     d->mValidLongitude = false;
00100   }
00101 }
00102 
00103 float Geo::longitude() const
00104 {
00105   return d->mLongitude;
00106 }
00107 
00108 bool Geo::isValid() const
00109 {
00110   return d->mValidLatitude && d->mValidLongitude;
00111 }
00112 
00113 bool Geo::operator==( const Geo &other ) const
00114 {
00115   if ( !other.isValid() && !isValid() ) {
00116     return true;
00117   }
00118 
00119   if ( !other.isValid() || !isValid() ) {
00120     return false;
00121   }
00122 
00123   if ( other.d->mLatitude == d->mLatitude && other.d->mLongitude == d->mLongitude ) {
00124     return true;
00125   }
00126 
00127   return false;
00128 }
00129 
00130 bool Geo::operator!=( const Geo &other ) const
00131 {
00132   return !( *this == other );
00133 }
00134 
00135 Geo &Geo::operator=( const Geo &other )
00136 {
00137   if ( this != &other ) {
00138     d = other.d;
00139   }
00140 
00141   return *this;
00142 }
00143 
00144 QString Geo::toString() const
00145 {
00146   QString str;
00147 
00148   str += QString( "Geo {\n" );
00149   str += QString( "  Valid: %1\n" ).arg( isValid() ? "true" : "false" );
00150   str += QString( "  Latitude: %1\n" ).arg( d->mLatitude );
00151   str += QString( "  Longitude: %1\n" ).arg( d->mLongitude );
00152   str += QString( "}\n" );
00153 
00154   return str;
00155 }
00156 
00157 QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
00158 {
00159     return s << geo.d->mLatitude << geo.d->mValidLatitude
00160              << geo.d->mLongitude << geo.d->mValidLongitude;
00161 }
00162 
00163 QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
00164 {
00165     s >> geo.d->mLatitude >> geo.d->mValidLatitude
00166       >> geo.d->mLongitude >> geo.d->mValidLongitude;
00167 
00168     return s;
00169 }

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal