File indexing completed on 2024-04-28 15:11:24

0001 /*
0002     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "qabstractitemmodel.h"
0010 
0011 class SkyObjItem;
0012 
0013 /**
0014  * @class SkyObjListModel
0015  * Represents a model for the list of interesting sky-objects to be displayed in the QML interface.
0016  *
0017  * @author Samikshan Bairagya
0018  */
0019 class SkyObjListModel : public QAbstractListModel
0020 {
0021     Q_OBJECT
0022   public:
0023     /** Constructor */
0024     explicit SkyObjListModel(SkyObjItem *soitem = nullptr, QObject *parent = nullptr);
0025 
0026     /**
0027      * @brief Add a sky-object to the model.
0028      * @param sobj
0029      * Pointer to sky-object to be added.
0030      */
0031     void addSkyObject(SkyObjItem *sobj);
0032 
0033     /**
0034      * @brief Create and return a QHash<int, QByteArray> of rolenames for the SkyObjItem.
0035      * @return QHash<int, QByteArray> of rolenames for the SkyObjItem.
0036      */
0037     QHash<int, QByteArray> roleNames() const override;
0038 
0039     /**
0040      * @brief Overridden method from QAbstractItemModel.
0041      * @return The number of items in the sky-object list model.
0042      */
0043     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0044 
0045     /**
0046      * @brief Overridden method from QAbstractItemModel.
0047      * @return Data stored under the given role for the sky-object item referred to by the index.
0048      */
0049     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0050 
0051     /**
0052      * @brief Get the list of sky-object items in the model.
0053      * @return A QList of pointers to SkyObjItems which are there in the model.
0054      */
0055     QList<SkyObjItem *> getSkyObjItems();
0056 
0057     /**
0058      * @brief Get sky-object item referred to by index.
0059      * @return Pointer to SkyObjItem referred to by index.
0060      */
0061     SkyObjItem *getSkyObjItem(int index);
0062 
0063     /** Erase all data in model. */
0064     void resetModel();
0065 
0066     int getSkyObjIndex(SkyObjItem *item);
0067 
0068   private:
0069     QList<SkyObjItem *> m_SoItemList; ///List of sky-object items in model.
0070 };