File indexing completed on 2025-01-05 03:59:01
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Guillaume Martres <smarter@ubuntu.com> 0004 // 0005 0006 #ifndef MARBLE_GEODATATRACK_H 0007 #define MARBLE_GEODATATRACK_H 0008 0009 #include "GeoDataGeometry.h" 0010 0011 #include <QList> 0012 0013 class QDateTime; 0014 0015 namespace Marble { 0016 0017 class GeoDataTrackPrivate; 0018 class GeoDataExtendedData; 0019 class GeoDataLineString; 0020 class GeoDataCoordinates; 0021 0022 /** 0023 * @class GeoDataTrack 0024 * @brief A geometry for tracking objects made of (time, coordinates) pairs 0025 * 0026 * GeoDataTrack implements the Track tag defined in Google's extension of the 0027 * Open Geospatial Consortium standard KML 2.2 at 0028 * https://developers.google.com/kml/documentation/kmlreference#gxtrack . 0029 * 0030 * A track is made of points, each point has a coordinates and a time value 0031 * associated with the coordinates. New points can be added using the addPoint() 0032 * method. The coordinates of the tracked object at a particular time can be 0033 * found using coordinatesAt(), you can specify if interpolation should be used 0034 * using the setInterpolate() function. 0035 * 0036 * By default, a LineString that passes through every coordinates in the track 0037 * is drawn. You can customize it by changing the GeoDataLineStyle, for example 0038 * if the GeoDataTrack is the geometry of feature, you can disable the line drawing with: 0039 * @code 0040 * feature->style()->lineStyle().setPenStyle( Qt::NoPen ); 0041 * @endcode 0042 * 0043 * For convenience, the methods appendCoordinates() and appendWhen() are provided. 0044 * They let you add points by specifying their coordinates and time value separately. 0045 * When N calls to one of these methods are followed by N calls to the other, 0046 * the first coordinates will be matched with the first time value, the second 0047 * coordinates with the second time value, etc. This follows the way "coord" 0048 * and "when" tags inside the Track tag should be parsed. 0049 */ 0050 class DIGIKAM_EXPORT GeoDataTrack : public GeoDataGeometry 0051 { 0052 0053 public: 0054 GeoDataTrack(); 0055 explicit GeoDataTrack( const GeoDataTrack &other ); 0056 0057 GeoDataTrack &operator=( const GeoDataTrack &other ); 0058 0059 const char *nodeType() const override; 0060 0061 EnumGeometryId geometryId() const override; 0062 0063 GeoDataGeometry *copy() const override; 0064 0065 /** 0066 * Returns the number of points in the track 0067 */ 0068 int size() const; 0069 0070 /** 0071 * @brief: Equality operators. 0072 */ 0073 bool operator==( const GeoDataTrack& other ) const; 0074 bool operator!=( const GeoDataTrack& other ) const; 0075 0076 /** 0077 * Returns true if coordinatesAt() should use interpolation, false otherwise. 0078 * The default is false. 0079 * 0080 * @see setInterpolate, coordinatesAt 0081 */ 0082 bool interpolate() const; 0083 0084 /** 0085 * Set whether coordinatesAt() should use interpolation. 0086 * 0087 * @see interpolate, coordinatesAt 0088 */ 0089 void setInterpolate(bool on); 0090 0091 /** 0092 * Return the time value of the first point in the track, or 0093 * an invalid QDateTime if the track is empty. 0094 */ 0095 QDateTime firstWhen() const; 0096 0097 /** 0098 * Return the time value of the last point in the track, or 0099 * an invalid QDateTime if the track is empty. 0100 */ 0101 QDateTime lastWhen() const; 0102 0103 /** 0104 * Returns the coordinates of all the points in the map, sorted by their 0105 * time value 0106 */ 0107 QVector<GeoDataCoordinates> coordinatesList() const; 0108 0109 /** 0110 * Returns the time value of all the points in the map, in chronological 0111 * order. 0112 * @since 0.26.0 0113 */ 0114 QVector<QDateTime> whenList() const; 0115 0116 /** 0117 * If interpolate() is true, return the coordinates interpolated from the 0118 * time values before and after @p when, otherwise return the coordinates 0119 * of the point with the closest time value less than or equal to @p when. 0120 * 0121 * @see interpolate 0122 */ 0123 GeoDataCoordinates coordinatesAt( const QDateTime &when ) const; 0124 0125 /** 0126 * Return coordinates at specified index. This is useful when the track contains 0127 * coordinates without time information. 0128 */ 0129 GeoDataCoordinates coordinatesAt( int index ) const; 0130 0131 /** 0132 * Add a new point with coordinates @p coord associated with the 0133 * time value @p when 0134 */ 0135 void addPoint( const QDateTime &when, const GeoDataCoordinates &coord ); 0136 0137 /** 0138 * Add the coordinates part for a new point. See this class description 0139 * for more information. 0140 * @see appendWhen 0141 */ 0142 void appendCoordinates( const GeoDataCoordinates &coord ); 0143 0144 /** 0145 * Add altitude information to the last appended coordinates 0146 */ 0147 void appendAltitude( qreal altitude ); 0148 0149 /** 0150 * Add the time value part for a new point. See this class description 0151 * for more information. 0152 * @see appendCoordinates 0153 */ 0154 void appendWhen( const QDateTime &when ); 0155 0156 /** 0157 * Remove all the points contained in the track. 0158 */ 0159 void clear(); 0160 0161 /** 0162 * Remove all points from the track whose time value is less than @p when. 0163 */ 0164 void removeBefore( const QDateTime &when ); 0165 0166 /** 0167 * Remove all points from the track whose time value is greater than @p when. 0168 */ 0169 void removeAfter( const QDateTime &when ); 0170 0171 /** 0172 * Return the GeoDataLineString representing the current track 0173 */ 0174 const GeoDataLineString *lineString() const; 0175 0176 /** 0177 * Return the ExtendedData assigned to the feature. 0178 */ 0179 const GeoDataExtendedData& extendedData() const; 0180 GeoDataExtendedData& extendedData(); 0181 0182 /** 0183 * Sets the ExtendedData of the feature. 0184 * @param extendedData the new ExtendedData to be used. 0185 */ 0186 void setExtendedData( const GeoDataExtendedData& extendedData ); 0187 0188 const GeoDataLatLonAltBox& latLonAltBox() const override; 0189 void pack( QDataStream& stream ) const override; 0190 void unpack( QDataStream& stream ) override; 0191 0192 private: 0193 Q_DECLARE_PRIVATE(GeoDataTrack) 0194 }; 0195 0196 } 0197 0198 Q_DECLARE_METATYPE( Marble::GeoDataTrack* ) 0199 0200 #endif // MARBLE_GEODATATRACK_H