• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
26using namespace KABC;
27
28class 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 mValidLatitude = other.mValidLatitude;
43 mValidLongitude = other.mValidLongitude;
44 }
45
46 float mLatitude;
47 float mLongitude;
48
49 bool mValidLatitude;
50 bool mValidLongitude;
51};
52
53Geo::Geo()
54 : d( new Private )
55{
56}
57
58Geo::Geo( float latitude, float longitude )
59 : d( new Private )
60{
61 setLatitude( latitude );
62 setLongitude( longitude );
63}
64
65Geo::Geo( const Geo &other )
66 : d( other.d )
67{
68}
69
70Geo::~Geo()
71{
72}
73
74void Geo::setLatitude( float latitude )
75{
76 if ( latitude >= -90 && latitude <= 90 ) {
77 d->mLatitude = latitude;
78 d->mValidLatitude = true;
79 } else {
80 d->mLatitude = 91;
81 d->mValidLatitude = false;
82 }
83}
84
85float Geo::latitude() const
86{
87 return d->mLatitude;
88}
89
90void Geo::setLongitude( float longitude )
91{
92 if ( longitude >= -180 && longitude <= 180 ) {
93 d->mLongitude = longitude;
94 d->mValidLongitude = true;
95 } else {
96 d->mLongitude = 181;
97 d->mValidLongitude = false;
98 }
99}
100
101float Geo::longitude() const
102{
103 return d->mLongitude;
104}
105
106bool Geo::isValid() const
107{
108 return d->mValidLatitude && d->mValidLongitude;
109}
110
111bool Geo::operator==( const Geo &other ) const
112{
113 if ( !other.isValid() && !isValid() ) {
114 return true;
115 }
116
117 if ( !other.isValid() || !isValid() ) {
118 return false;
119 }
120
121 if ( other.d->mLatitude == d->mLatitude && other.d->mLongitude == d->mLongitude ) {
122 return true;
123 }
124
125 return false;
126}
127
128bool Geo::operator!=( const Geo &other ) const
129{
130 return !( *this == other );
131}
132
133Geo &Geo::operator=( const Geo &other )
134{
135 if ( this != &other ) {
136 d = other.d;
137 }
138
139 return *this;
140}
141
142QString Geo::toString() const
143{
144 QString str;
145
146 str += QLatin1String( "Geo {\n" );
147 str += QString::fromLatin1( " Valid: %1\n" ).
148 arg( isValid() ? QLatin1String( "true" ) : QLatin1String( "false" ) );
149 str += QString::fromLatin1( " Latitude: %1\n" ).arg( d->mLatitude );
150 str += QString::fromLatin1( " Longitude: %1\n" ).arg( d->mLongitude );
151 str += QLatin1String( "}\n" );
152
153 return str;
154}
155
156QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
157{
158 return s << geo.d->mLatitude << geo.d->mValidLatitude
159 << geo.d->mLongitude << geo.d->mValidLongitude;
160}
161
162QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
163{
164 s >> geo.d->mLatitude >> geo.d->mValidLatitude
165 >> geo.d->mLongitude >> geo.d->mValidLongitude;
166
167 return s;
168}
KABC::Geo
Geographic position.
Definition: geo.h:36
KABC::Geo::~Geo
~Geo()
Destroys the geographics position object.
Definition: geo.cpp:70
KABC::Geo::operator!=
bool operator!=(const Geo &) const
Not-Equal operator.
Definition: geo.cpp:128
KABC::Geo::Geo
Geo()
Creates an invalid geographics position object.
Definition: geo.cpp:53
KABC::Geo::isValid
bool isValid() const
Returns, whether this object contains a valid geographical position.
Definition: geo.cpp:106
KABC::Geo::setLatitude
void setLatitude(float latitude)
Sets the latitude.
Definition: geo.cpp:74
KABC::Geo::operator=
Geo & operator=(const Geo &other)
Assignment operator.
Definition: geo.cpp:133
KABC::Geo::longitude
float longitude() const
Returns the longitude.
Definition: geo.cpp:101
KABC::Geo::latitude
float latitude() const
Returns the latitude.
Definition: geo.cpp:85
KABC::Geo::toString
QString toString() const
Returns string representation of geographical position.
Definition: geo.cpp:142
KABC::Geo::setLongitude
void setLongitude(float longitude)
Sets the longitude.
Definition: geo.cpp:90
KABC::Geo::operator==
bool operator==(const Geo &) const
Equality operator.
Definition: geo.cpp:111
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition: address.h:29
KABC::operator<<
QDataStream & operator<<(QDataStream &stream, const Address &address)
Serializes the address object into the stream.
Definition: address.cpp:680
KABC::operator>>
QDataStream & operator>>(QDataStream &stream, Address &address)
Initializes the address object from the stream.
Definition: address.cpp:688
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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