File indexing completed on 2024-04-21 03:49:34

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Thibaut Gridel <tgridel@free.fr>
0004 //
0005 
0006 #ifndef MARBLE_GEODATATREEMODEL_H
0007 #define MARBLE_GEODATATREEMODEL_H
0008 
0009 #include "marble_export.h"
0010 
0011 #include <QAbstractItemModel>
0012 
0013 class QItemSelectionModel;
0014 
0015 namespace Marble
0016 {
0017 class GeoDataObject;
0018 class GeoDataDocument;
0019 class GeoDataFeature;
0020 class GeoDataContainer;
0021 class GeoDataTourPrimitive;
0022 
0023 
0024 /**
0025  * @short The representation of GeoData in a model
0026  * This class represents all available data given by kml-data files.
0027  */
0028 class MARBLE_EXPORT GeoDataTreeModel : public QAbstractItemModel
0029 {
0030     Q_OBJECT
0031 
0032  public:
0033 
0034     /**
0035      * Creates a new GeoDataTreeModel.
0036      *
0037      * @param parent The parent object.
0038      */
0039     explicit GeoDataTreeModel( QObject *parent = nullptr );
0040 
0041     /**
0042      * Destroys the GeoDataModel.
0043      */
0044     ~GeoDataTreeModel() override;
0045 
0046     /**
0047      * Return the number of Items in the Model.
0048      */
0049     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0050 
0051     QVariant headerData(int section, Qt::Orientation orientation,
0052                                 int role = Qt::DisplayRole) const override;
0053 
0054     QHash<int, QByteArray> roleNames() const override;
0055 
0056     QVariant data(const QModelIndex &index, int role) const override;
0057 
0058     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0059 
0060     QModelIndex index(const GeoDataObject *object) const;
0061 
0062     QModelIndex parent(const QModelIndex &index) const override;
0063 
0064     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0065 
0066     Qt::ItemFlags flags(const QModelIndex &index) const override;
0067 
0068     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0069 
0070     QItemSelectionModel *selectionModel();
0071 
0072     GeoDataDocument *rootDocument();
0073 
0074 public Q_SLOTS:
0075 
0076     /**
0077       * Sets the root document to use. This replaces previously loaded data, if any.
0078       * @param document The new root document. Ownership retains with the caller,
0079       *   i.e. GeoDataTreeModel will not delete the passed document at its destruction.
0080       */
0081     void setRootDocument( GeoDataDocument *document );
0082 
0083     int addFeature( GeoDataContainer *parent, GeoDataFeature *feature, int row = -1 );
0084 
0085     bool removeFeature( GeoDataContainer *parent, int index );
0086 
0087     int removeFeature(GeoDataFeature *feature);
0088 
0089     void updateFeature( GeoDataFeature *feature );
0090 
0091     int addDocument( GeoDataDocument *document );
0092 
0093     void removeDocument( int index );
0094 
0095     void removeDocument( GeoDataDocument* document );
0096 
0097     int addTourPrimitive( const QModelIndex &parent, GeoDataTourPrimitive *primitive, int row = -1 );
0098     bool removeTourPrimitive( const QModelIndex &parent, int index );
0099     bool swapTourPrimitives( const QModelIndex &parent, int indexA, int indexB );
0100 
0101 Q_SIGNALS:
0102     /// insert and remove row don't trigger any signal that proxies forward
0103     /// this signal will refresh geometry layer and placemark layout
0104     void removed( GeoDataObject *object );
0105     void added( GeoDataObject *object );
0106  private:
0107     Q_DISABLE_COPY( GeoDataTreeModel )
0108     class Private;
0109     Private* const d;
0110 };
0111 
0112 }
0113 
0114 #endif // MARBLE_GEODATATREEMODEL_H