File indexing completed on 2024-04-28 15:09:12

0001 /*
0002     SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "profileinfo.h"
0010 
0011 #include <QJsonArray>
0012 #include <QObject>
0013 #include <QSharedPointer>
0014 #include <QVariantMap>
0015 
0016 namespace Ekos
0017 {
0018 
0019 /**
0020  * @brief The ProfileSettings class
0021  *
0022  * General-purpose class to encapsulate profile-specific settings in the database.
0023  *
0024  * The settings are stored as QVariant Map. Each element in the array should have the following format.
0025  * {
0026  *     "id1": payload1,
0027  *     "id2", payload2,
0028  *     ...
0029  * }
0030  *
0031  * 1. The ID is a unique number from the Settings enum.
0032  * 2. The Payload is QVariant.
0033  *
0034  * @author Jasem Mutlaq
0035  * @version 1.0
0036  */
0037 class ProfileSettings : public QObject
0038 {
0039         Q_OBJECT
0040 
0041     public:
0042 
0043         static ProfileSettings *Instance();
0044         static void release();
0045 
0046         // Settings
0047         typedef enum
0048         {
0049             PrimaryOpticalTrain,
0050 
0051             CaptureOpticalTrain,
0052             FocusOpticalTrain,
0053             MountOpticalTrain,
0054             GuideOpticalTrain,
0055             AlignOpticalTrain,
0056             DarkLibraryOpticalTrain,
0057         } Settings;
0058 
0059         void setProfile(const QSharedPointer<ProfileInfo> &profile);
0060 
0061         void setOneSetting(Settings id, const QVariant &value);
0062         QVariant getOneSetting(Settings id);
0063         void initSettings();
0064         void setSettings(const QVariantMap &settings);
0065         const QVariantMap &getSettings() const
0066         {
0067             return m_Settings;
0068         }
0069         uint32_t id() const
0070         {
0071             return m_Profile->id;
0072         }
0073 
0074     signals:
0075         void updated();
0076 
0077     private:
0078 
0079         ProfileSettings(QObject *parent = nullptr);
0080         static ProfileSettings *m_Instance;
0081 
0082         QSharedPointer<ProfileInfo> m_Profile;
0083         QVariantMap m_Settings;
0084 };
0085 
0086 }