1 /*
2     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "qabstractitemmodel.h"
10 
11 class SkyObjItem;
12 
13 /**
14  * @class SkyObjListModel
15  * Represents a model for the list of interesting sky-objects to be displayed in the QML interface.
16  *
17  * @author Samikshan Bairagya
18  */
19 class SkyObjListModel : public QAbstractListModel
20 {
21     Q_OBJECT
22   public:
23     /** Constructor */
24     explicit SkyObjListModel(SkyObjItem *soitem = nullptr, QObject *parent = nullptr);
25 
26     /**
27      * @brief Add a sky-object to the model.
28      * @param sobj
29      * Pointer to sky-object to be added.
30      */
31     void addSkyObject(SkyObjItem *sobj);
32 
33     /**
34      * @brief Create and return a QHash<int, QByteArray> of rolenames for the SkyObjItem.
35      * @return QHash<int, QByteArray> of rolenames for the SkyObjItem.
36      */
37     QHash<int, QByteArray> roleNames() const override;
38 
39     /**
40      * @brief Overridden method from QAbstractItemModel.
41      * @return The number of items in the sky-object list model.
42      */
43     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
44 
45     /**
46      * @brief Overridden method from QAbstractItemModel.
47      * @return Data stored under the given role for the sky-object item referred to by the index.
48      */
49     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
50 
51     /**
52      * @brief Get the list of sky-object items in the model.
53      * @return A QList of pointers to SkyObjItems which are there in the model.
54      */
55     QList<SkyObjItem *> getSkyObjItems();
56 
57     /**
58      * @brief Get sky-object item referred to by index.
59      * @return Pointer to SkyObjItem referred to by index.
60      */
61     SkyObjItem *getSkyObjItem(int index);
62 
63     /** Erase all data in model. */
64     void resetModel();
65 
66     int getSkyObjIndex(SkyObjItem *item);
67 
68   private:
69     QList<SkyObjItem *> m_SoItemList; ///List of sky-object items in model.
70 };
71