Kstars

opticaltrainsettings.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "opticaltrainsettings.h"
8#include <kstars_debug.h>
9
10#include "kstars.h"
11#include "kstarsdata.h"
12#include "ksuserdb.h"
13
14#include <QJsonDocument>
15
16namespace Ekos
17{
18
19OpticalTrainSettings *OpticalTrainSettings::m_Instance = nullptr;
20
21////////////////////////////////////////////////////////////////////////////
22///
23////////////////////////////////////////////////////////////////////////////
24OpticalTrainSettings *OpticalTrainSettings::Instance()
25{
26 if (m_Instance == nullptr)
27 m_Instance = new OpticalTrainSettings(KStars::Instance());
28
29 return m_Instance;
30}
31
32////////////////////////////////////////////////////////////////////////////
33///
34////////////////////////////////////////////////////////////////////////////
35void OpticalTrainSettings::release()
36{
37 delete (m_Instance);
38 m_Instance = nullptr;
39}
40
41////////////////////////////////////////////////////////////////////////////
42///
43////////////////////////////////////////////////////////////////////////////
44OpticalTrainSettings::OpticalTrainSettings(QObject *parent) : QObject(parent)
45{
46}
47
48////////////////////////////////////////////////////////////////////////////
49///
50////////////////////////////////////////////////////////////////////////////
51void OpticalTrainSettings::setOpticalTrainID(uint32_t id)
52{
53 m_TrainID = id;
54 // If not in database yet, create an empty entry.
55 if (KStars::Instance()->data()->userdb()->GetOpticalTrainSettings(m_TrainID, m_Settings) == false)
56 {
57 initSettings();
58 KStars::Instance()->data()->userdb()->GetOpticalTrainSettings(m_TrainID, m_Settings);
59 }
60}
61
62////////////////////////////////////////////////////////////////////////////
63///
64////////////////////////////////////////////////////////////////////////////
65void OpticalTrainSettings::initSettings()
66{
67 auto object = QJsonObject::fromVariantMap(QVariantMap());
70}
71
72////////////////////////////////////////////////////////////////////////////
73///
74////////////////////////////////////////////////////////////////////////////
75void OpticalTrainSettings::setSettings(const QVariantMap &settings)
76{
77 m_Settings = settings;
78 auto object = QJsonObject::fromVariantMap(m_Settings);
79 KStars::Instance()->data()->userdb()->UpdateOpticalTrainSettings(m_TrainID,
81}
82
83////////////////////////////////////////////////////////////////////////////
84///
85////////////////////////////////////////////////////////////////////////////
86QVariant OpticalTrainSettings::getOneSetting(Settings id)
87{
88 return m_Settings[QString::number(id)];
89}
90
91////////////////////////////////////////////////////////////////////////////
92///
93////////////////////////////////////////////////////////////////////////////
94void OpticalTrainSettings::setOneSetting(Settings id, const QVariant &value)
95{
96 m_Settings[QString::number(id)] = value;
97 auto object = QJsonObject::fromVariantMap(m_Settings);
98 KStars::Instance()->data()->userdb()->UpdateOpticalTrainSettings(m_TrainID,
100}
101}
bool GetOpticalTrainSettings(uint32_t train, QVariantMap &settings)
Populate the reference passed with settings for one paritcular Train.
bool AddOpticalTrainSettings(uint32_t train, const QByteArray &settings)
Add new Train settings to the database.
KSUserDB * userdb()
Definition kstarsdata.h:215
static KStars * Instance()
Definition kstars.h:121
KStarsData * data() const
Definition kstars.h:133
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
QJsonObject fromVariantMap(const QVariantMap &map)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.