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 | | ||||
30 | class ATCORE_EXPORT MachineInfo : public QObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | public: | ||||
34 | /** | ||||
35 | * @brief KEYS enum Possible keys for the printer settings | ||||
36 | */ | ||||
37 | enum class KEY { | ||||
38 | NAME = 0, //!< Profile Name | ||||
patrickelectric: this should be a namespace or a enum class | |||||
39 | BAUDRATE, //!< Machine BAUD Rate | ||||
patrickelectric: Start the first one as zero, we may add something before name | |||||
40 | FIRMWARE, //!<Firmware name | ||||
41 | MAXBEDTEMP, //!<Maximum Bed Temperature | ||||
42 | MAXEXTTEMP, //!<Maximum Extruder Temperature | ||||
43 | POSTPAUSE, //!<Post Pause Commands | ||||
44 | ISCARTESIAN, //!<Is the machine Cartesian | ||||
45 | XMAX, //!<X Size for Cartesian machines, Radius for Deltas. | ||||
46 | YMAX, //!<Y Size | ||||
47 | ZMAX, //!<Z Size for Cartesian machines, Height for Deltas. | ||||
48 | AUTOTEMPREPORT //!<Supports AutoTemp Reporting. | ||||
patrickelectric: comma in the end | |||||
49 | }; | ||||
50 | Q_ENUM(KEY) | ||||
51 | | ||||
patrickelectric: NICE | |||||
52 | /** | ||||
53 | * @brief get a Referance to the MachineInfo Instance, | ||||
54 | * In QML create a contextProperty of MachineInfo::getInstance() to use. | ||||
55 | */ | ||||
56 | static const MachineInfo &getInstance(); | ||||
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… | |||||
57 | | ||||
58 | /** | ||||
59 | * @brief Read a full profile | ||||
60 | * @param profileName: name of the profile you want to read. | ||||
patrickelectric: When you are a QObject copy is not allowed, this looks unnecessary. | |||||
61 | * @return A full map of the profile | ||||
patrickelectric: why this is public ? | |||||
62 | * @sa readKey() | ||||
63 | */ | ||||
64 | Q_INVOKABLE QVariantMap readProfile(const QString &profileName) const; | ||||
65 | | ||||
66 | /** | ||||
67 | * @brief Read a key from a profile | ||||
68 | * @param profileName: name of the profile you want to read from. | ||||
69 | * @param key: the Key you want to read | ||||
70 | * @return The value of the requested Key | ||||
71 | * @sa readProfile() | ||||
72 | */ | ||||
73 | Q_INVOKABLE QVariant readKey(const QString &profileName, const MachineInfo::KEY key) const; | ||||
74 | | ||||
75 | /** | ||||
76 | * @brief Store a new profile, Must be used for new profiles. | ||||
77 | * @param profile: A complete machine profile or one that at very least has MachineInfo::Name and any other valid Key. | ||||
78 | * @sa storeKey() | ||||
79 | */ | ||||
80 | Q_INVOKABLE void storeProfile(const QMap<MachineInfo::KEY, QVariant> &profile) const; | ||||
81 | | ||||
82 | /** | ||||
83 | * @brief Store a key to an existing profile, Sending a key of Key::NAME will rename the profile | ||||
84 | * @param profileName: profile to write into | ||||
85 | * @param key: The key you will write to | ||||
86 | * @param value: The value you will store. | ||||
87 | * @return true if successful | ||||
88 | * @sa storeProfile() | ||||
89 | */ | ||||
90 | Q_INVOKABLE bool storeKey(const QString &profileName, const MachineInfo::KEY key, const QVariant &value) const; | ||||
91 | | ||||
92 | /** | ||||
93 | * @brief copyies a profile and optionally deletes the src profile | ||||
94 | * @param srcProfile: profiles Current Name | ||||
95 | * @param destProfile: profiles New Name | ||||
96 | * @param rmSrc: delete srcProfile (defalut false) | ||||
97 | * @return true if successful | ||||
98 | */ | ||||
99 | Q_INVOKABLE bool copyProfile(const QString &srcProfile, const QString &destProfile, bool rmSrc = false) const; | ||||
100 | /** | ||||
101 | * @brief Remove a full profile | ||||
102 | * @param profileName: name of the profile you want to remove. | ||||
103 | * @return true if successful. | ||||
104 | */ | ||||
105 | Q_INVOKABLE bool removeProfile(const QString &profileName) const; | ||||
106 | | ||||
107 | /** | ||||
108 | * @brief Get a list of all the profile names | ||||
109 | * @return QStringList containing the stored profile names. | ||||
110 | */ | ||||
111 | Q_INVOKABLE QStringList profileNames() const; | ||||
112 | | ||||
113 | signals: | ||||
114 | /** | ||||
115 | * @brief A profile has changed | ||||
116 | */ | ||||
117 | void profilesChanged() const; | ||||
118 | | ||||
119 | private: | ||||
120 | explicit MachineInfo(QObject *parent = nullptr); | ||||
121 | ~MachineInfo() = default; | ||||
122 | | ||||
123 | /** | ||||
124 | * @brief used to hold MachineInfo::KEY name and defaultValues. | ||||
125 | */ | ||||
126 | struct keyInfo { | ||||
127 | QString name; //!< Key name used in the settings file | ||||
128 | QVariant defaultValue; //!< Defaut Value for the key | ||||
129 | }; | ||||
130 | /** | ||||
131 | * @brief Map of MachineInfo::KEY , KeyString and DefaultValue | ||||
132 | */ | ||||
133 | static const QMap<MachineInfo::KEY, MachineInfo::keyInfo> decoderMap; | ||||
134 | | ||||
135 | /** | ||||
136 | * @brief m_settings our settings object. | ||||
137 | */ | ||||
138 | | ||||
139 | QSettings *m_settings = nullptr; | ||||
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… |
this should be a namespace or a enum class