Changeset View
Changeset View
Standalone View
Standalone View
src/core/machineinfo.h
- This file was added.
1 | /* AtCore | ||||
---|---|---|---|---|---|
2 | Copyright (C) <2019> | ||||
3 | | ||||
4 | Authors: | ||||
5 | Chris Rizzitello <rizzitello@kde.org> | ||||
6 | | ||||
7 | This library is free software; you can redistribute it and/or | ||||
8 | modify it under the terms of the GNU Lesser General Public | ||||
9 | License as published by the Free Software Foundation; either | ||||
10 | version 2.1 of the License, or (at your option) version 3, or any | ||||
11 | later version accepted by the membership of KDE e.V. (or its | ||||
12 | successor approved by the membership of KDE e.V.), which shall | ||||
13 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
14 | | ||||
15 | This library is distributed in the hope that it will be useful, | ||||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
18 | Lesser General Public License for more details. | ||||
19 | | ||||
20 | You should have received a copy of the GNU Lesser General Public | ||||
21 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
22 | */ | ||||
23 | | ||||
24 | #pragma once | ||||
25 | #include "atcore_export.h" | ||||
26 | | ||||
27 | #include <QObject> | ||||
28 | #include <QSettings> | ||||
29 | #include <QQmlEngine> | ||||
30 | | ||||
31 | class ATCORE_EXPORT MachineInfo : public QObject | ||||
32 | { | ||||
33 | Q_OBJECT | ||||
34 | public: | ||||
35 | /** | ||||
36 | * @brief KEYS enum Possible keys for the printer settings | ||||
37 | */ | ||||
38 | enum class KEY { | ||||
patrickelectric: this should be a namespace or a enum class | |||||
39 | NAME = 0, //!< Profile Name | ||||
patrickelectric: Start the first one as zero, we may add something before name | |||||
40 | BAUDRATE, //!< Machine BAUD Rate | ||||
41 | FIRMWARE, //!<Firmware name | ||||
42 | MAXBEDTEMP, //!<Maximum Bed Temperature | ||||
43 | MAXEXTTEMP, //!<Maximum Extruder Temperature | ||||
44 | POSTPAUSE, //!<Post Pause Commands | ||||
45 | ISCARTESIAN, //!<Is the machine Cartesian | ||||
46 | XMAX, //!<X Size for Cartesian machines, Radius for Deltas. | ||||
47 | YMAX, //!<Y Size | ||||
48 | ZMAX, //!<Z Size for Cartesian machines, Height for Deltas. | ||||
49 | AUTOTEMPREPORT, //!<Supports AutoTemp Reporting. | ||||
patrickelectric: comma in the end | |||||
50 | }; | ||||
51 | Q_ENUM(KEY) | ||||
patrickelectric: NICE | |||||
52 | | ||||
53 | /** | ||||
54 | * @brief Get the MachineInfo Instance. | ||||
55 | * @sa qmlSingletonRegister() | ||||
56 | */ | ||||
57 | static MachineInfo *instance(); | ||||
get is not usually used in our api and Qt api, I think this function should be instance() or self(). patrickelectric: get is not usually used in our api and Qt api, I think this function should be `instance()` or… | |||||
58 | | ||||
59 | /** | ||||
60 | * @brief Register The MachineInfo Singleton for QML | ||||
patrickelectric: When you are a QObject copy is not allowed, this looks unnecessary. | |||||
61 | */ | ||||
patrickelectric: why this is public ? | |||||
62 | QObject *qmlSingletonRegister(QQmlEngine *engine, QJSEngine *scriptEngine); | ||||
63 | | ||||
64 | /** | ||||
65 | * @brief Read a full profile | ||||
66 | * @param profileName: name of the profile you want to read. | ||||
67 | * @return A full map of the profile | ||||
68 | * @sa readKey() | ||||
69 | */ | ||||
70 | Q_INVOKABLE QVariantMap readProfile(const QString &profileName) const; | ||||
71 | | ||||
72 | /** | ||||
73 | * @brief Read a key from a profile | ||||
74 | * @param profileName: name of the profile you want to read from. | ||||
75 | * @param key: the Key you want to read | ||||
76 | * @return The value of the requested Key | ||||
77 | * @sa readProfile() | ||||
78 | */ | ||||
79 | Q_INVOKABLE QVariant readKey(const QString &profileName, const MachineInfo::KEY key) const; | ||||
80 | | ||||
81 | /** | ||||
82 | * @brief Store a new profile, Must be used for new profiles. | ||||
83 | * @param profile: A complete machine profile or one that at very least has MachineInfo::Name and any other valid Key. | ||||
84 | * @sa storeKey() | ||||
85 | */ | ||||
86 | Q_INVOKABLE void storeProfile(const QMap<MachineInfo::KEY, QVariant> &profile) const; | ||||
87 | | ||||
88 | /** | ||||
89 | * @brief Store a key to an existing profile, Sending a key of Key::NAME will rename the profile | ||||
90 | * @param profileName: profile to write into | ||||
91 | * @param key: The key you will write to | ||||
92 | * @param value: The value you will store. | ||||
93 | * @return true if successful | ||||
94 | * @sa storeProfile() | ||||
95 | */ | ||||
96 | Q_INVOKABLE bool storeKey(const QString &profileName, const MachineInfo::KEY key, const QVariant &value) const; | ||||
97 | | ||||
98 | /** | ||||
99 | * @brief copyies a profile and optionally deletes the src profile | ||||
100 | * @param srcProfile: profiles Current Name | ||||
101 | * @param destProfile: profiles New Name | ||||
102 | * @param rmSrc: delete srcProfile (defalut false) | ||||
103 | * @return true if successful | ||||
104 | */ | ||||
105 | Q_INVOKABLE bool copyProfile(const QString &srcProfile, const QString &destProfile, bool rmSrc = false) const; | ||||
106 | /** | ||||
107 | * @brief Remove a full profile | ||||
108 | * @param profileName: name of the profile you want to remove. | ||||
109 | * @return true if successful. | ||||
110 | */ | ||||
111 | Q_INVOKABLE bool removeProfile(const QString &profileName) const; | ||||
112 | | ||||
113 | /** | ||||
114 | * @brief Get a list of all the profile names | ||||
115 | * @return QStringList containing the stored profile names. | ||||
116 | */ | ||||
117 | Q_INVOKABLE QStringList profileNames() const; | ||||
118 | | ||||
119 | signals: | ||||
120 | /** | ||||
121 | * @brief A profile has changed | ||||
122 | */ | ||||
123 | void profilesChanged() const; | ||||
124 | | ||||
125 | private: | ||||
126 | MachineInfo *operator = (MachineInfo &other) = delete; | ||||
127 | MachineInfo(const MachineInfo &other) = delete; | ||||
128 | explicit MachineInfo(QObject *parent = nullptr); | ||||
129 | ~MachineInfo() = default; | ||||
130 | | ||||
131 | /** | ||||
132 | * @brief used to hold MachineInfo::KEY name and defaultValues. | ||||
133 | */ | ||||
134 | struct keyInfo { | ||||
135 | QString name; //!< Key name used in the settings file | ||||
136 | QVariant defaultValue; //!< Defaut Value for the key | ||||
137 | }; | ||||
138 | /** | ||||
139 | * @brief Map of MachineInfo::KEY , KeyString and DefaultValue | ||||
140 | */ | ||||
patrickelectric: is there a need to be a pointer ? | |||||
@rizzitello ping ^ patrickelectric: @rizzitello ping ^ | |||||
It is a pointer because At creation time we can automaticly set the paths for settings without any additional code. If you make this a regular object you have to do this via QSettings::setPath and the docs for that say "Warning: This function doesn't affect existing QSettings objects.". So now we can't make it a class member at all and instead in our code we have to have some kind of settings* return for access across the object. I've tried several ways to make it just a QSettings object but it does not even build correctly when its not used as a pointer. rizzitello: It is a pointer because At creation time we can automaticly set the paths for settings without… | |||||
141 | static const QMap<MachineInfo::KEY, MachineInfo::keyInfo> decoderMap; | ||||
142 | | ||||
143 | /** | ||||
144 | * @brief m_settings our settings object. | ||||
145 | */ | ||||
146 | | ||||
147 | QSettings *m_settings = nullptr; | ||||
148 | }; |
this should be a namespace or a enum class