File indexing completed on 2024-10-27 06:45:33
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KCONTACTS_GEO_H 0009 #define KCONTACTS_GEO_H 0010 0011 #include "kcontacts_export.h" 0012 0013 #include <QMetaType> 0014 #include <QSharedDataPointer> 0015 #include <QString> 0016 0017 namespace KContacts 0018 { 0019 /** 0020 * @short Geographic position 0021 * 0022 * This class represents a geographic position. 0023 */ 0024 class KCONTACTS_EXPORT Geo 0025 { 0026 friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Geo &); 0027 friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Geo &); 0028 0029 Q_GADGET 0030 Q_PROPERTY(float latitude READ latitude WRITE setLatitude) 0031 Q_PROPERTY(float longitude READ longitude WRITE setLongitude) 0032 Q_PROPERTY(bool isValid READ isValid) 0033 0034 public: 0035 /** 0036 * Creates an invalid geographics position object. 0037 */ 0038 Geo(); 0039 0040 /** 0041 * Creates a geographics position object. 0042 * 0043 * @param latitude Geographical latitude 0044 * @param longitude Geographical longitude 0045 */ 0046 Geo(float latitude, float longitude); 0047 0048 /** 0049 * Copy constructor. 0050 */ 0051 Geo(const Geo &other); 0052 0053 /** 0054 * Destroys the geographics position object. 0055 */ 0056 ~Geo(); 0057 0058 /** 0059 * Sets the @p latitude. 0060 * 0061 * @param latitude The location's latitude coordinate 0062 */ 0063 void setLatitude(float latitude); 0064 0065 /** 0066 * Returns the latitude. 0067 */ 0068 Q_REQUIRED_RESULT float latitude() const; 0069 0070 /** 0071 * Sets the @p longitude. 0072 * 0073 * @param longitude The location's longitude coordinate 0074 */ 0075 void setLongitude(float longitude); 0076 0077 /** 0078 * Returns the longitude. 0079 */ 0080 Q_REQUIRED_RESULT float longitude() const; 0081 0082 /** 0083 * Returns, whether this object contains a valid geographical position. 0084 */ 0085 Q_REQUIRED_RESULT bool isValid() const; 0086 0087 /** 0088 * Equality operator. 0089 * 0090 * @note Two invalid Geo instance will return @c true 0091 */ 0092 Q_REQUIRED_RESULT bool operator==(const Geo &other) const; 0093 0094 /** 0095 * Not-Equal operator. 0096 */ 0097 bool operator!=(const Geo &other) const; 0098 0099 /** 0100 * Assignment operator. 0101 * 0102 * @param other The Geo instance to assign to @c this 0103 */ 0104 Geo &operator=(const Geo &other); 0105 0106 /** 0107 * Returns string representation of geographical position. 0108 */ 0109 Q_REQUIRED_RESULT QString toString() const; 0110 0111 /** 0112 * Clears the class, marking it as invalid. 0113 * 0114 * @since 5.6 0115 */ 0116 void clear(); 0117 0118 private: 0119 class Private; 0120 QSharedDataPointer<Private> d; 0121 }; 0122 0123 /** 0124 * Serializes the geographical position @p object into the @p stream. 0125 */ 0126 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Geo &object); 0127 0128 /** 0129 * Initializes the geographical position @p object from the @p stream. 0130 */ 0131 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Geo &object); 0132 } 0133 0134 Q_DECLARE_TYPEINFO(KContacts::Geo, Q_RELOCATABLE_TYPE); 0135 0136 #endif