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 "catalogobject.h" 0010 #include "skyobjitem.h" 0011 #include "catalogsdb.h" 0012 #include <QList> 0013 #include <QObject> 0014 0015 #include "polyfills/qstring_hash.h" 0016 #include <unordered_map> 0017 0018 class ObsConditions; 0019 class SkyObjListModel; 0020 0021 /** 0022 * @class ModelManager 0023 * @brief Manages models for QML listviews of different types of sky-objects. 0024 * 0025 * @author Samikshan Bairagya 0026 */ 0027 class ModelManager : public QObject 0028 { 0029 Q_OBJECT 0030 public: 0031 /** 0032 * @enum ObjectList 0033 * @brief Model type for different types of sky-objects. 0034 */ 0035 enum ObjectList 0036 { 0037 Planets, 0038 Stars, 0039 Constellations, 0040 Galaxies, 0041 Clusters, 0042 Nebulas, 0043 Satellites, 0044 Asteroids, 0045 Comets, 0046 Supernovas, 0047 Messier, 0048 NGC, 0049 IC, 0050 Sharpless, 0051 NumberOfLists 0052 }; 0053 0054 /** 0055 * @brief Constructor - Creates models for different sky-object types. 0056 * @param obs Pointer to an ObsConditions object. 0057 */ 0058 explicit ModelManager(ObsConditions *obs); 0059 ~ModelManager() override; 0060 0061 /** Updates sky-object list models. */ 0062 void updateAllModels(ObsConditions *obs); 0063 0064 void updateModel(ObsConditions *obs, QString modelName); 0065 0066 /** Clears all sky-objects list models. */ 0067 void resetAllModels(); 0068 0069 void setShowOnlyVisibleObjects(bool show) { showOnlyVisible = show; } 0070 0071 bool showOnlyVisibleObjects() { return showOnlyVisible; } 0072 0073 void setShowOnlyFavoriteObjects(bool show) { showOnlyFavorites = show; } 0074 0075 bool showOnlyFavoriteObjects() { return showOnlyFavorites; } 0076 0077 /** 0078 * Load objects from the dso db for the catalog with \p name can 0079 * be used to retreive the object lists later. 0080 * 0081 * This is implemented by searching the dso database for objects 0082 * whichs name starts with a prefix to capture subsets of a catalog. 0083 */ 0084 void loadCatalog(const QString &name); 0085 0086 /** 0087 * @brief Returns model of given type. 0088 * @return Pointer to SkyObjListModel of given type. 0089 * @param modelName Name of sky-object model to be returned. 0090 */ 0091 SkyObjListModel *returnModel(QString modelName); 0092 0093 int getModelNumber(QString modelName); 0094 0095 SkyObjListModel *getTempModel() { return tempModel; } 0096 0097 signals: 0098 void loadProgressUpdated(double progress); 0099 void modelUpdated(); 0100 0101 private: 0102 void loadLists(); 0103 void loadObjectList(QList<SkyObjItem *> &skyObjectList, int type); 0104 void loadNamedStarList(); 0105 void loadObjectsIntoModel(SkyObjListModel &model, QList<SkyObjItem *> &skyObjectList); 0106 0107 ObsConditions *m_ObsConditions{ nullptr }; 0108 QList<QList<SkyObjItem *>> m_ObjectList; 0109 QList<SkyObjListModel *> m_ModelList; 0110 bool showOnlyVisible{ true }; 0111 bool showOnlyFavorites{ true }; 0112 QList<SkyObjItem *> favoriteGalaxies; 0113 QList<SkyObjItem *> favoriteNebulas; 0114 QList<SkyObjItem *> favoriteClusters; 0115 SkyObjListModel *tempModel{ nullptr }; 0116 std::unordered_map<int, CatalogsDB::CatalogObjectList> m_CatalogMap; 0117 std::unordered_map<int, std::list<SkyObjItem>> m_CatalogSkyObjItems; 0118 };