Kstars

constellationartcomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 M.S.Adityan <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "constellationartcomponent.h"
8 
9 #include "constellationsart.h"
10 #include "culturelist.h"
11 #include "kspaths.h"
12 #include "Options.h"
13 #ifndef KSTARS_LITE
14 #include "skymap.h"
15 #include "skypainter.h"
16 #endif
17 
18 #include <QSqlError>
19 #include <QSqlQuery>
20 
22 {
23  cultureName = cultures->current();
24  records = 0;
25  loadData();
26 }
27 
29 {
30  deleteData();
31 }
32 
34 {
35  qDeleteAll(m_ConstList);
36  m_ConstList.clear();
37 }
38 
40 {
41  if (m_ConstList.isEmpty())
42  {
43  QSqlDatabase skydb = QSqlDatabase::addDatabase("QSQLITE", "skycultures");
44  QString dbfile = KSPaths::locate(QStandardPaths::AppLocalDataLocation, "skycultures.sqlite");
45 
46  skydb.setDatabaseName(dbfile);
47  if (skydb.open() == false)
48  {
49  qWarning() << "Unable to open sky cultures database file " << dbfile;
50  return;
51  }
52  QSqlQuery get_query(skydb);
53 
54  if (cultureName == "Western")
55  {
56  if (!get_query.exec("SELECT * FROM western"))
57  {
58  qDebug() << Q_FUNC_INFO << get_query.lastError();
59  return;
60  }
61  }
62  if (cultureName == "Inuit")
63  {
64  if (!get_query.exec("SELECT * FROM inuit"))
65  {
66  qDebug() << Q_FUNC_INFO << get_query.lastError();
67  return;
68  }
69  }
70 
71  while (get_query.next())
72  {
73  QString abbreviation = get_query.value("Abbreviation").toString();
74  QString filename = get_query.value("Filename").toString();
75  QString midpointRA = get_query.value("MidpointRA").toString();
76  QString midpointDEC = get_query.value("MidpointDEC").toString();
77  double pa = get_query.value("Position Angle").toDouble();
78  double w = get_query.value("Width").toDouble();
79  double h = get_query.value("Height").toDouble();
80 
81  dms midpointra = dms::fromString(midpointRA, false);
82  dms midpointdec = dms::fromString(midpointDEC, true);
83 
84  // appends constellation info
85  ConstellationsArt *ca = new ConstellationsArt(midpointra, midpointdec, pa, w, h, abbreviation, filename);
86  m_ConstList.append(ca);
87  //qDebug()<<"Successfully read skyculture.sqlite"<<abbreviation<<filename<<midpointRA<<midpointDEC<<pa<<w<<h;
88  records++;
89  }
90  //qDebug()<<"Successfully processed"<<records<<"records for"<<cultureName<<"sky culture";
91  skydb.close();
92  }
93 }
94 
96 {
97  int i = 0;
98  for (i = 0; i < m_ConstList.size(); i++)
99  {
100  qDebug() << Q_FUNC_INFO << m_ConstList[i]->getAbbrev() << m_ConstList[i]->getImageFileName();
101  qDebug() << Q_FUNC_INFO << m_ConstList[i]->pa();
102  }
103 }
104 
106 {
107  Q_UNUSED(skyp)
108 #ifndef KSTARS_LITE
109  if (Options::showConstellationArt() && SkyMap::IsSlewing() == false)
110  {
111  for (int i = 0; i < records; i++)
112  skyp->drawConstellationArtImage(m_ConstList[i]);
113  }
114 
115 //Loops through the QList containing all data required to draw constellations.
116 #endif
117 }
void append(const T &value)
QVariant value(int index) const const
void loadData()
Read the skycultures.sqlite database file.
bool exec(const QString &query)
void deleteData()
deletes all created ConstellationsArt objects.
int size() const const
QSqlDatabase addDatabase(const QString &type, const QString &connectionName)
double toDouble(bool *ok) const const
void showList()
Shows the details of the constellations selected skyculture.
void setDatabaseName(const QString &name)
QString current() const
Return the current sky culture.
Definition: culturelist.h:23
bool next()
bool isEmpty() const const
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
QSqlError lastError() const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void clear()
ConstellationArtComponent(SkyComposite *, CultureList *cultures)
Constructor.
~ConstellationArtComponent() override
Destructor.
Information about a ConstellationsArt object. This class represents a constellation image.
virtual bool drawConstellationArtImage(ConstellationsArt *obj)=0
Draw a ConstellationsArt object.
static dms fromString(const QString &s, bool deg)
Static function to create a DMS object from a QString.
Definition: dms.cpp:421
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.