• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • 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 += QLatin1String( "Geo {\n" );
00149   str += QString::fromLatin1( "  Valid: %1\n" ).
00150          arg( isValid() ? QLatin1String( "true" ) : QLatin1String( "false" ) );
00151   str += QString::fromLatin1( "  Latitude: %1\n" ).arg( d->mLatitude );
00152   str += QString::fromLatin1( "  Longitude: %1\n" ).arg( d->mLongitude );
00153   str += QLatin1String( "}\n" );
00154 
00155   return str;
00156 }
00157 
00158 QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
00159 {
00160     return s << geo.d->mLatitude << geo.d->mValidLatitude
00161              << geo.d->mLongitude << geo.d->mValidLongitude;
00162 }
00163 
00164 QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
00165 {
00166     s >> geo.d->mLatitude >> geo.d->mValidLatitude
00167       >> geo.d->mLongitude >> geo.d->mValidLongitude;
00168 
00169     return s;
00170 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:09:41 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

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

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal