7#include "modelmanager.h"
9#include "ksfilereader.h"
11#include "kstarsdata.h"
12#include "obsconditions.h"
13#include "skymapcomposite.h"
14#include "skyobjitem.h"
15#include "skyobjlistmodel.h"
16#include "starobject.h"
17#include "catalogsdb.h"
19#include <QtConcurrent>
23 m_ObsConditions = obs;
34 for (
int i = 0; i < NumberOfLists; i++)
40#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
47ModelManager::~ModelManager()
49 qDeleteAll(m_ModelList);
55void ModelManager::loadLists()
60 emit loadProgressUpdated(0);
64 for (
int i = 0; i < listStars.
size(); i++)
66 QPair<QString, const SkyObject *> pair = listStars.
value(i);
72 for (
int i = 0; i < m_ObjectList[Stars].
size(); i++)
75 if (prevName == star->
getName())
84 if (!fileReader.
open(
"Interesting.dat"))
94 if (line.
length() == 0 || line[0] ==
'#')
103 case SkyObject::OPEN_CLUSTER:
104 case SkyObject::GLOBULAR_CLUSTER:
105 case SkyObject::GALAXY_CLUSTER:
108 case SkyObject::PLANETARY_NEBULA:
109 case SkyObject::DARK_NEBULA:
110 case SkyObject::GASEOUS_NEBULA:
113 case SkyObject::GALAXY:
120 emit loadProgressUpdated(0.20);
123 emit loadProgressUpdated(0.30);
124 loadObjectList(m_ObjectList[Comets], SkyObject::COMET);
125 emit loadProgressUpdated(0.40);
126 loadObjectList(m_ObjectList[Satellites], SkyObject::SATELLITE);
127 loadObjectList(m_ObjectList[Supernovas], SkyObject::SUPERNOVA);
128 emit loadProgressUpdated(0.50);
129 loadObjectList(m_ObjectList[Constellations], SkyObject::CONSTELLATION);
130 emit loadProgressUpdated(0.55);
131 loadObjectList(m_ObjectList[Planets], SkyObject::PLANET);
132 emit loadProgressUpdated(0.60);
134 loadObjectList(m_ObjectList[Galaxies], SkyObject::GALAXY);
135 emit loadProgressUpdated(0.70);
137 loadObjectList(m_ObjectList[Clusters], SkyObject::OPEN_CLUSTER);
138 loadObjectList(m_ObjectList[Clusters], SkyObject::GLOBULAR_CLUSTER);
139 loadObjectList(m_ObjectList[Clusters], SkyObject::GALAXY_CLUSTER);
140 emit loadProgressUpdated(0.80);
142 loadObjectList(m_ObjectList[Nebulas], SkyObject::PLANETARY_NEBULA);
143 loadObjectList(m_ObjectList[Nebulas], SkyObject::SUPERNOVA_REMNANT);
144 loadObjectList(m_ObjectList[Nebulas], SkyObject::GASEOUS_NEBULA);
145 loadObjectList(m_ObjectList[Nebulas], SkyObject::DARK_NEBULA);
147 emit loadProgressUpdated(0.90);
148 emit loadProgressUpdated(1);
153 m_ObsConditions = obs;
156 for (
int i = 0; i < NumberOfLists; i++)
157 loadObjectsIntoModel(*m_ModelList[i], m_ObjectList[i]);
162 m_ObsConditions = obs;
164 const auto modelNumber = getModelNumber(modelName);
166 if (modelNumber > -1 && model)
169 if (showOnlyFavorites && modelName ==
"galaxies")
170 loadObjectsIntoModel(*m_ModelList[modelNumber], favoriteGalaxies);
171 else if (showOnlyFavorites && modelName ==
"nebulas")
172 loadObjectsIntoModel(*m_ModelList[modelNumber], favoriteNebulas);
173 else if (showOnlyFavorites && modelName ==
"clusters")
174 loadObjectsIntoModel(*m_ModelList[modelNumber], favoriteClusters);
176 loadObjectsIntoModel(*m_ModelList[modelNumber], m_ObjectList[modelNumber]);
189 for (
int i = 0; i < objects.size(); i++)
194 QPair<QString, const SkyObject *> pair = objects.value(i);
195 const SkyObject *listObject = pair.second;
197 if (listObject->
name() !=
i18n(
"Sun"))
201 for (
int i = 0; i < skyObjectList.
size(); i++)
207 if (prevName == obj->
getName())
235int ModelManager::getModelNumber(
QString modelName)
237 if (modelName ==
"planets")
239 if (modelName ==
"stars")
241 if (modelName ==
"constellations")
242 return Constellations;
243 if (modelName ==
"galaxies")
245 if (modelName ==
"clusters")
247 if (modelName ==
"nebulas")
249 if (modelName ==
"asteroids")
251 if (modelName ==
"comets")
253 if (modelName ==
"supernovas")
255 if (modelName ==
"satellites")
257 if (modelName ==
"messier")
259 if (modelName ==
"ngc")
261 if (modelName ==
"ic")
263 if (modelName ==
"sharpless")
271 int modelNumber = getModelNumber(modelName);
272 if (modelNumber > -1 && modelNumber < NumberOfLists)
273 return m_ModelList[modelNumber];
280 const auto id = getModelNumber(name);
281 if (m_CatalogMap.count(
id) > 0)
284 const std::unordered_map<QString, QString> search_prefixes{
285 {
"ngc",
"NGC " }, {
"ic",
"IC " }, {
"messier",
"M " }, {
"sharpless",
"Sh2 " }
290 const auto &prefix = search_prefixes.at(name);
291 const int offset = prefix.size();
293 m_CatalogMap[id] = std::get<2>(manager.general_master_query(
294 QString(
"name LIKE '%1'").arg(prefix +
"%"),
295 QString(
"CAST(SUBSTR(name,%1) AS INT)").arg(offset)));
297 auto &lst = m_CatalogSkyObjItems[id];
299 for (
auto &obj : m_CatalogMap[
id])
301 obj.updateCoordsNow(KStarsData::Instance()->updateNum());
302 lst.emplace_back(&obj);
305 auto &p_lst = m_ObjectList[id];
306 for (
auto &obj : lst)
309 updateModel(m_ObsConditions, name);
310 emit loadProgressUpdated(1);
Manages the catalog database and provides an interface to provide an interface to query and modify th...
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
QString readLine()
increments the line number and returns the next line from the file as a QString.
bool hasMoreLines() const
bool open(const QString &fname)
opens the file fname from the QStandardPaths::AppLocalDataLocation directory and uses that file for t...
KStarsData is the backbone of KStars.
SkyMapComposite * skyComposite()
static bool Closing
Set to true when the application is being closed.
void resetAllModels()
Clears all sky-objects list models.
void loadCatalog(const QString &name)
Load objects from the dso db for the catalog with name can be used to retreive the object lists later...
ModelManager(ObsConditions *obs)
Constructor - Creates models for different sky-object types.
SkyObjListModel * returnModel(QString modelName)
Returns model of given type.
void updateAllModels(ObsConditions *obs)
Updates sky-object list models.
This class deals with the observing conditions of the night sky.
bool isVisible(GeoLocation *geo, dms *lst, SkyObject *so)
Evaluate visibility of sky-object based on current observing conditions.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument.
Represents an item in the list of interesting sky-objects.
SkyObject * getSkyObject()
Get sky-object associated with the SkyObjItem.
QString getName() const
Get name of sky-object associated with the SkyObjItem.
Represents a model for the list of interesting sky-objects to be displayed in the QML interface.
void resetModel()
Erase all data in model.
void addSkyObject(SkyObjItem *sobj)
Add a sky-object to the model.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
virtual QString name(void) const
This is a subclass of SkyObject.
bool hasLatinName() const
QString i18n(const char *text, const TYPE &arg...)
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
void removeAt(qsizetype i)
qsizetype size() const const
T value(qsizetype i) const const
qsizetype length() const const
QFuture< T > run(Function function,...)