qtmobility/src/location/qgeopositioninfo.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    47 QTM_BEGIN_NAMESPACE
    47 QTM_BEGIN_NAMESPACE
    48 
    48 
    49 class QGeoPositionInfoPrivate
    49 class QGeoPositionInfoPrivate
    50 {
    50 {
    51 public:
    51 public:
    52     QDateTime dateTime;
    52     QDateTime timestamp;
    53     QGeoCoordinate coord;
    53     QGeoCoordinate coord;
    54     QHash<int, qreal> doubleAttribs;
    54     QHash<int, qreal> doubleAttribs;
    55 };
    55 };
    56 
    56 
    57 /*!
    57 /*!
    87         : d(new QGeoPositionInfoPrivate)
    87         : d(new QGeoPositionInfoPrivate)
    88 {
    88 {
    89 }
    89 }
    90 
    90 
    91 /*!
    91 /*!
    92     Creates a QGeoPositionInfo for the given \a coordinate and \a dateTime.
    92     Creates a QGeoPositionInfo for the given \a coordinate and \a timestamp.
    93 */
    93 */
    94 QGeoPositionInfo::QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime &dateTime)
    94 QGeoPositionInfo::QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime &timestamp)
    95         : d(new QGeoPositionInfoPrivate)
    95         : d(new QGeoPositionInfoPrivate)
    96 {
    96 {
    97     d->dateTime = dateTime;
    97     d->timestamp = timestamp;
    98     d->coord = coordinate;
    98     d->coord = coordinate;
    99 }
    99 }
   100 
   100 
   101 /*!
   101 /*!
   102     Creates a QGeoPositionInfo with the values of \a other.
   102     Creates a QGeoPositionInfo with the values of \a other.
   121 QGeoPositionInfo &QGeoPositionInfo::operator=(const QGeoPositionInfo & other)
   121 QGeoPositionInfo &QGeoPositionInfo::operator=(const QGeoPositionInfo & other)
   122 {
   122 {
   123     if (this == &other)
   123     if (this == &other)
   124         return *this;
   124         return *this;
   125 
   125 
   126     d->dateTime = other.d->dateTime;
   126     d->timestamp = other.d->timestamp;
   127     d->coord = other.d->coord;
   127     d->coord = other.d->coord;
   128     d->doubleAttribs = other.d->doubleAttribs;
   128     d->doubleAttribs = other.d->doubleAttribs;
   129 
   129 
   130     return *this;
   130     return *this;
   131 }
   131 }
   134     Returns true if all of this object's values are the same as those of
   134     Returns true if all of this object's values are the same as those of
   135     \a other.
   135     \a other.
   136 */
   136 */
   137 bool QGeoPositionInfo::operator==(const QGeoPositionInfo &other) const
   137 bool QGeoPositionInfo::operator==(const QGeoPositionInfo &other) const
   138 {
   138 {
   139     return d->dateTime == other.d->dateTime
   139     return d->timestamp == other.d->timestamp
   140            && d->coord == other.d->coord
   140            && d->coord == other.d->coord
   141            && d->doubleAttribs == other.d->doubleAttribs;
   141            && d->doubleAttribs == other.d->doubleAttribs;
   142 }
   142 }
   143 
   143 
   144 /*!
   144 /*!
   147     Returns true if any of this object's values are not the same as those of
   147     Returns true if any of this object's values are not the same as those of
   148     \a other.
   148     \a other.
   149 */
   149 */
   150 
   150 
   151 /*!
   151 /*!
   152     Returns true if the dateTime() and coordinate() values are both valid.
   152     Returns true if the timestamp() and coordinate() values are both valid.
   153 
   153 
   154     \sa QGeoCoordinate::isValid(), QDateTime::isValid()
   154     \sa QGeoCoordinate::isValid(), QDateTime::isValid()
   155 */
   155 */
   156 bool QGeoPositionInfo::isValid() const
   156 bool QGeoPositionInfo::isValid() const
   157 {
   157 {
   158     return d->dateTime.isValid() && d->coord.isValid();
   158     return d->timestamp.isValid() && d->coord.isValid();
   159 }
   159 }
   160 
   160 
   161 /*!
   161 /*!
   162     Sets the date and time at which this position was reported to \a dateTime.
   162     Sets the date and time at which this position was reported to \a timestamp.
   163 
   163 
   164     The \a dateTime must be in UTC time.
   164     The \a timestamp must be in UTC time.
   165 
   165 
   166     \sa dateTime()
   166     \sa timestamp()
   167 */
   167 */
   168 void QGeoPositionInfo::setDateTime(const QDateTime &dateTime)
   168 void QGeoPositionInfo::setTimestamp(const QDateTime &timestamp)
   169 {
   169 {
   170     d->dateTime = dateTime;
   170     d->timestamp = timestamp;
   171 }
   171 }
   172 
   172 
   173 /*!
   173 /*!
   174     Returns the date and time at which this position was reported, in UTC time.
   174     Returns the date and time at which this position was reported, in UTC time.
   175 
   175 
   176     Returns an invalid QDateTime if no date/time value has been set.
   176     Returns an invalid QDateTime if no date/time value has been set.
   177 
   177 
   178     \sa setDateTime()
   178     \sa setTimestamp()
   179 */
   179 */
   180 QDateTime QGeoPositionInfo::dateTime() const
   180 QDateTime QGeoPositionInfo::timestamp() const
   181 {
   181 {
   182     return d->dateTime;
   182     return d->timestamp;
   183 }
   183 }
   184 
   184 
   185 /*!
   185 /*!
   186     Sets the coordinate for this position to \a coordinate.
   186     Sets the coordinate for this position to \a coordinate.
   187 
   187 
   215 }
   215 }
   216 
   216 
   217 /*!
   217 /*!
   218     Returns the value of the specified \a attribute as a qreal value.
   218     Returns the value of the specified \a attribute as a qreal value.
   219 
   219 
   220     Returns -1 if the value has not been set.
   220     Returns -1 if the value has not been set, although this may also
       
   221     be a legitimate value for some attributes.
       
   222     
       
   223     The function hasAttribute() should be used to determine whether or 
       
   224     not a value has been set for an attribute.
   221 
   225 
   222     \sa hasAttribute(), setAttribute()
   226     \sa hasAttribute(), setAttribute()
   223 */
   227 */
   224 qreal QGeoPositionInfo::attribute(Attribute attribute) const
   228 qreal QGeoPositionInfo::attribute(Attribute attribute) const
   225 {
   229 {
   244 {
   248 {
   245     return d->doubleAttribs.contains(int(attribute));
   249     return d->doubleAttribs.contains(int(attribute));
   246 }
   250 }
   247 
   251 
   248 #ifndef QT_NO_DEBUG_STREAM
   252 #ifndef QT_NO_DEBUG_STREAM
   249 QDebug operator<<(QDebug dbg, const QGeoPositionInfo &update)
   253 QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info)
   250 {
   254 {
   251     dbg.nospace() << "QGeoPositionInfo(" << update.d->dateTime;
   255     dbg.nospace() << "QGeoPositionInfo(" << info.d->timestamp;
   252     dbg.nospace() << ", ";
   256     dbg.nospace() << ", ";
   253     dbg.nospace() << update.d->coord;
   257     dbg.nospace() << info.d->coord;
   254 
   258 
   255     QList<int> attribs = update.d->doubleAttribs.keys();
   259     QList<int> attribs = info.d->doubleAttribs.keys();
   256     for (int i = 0; i < attribs.count(); i++) {
   260     for (int i = 0; i < attribs.count(); i++) {
   257         dbg.nospace() << ", ";
   261         dbg.nospace() << ", ";
   258         switch (attribs[i]) {
   262         switch (attribs[i]) {
   259             case QGeoPositionInfo::Direction:
   263             case QGeoPositionInfo::Direction:
   260                 dbg.nospace() << "Direction=";
   264                 dbg.nospace() << "Direction=";
   273                 break;
   277                 break;
   274             case QGeoPositionInfo::VerticalAccuracy:
   278             case QGeoPositionInfo::VerticalAccuracy:
   275                 dbg.nospace() << "VerticalAccuracy=";
   279                 dbg.nospace() << "VerticalAccuracy=";
   276                 break;
   280                 break;
   277         }
   281         }
   278         dbg.nospace() << update.d->doubleAttribs[attribs[i]];
   282         dbg.nospace() << info.d->doubleAttribs[attribs[i]];
   279     }
   283     }
   280     dbg.nospace() << ')';
   284     dbg.nospace() << ')';
   281     return dbg;
   285     return dbg;
   282 }
   286 }
   283 #endif
   287 #endif
   292     \sa {Format of the QDataStream Operators}
   296     \sa {Format of the QDataStream Operators}
   293 */
   297 */
   294 
   298 
   295 QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info)
   299 QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info)
   296 {
   300 {
   297     stream << info.d->dateTime;
   301     stream << info.d->timestamp;
   298     stream << info.d->coord;
   302     stream << info.d->coord;
   299     stream << info.d->doubleAttribs;
   303     stream << info.d->doubleAttribs;
   300     return stream;
   304     return stream;
   301 }
   305 }
   302 #endif
   306 #endif
   312     \sa {Format of the QDataStream Operators}
   316     \sa {Format of the QDataStream Operators}
   313 */
   317 */
   314 
   318 
   315 QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info)
   319 QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info)
   316 {
   320 {
   317     stream >> info.d->dateTime;
   321     stream >> info.d->timestamp;
   318     stream >> info.d->coord;
   322     stream >> info.d->coord;
   319     stream >> info.d->doubleAttribs;
   323     stream >> info.d->doubleAttribs;
   320     return stream;
   324     return stream;
   321 }
   325 }
   322 #endif
   326 #endif