• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.1 API Reference
  • KDE Home
  • Contact Us
 

kabc

  • kabc
geo.cpp
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., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "geo.h"
22 
23 #include <QtCore/QDataStream>
24 #include <QtCore/QSharedData>
25 
26 using namespace KABC;
27 
28 class Geo::Private : public QSharedData
29 {
30  public:
31  Private()
32  : mLatitude( 91 ), mLongitude( 181 ),
33  mValidLatitude( false ), mValidLongitude( false )
34  {
35  }
36 
37  Private( const Private &other )
38  : QSharedData( other )
39  {
40  mLatitude = other.mLatitude;
41  mLongitude = other.mLongitude;
42  mValid = other.mValid;
43  mValidLatitude = other.mValidLatitude;
44  mValidLongitude = other.mValidLongitude;
45  }
46 
47  float mLatitude;
48  float mLongitude;
49 
50  bool mValid;
51  bool mValidLatitude;
52  bool mValidLongitude;
53 };
54 
55 Geo::Geo()
56  : d( new Private )
57 {
58 }
59 
60 Geo::Geo( float latitude, float longitude )
61  : d( new Private )
62 {
63  setLatitude( latitude );
64  setLongitude( longitude );
65 }
66 
67 Geo::Geo( const Geo &other )
68  : d( other.d )
69 {
70 }
71 
72 Geo::~Geo()
73 {
74 }
75 
76 void Geo::setLatitude( float latitude )
77 {
78  if ( latitude >= -90 && latitude <= 90 ) {
79  d->mLatitude = latitude;
80  d->mValidLatitude = true;
81  } else {
82  d->mLatitude = 91;
83  d->mValidLatitude = false;
84  }
85 }
86 
87 float Geo::latitude() const
88 {
89  return d->mLatitude;
90 }
91 
92 void Geo::setLongitude( float longitude )
93 {
94  if ( longitude >= -180 && longitude <= 180 ) {
95  d->mLongitude = longitude;
96  d->mValidLongitude = true;
97  } else {
98  d->mLongitude = 181;
99  d->mValidLongitude = false;
100  }
101 }
102 
103 float Geo::longitude() const
104 {
105  return d->mLongitude;
106 }
107 
108 bool Geo::isValid() const
109 {
110  return d->mValidLatitude && d->mValidLongitude;
111 }
112 
113 bool Geo::operator==( const Geo &other ) const
114 {
115  if ( !other.isValid() && !isValid() ) {
116  return true;
117  }
118 
119  if ( !other.isValid() || !isValid() ) {
120  return false;
121  }
122 
123  if ( other.d->mLatitude == d->mLatitude && other.d->mLongitude == d->mLongitude ) {
124  return true;
125  }
126 
127  return false;
128 }
129 
130 bool Geo::operator!=( const Geo &other ) const
131 {
132  return !( *this == other );
133 }
134 
135 Geo &Geo::operator=( const Geo &other )
136 {
137  if ( this != &other ) {
138  d = other.d;
139  }
140 
141  return *this;
142 }
143 
144 QString Geo::toString() const
145 {
146  QString str;
147 
148  str += QLatin1String( "Geo {\n" );
149  str += QString::fromLatin1( " Valid: %1\n" ).
150  arg( isValid() ? QLatin1String( "true" ) : QLatin1String( "false" ) );
151  str += QString::fromLatin1( " Latitude: %1\n" ).arg( d->mLatitude );
152  str += QString::fromLatin1( " Longitude: %1\n" ).arg( d->mLongitude );
153  str += QLatin1String( "}\n" );
154 
155  return str;
156 }
157 
158 QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
159 {
160  return s << geo.d->mLatitude << geo.d->mValidLatitude
161  << geo.d->mLongitude << geo.d->mValidLongitude;
162 }
163 
164 QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
165 {
166  s >> geo.d->mLatitude >> geo.d->mValidLatitude
167  >> geo.d->mLongitude >> geo.d->mValidLongitude;
168 
169  return s;
170 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:09:50 by doxygen 1.8.1.1 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.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 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