File indexing completed on 2024-05-12 04:41:10
0001 /* AtCore KDE Libary for 3D Printers 0002 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 SPDX-FileCopyrightText: 2019 Chris Rizzitello <rizzitello@kde.org> 0004 SPDX-FileCopyrightText: 2019 Lays Rodrigues <lays.rodrigues@kde.org> 0005 */ 0006 0007 #pragma once 0008 #include "atcore_export.h" 0009 0010 #include <QObject> 0011 #include <QQmlEngine> 0012 #include <QSettings> 0013 #include <QVariant> 0014 0015 class ATCORE_EXPORT MachineInfo : public QObject 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(QStringList profileNames READ profileNames NOTIFY profilesChanged) 0019 public: 0020 /** 0021 * @brief KEYS enum Possible keys for the printer settings 0022 */ 0023 enum class KEY { 0024 NAME = 0, //!< Profile Name 0025 BAUDRATE, //!< Machine BAUD Rate 0026 FIRMWARE, //!< Firmware name 0027 MAXBEDTEMP, //!< Maximum Bed Temperature 0028 MAXEXTTEMP, //!< Maximum Extruder Temperature 0029 POSTPAUSE, //!< Post Pause Commands 0030 ISCARTESIAN, //!< Is the machine Cartesian 0031 XMAX, //!< X Size for Cartesian machines, Radius for Deltas. 0032 YMAX, //!< Y Size 0033 ZMAX, //!< Z Size for Cartesian machines, Height for Deltas. 0034 AUTOTEMPREPORT, //!< Supports AutoTemp Reporting. 0035 }; 0036 Q_ENUM(KEY) 0037 0038 /** 0039 * @brief Get the MachineInfo Instance. 0040 * @sa qmlSingletonRegister() 0041 */ 0042 static MachineInfo *instance(); 0043 0044 /** 0045 * @brief Register The MachineInfo Singleton for QML 0046 */ 0047 QObject *qmlSingletonRegister(QQmlEngine *engine, QJSEngine *scriptEngine); 0048 0049 /** 0050 * @brief Read a full profile 0051 * @param profileName: name of the profile you want to read. 0052 * @return A full map of the profile 0053 * @sa readKey() 0054 */ 0055 Q_INVOKABLE QVariantMap readProfile(const QString &profileName) const; 0056 0057 /** 0058 * @brief Read a key from a profile 0059 * @param profileName: name of the profile you want to read from. 0060 * @param key: the Key you want to read 0061 * @return The value of the requested Key 0062 * @sa readProfile() 0063 */ 0064 Q_INVOKABLE QVariant readKey(const QString &profileName, const MachineInfo::KEY key) const; 0065 0066 /** 0067 * @brief Store a new profile, Must be used for new profiles. 0068 * @param profile: A complete machine profile or one that at very least has MachineInfo::Name and any other valid Key. 0069 * @sa storeKey() 0070 */ 0071 void storeProfile(const QMap<MachineInfo::KEY, QVariant> &profile) const; 0072 0073 /** 0074 * @brief Store a new profile, Must be used for new profiles or to override a profile. 0075 * @param profile: A complete machine profile or one that at very least has a profile Name and any other valid Key. 0076 * @sa storeKey() 0077 */ 0078 Q_INVOKABLE void storeProfile(const QVariantMap &profile) const; 0079 0080 /** 0081 * @brief Store a key to an existing profile, Sending a key of Key::NAME will rename the profile 0082 * @param profileName: profile to write into 0083 * @param key: The key you will write to 0084 * @param value: The value you will store. 0085 * @return true if successful 0086 * @sa storeProfile() 0087 */ 0088 Q_INVOKABLE bool storeKey(const QString &profileName, const MachineInfo::KEY key, const QVariant &value) const; 0089 0090 /** 0091 * @brief copyies a profile and optionally deletes the src profile 0092 * @param srcProfile: profiles Current Name 0093 * @param destProfile: profiles New Name 0094 * @param rmSrc: delete srcProfile (defalut false) 0095 * @return true if successful 0096 */ 0097 Q_INVOKABLE bool copyProfile(const QString &srcProfile, const QString &destProfile, bool rmSrc = false) const; 0098 /** 0099 * @brief Remove a full profile 0100 * @param profileName: name of the profile you want to remove. 0101 * @return true if successful. 0102 */ 0103 Q_INVOKABLE bool removeProfile(const QString &profileName) const; 0104 0105 /** 0106 * @brief Get a list of all the profile names 0107 * @return QStringList containing the stored profile names. 0108 */ 0109 QStringList profileNames() const; 0110 0111 /** 0112 * @brief Translate a key enum to string 0113 * @param key: name of the key to be translated. 0114 * @return key string if successful. 0115 */ 0116 Q_INVOKABLE QString keyName(const MachineInfo::KEY key) const; 0117 0118 signals: 0119 /** 0120 * @brief A profile has changed 0121 */ 0122 void profilesChanged() const; 0123 0124 private: 0125 MachineInfo *operator=(MachineInfo &other) = delete; 0126 MachineInfo(const MachineInfo &other) = delete; 0127 explicit MachineInfo(QObject *parent = nullptr); 0128 ~MachineInfo() = default; 0129 0130 /** 0131 * @brief used to hold MachineInfo::KEY name and defaultValues. 0132 */ 0133 struct keyInfo { 0134 QString name; //!< Key name used in the settings file 0135 QVariant defaultValue; //!< Defaut Value for the key 0136 }; 0137 /** 0138 * @brief Map of MachineInfo::KEY , KeyString and DefaultValue 0139 */ 0140 static const QMap<MachineInfo::KEY, MachineInfo::keyInfo> decoderMap; 0141 0142 /** 0143 * @brief m_settings our settings object. 0144 */ 0145 0146 QSettings *m_settings = nullptr; 0147 };