File indexing completed on 2024-04-28 03:48:56

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <inge@lysator.liu.se>
0005 // SPDX-FileCopyrightText: 2009 Patrick Spendrin <ps_ml@gmx.de>
0006 //
0007 
0008 
0009 #ifndef MARBLE_GEODATACONTAINER_H
0010 #define MARBLE_GEODATACONTAINER_H
0011 
0012 #include <QVector>
0013 
0014 #include "geodata_export.h"
0015 
0016 #include "GeoDataFeature.h"
0017 
0018 namespace Marble
0019 {
0020 
0021 class GeoDataContainerPrivate;
0022 
0023 class GeoDataFolder;
0024 class GeoDataPlacemark;
0025 class GeoDataLatLonAltBox;
0026 
0027 /**
0028  * @short  A base class that can hold GeoDataFeatures
0029  *
0030  * GeoDataContainer is the base class for the GeoData container
0031  * classes GeoDataFolder and GeoDataDocument.  It is never
0032  * instantiated by itself, but is always used as part of a derived
0033  * class.
0034  *
0035  * It is based on GeoDataFeature, and it only adds a
0036  * QVector<GeodataFeature *> to it, making it a Feature that can hold
0037  * other Features.
0038  *
0039  * @see GeoDataFolder
0040  * @see GeoDataDocument
0041  */
0042 class GEODATA_EXPORT GeoDataContainer : public GeoDataFeature
0043 {
0044  public:
0045     /// Default constructor
0046     GeoDataContainer();
0047     GeoDataContainer( const GeoDataContainer& other );
0048     /// Destruct the GeoDataContainer
0049     ~GeoDataContainer() override;
0050 
0051     GeoDataContainer& operator=(const GeoDataContainer& other);
0052 
0053     /**
0054      * @brief A convenience function that returns the LatLonAltBox of all
0055      * placemarks in this container.
0056      * @return The GeoDataLatLonAltBox
0057      *
0058      * @see GeoDataLatLonAltBox
0059      */
0060     GeoDataLatLonAltBox latLonAltBox() const;
0061 
0062     /**
0063      * @brief A convenience function that returns all folders in this container.
0064      * @return A QVector of GeoDataFolder
0065      *
0066      * @see GeoDataFolder
0067      */
0068     QVector<GeoDataFolder*> folderList() const;
0069 
0070     /**
0071      * @brief A convenience function that returns all features in this container.
0072      * @return A QVector of GeoDataFeature
0073      *
0074      * @see GeoDataFeature
0075      */
0076     QVector<GeoDataFeature*> featureList() const;
0077 
0078     /**
0079      * @brief A convenience function that returns all placemarks in this container.
0080      * @return A QVector of GeoDataPlacemark
0081      *
0082      * @see GeoDataPlacemark
0083      */
0084     QVector<GeoDataPlacemark*> placemarkList() const;
0085     
0086     /**
0087      * @brief  returns the requested child item
0088      */
0089     GeoDataFeature* child( int );
0090 
0091     /**
0092      * @brief  returns the requested child item
0093      */
0094     const GeoDataFeature* child( int ) const;
0095 
0096     /**
0097      * @brief returns the position of an item in the list
0098      */
0099     int childPosition( const GeoDataFeature *child) const;
0100 
0101     /**
0102      * @brief inserts @p feature at position @p index in the container
0103      */
0104     void insert( int index, GeoDataFeature *feature );
0105 
0106     GEODATA_DEPRECATED void insert(GeoDataFeature *other, int index);
0107 
0108     /**
0109     * @brief add an element
0110     */
0111     void append( GeoDataFeature *other );
0112 
0113     void remove( int index );
0114 
0115     void remove(int index, int count);
0116 
0117     int removeAll(GeoDataFeature* feature);
0118 
0119     void removeAt(int index);
0120 
0121     void removeFirst();
0122 
0123     void removeLast();
0124 
0125     bool removeOne( GeoDataFeature *feature );
0126 
0127     /**
0128     * @brief size of the container
0129     */
0130     int size() const;
0131 
0132     /**
0133      * @brief Returns true if the container has size 0; otherwise returns false.
0134      */
0135     bool isEmpty() const;
0136 
0137     /**
0138     * @brief return the reference of the element at a specific position
0139     */
0140     GeoDataFeature& at( int pos );
0141     const GeoDataFeature& at( int pos ) const;
0142 
0143     /**
0144     * @brief return the reference of the last element for convenience
0145     */
0146     GeoDataFeature& last();
0147     const GeoDataFeature& last() const;
0148     /**
0149     * @brief return the reference of the last element for convenience
0150     */
0151     GeoDataFeature& first();
0152     const GeoDataFeature& first() const;
0153 
0154     QVector<GeoDataFeature*>::Iterator begin();
0155     QVector<GeoDataFeature*>::Iterator end();
0156     QVector<GeoDataFeature*>::ConstIterator constBegin() const;
0157     QVector<GeoDataFeature*>::ConstIterator constEnd() const;
0158     void clear();
0159 
0160     /**
0161      * @brief  Serialize the container to a stream.
0162      * @param  stream  the stream
0163      */
0164     void pack( QDataStream& stream ) const override;
0165     /**
0166      * @brief  Unserialize the container from a stream
0167      * @param  stream  the stream
0168      */
0169     void unpack( QDataStream& stream ) override;
0170 
0171  protected:
0172     explicit GeoDataContainer(GeoDataContainerPrivate *priv);
0173     GeoDataContainer(const GeoDataContainer& other, GeoDataContainerPrivate *priv);
0174 
0175     bool equals( const GeoDataContainer &other ) const;
0176     using GeoDataFeature::equals;
0177 
0178  private:
0179     Q_DECLARE_PRIVATE(GeoDataContainer)
0180 };
0181 
0182 }
0183 
0184 #endif