23 #include <QtCore/QDataStream> 24 #include <QtCore/QSharedData> 28 class Geo::Private :
public QSharedData
32 : mLatitude( 91 ), mLongitude( 181 ),
33 mValidLatitude( false ), mValidLongitude( false )
37 Private(
const Private &other )
38 : QSharedData( other )
40 mLatitude = other.mLatitude;
41 mLongitude = other.mLongitude;
42 mValidLatitude = other.mValidLatitude;
43 mValidLongitude = other.mValidLongitude;
76 if ( latitude >= -90 && latitude <= 90 ) {
78 d->mValidLatitude =
true;
81 d->mValidLatitude =
false;
92 if ( longitude >= -180 && longitude <= 180 ) {
94 d->mValidLongitude =
true;
97 d->mValidLongitude =
false;
103 return d->mLongitude;
108 return d->mValidLatitude && d->mValidLongitude;
121 if ( other.d->mLatitude == d->mLatitude && other.d->mLongitude == d->mLongitude ) {
130 return !( *
this == other );
135 if (
this != &other ) {
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" );
156 QDataStream &KABC::operator<<( QDataStream &s,
const Geo &geo )
158 return s << geo.d->mLatitude << geo.d->mValidLatitude
159 << geo.d->mLongitude << geo.d->mValidLongitude;
162 QDataStream &KABC::operator>>( QDataStream &s,
Geo &geo )
164 s >> geo.d->mLatitude >> geo.d->mValidLatitude
165 >> geo.d->mLongitude >> geo.d->mValidLongitude;
void setLongitude(float longitude)
Sets the longitude.
void setLatitude(float latitude)
Sets the latitude.
bool isValid() const
Returns, whether this object contains a valid geographical position.
bool operator!=(const Geo &) const
Not-Equal operator.
bool operator==(const Geo &) const
Equality operator.
float latitude() const
Returns the latitude.
QString toString() const
Returns string representation of geographical position.
float longitude() const
Returns the longitude.
Geo()
Creates an invalid geographics position object.
~Geo()
Destroys the geographics position object.
Geo & operator=(const Geo &other)
Assignment operator.