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 | | ||||
26 | #include <QObject> | ||||
27 | #include <QSettings> | ||||
28 | | ||||
29 | class MachineInfo : public QObject | ||||
30 | { | ||||
31 | Q_OBJECT | ||||
32 | public: | ||||
33 | /** | ||||
34 | * @brief KEYS enum Possible keys for the printer settings | ||||
35 | */ | ||||
36 | enum KEY { | ||||
37 | NAME, //!< Profile Name | ||||
38 | BAUDRATE, //!< Machine BAUD Rate | ||||
patrickelectric: this should be a namespace or a enum class | |||||
39 | FIRMWARE, //!<Firmware name | ||||
patrickelectric: Start the first one as zero, we may add something before name | |||||
40 | MAXBEDTEMP, //!<Maximum Bed Temperature | ||||
41 | MAXEXTTEMP, //!<Maximum Extruder Temperature | ||||
42 | POSTPAUSE, //!<Post Pause Commands | ||||
43 | HEATEDBED, //!<Machine has heated bed | ||||
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. | ||||
49 | }; | ||||
patrickelectric: comma in the end | |||||
50 | Q_ENUM(KEY) | ||||
51 | | ||||
patrickelectric: NICE | |||||
52 | /** | ||||
53 | * @brief get MachineInfo Instance | ||||
54 | */ | ||||
55 | static const MachineInfo &getInstance(); | ||||
56 | MachineInfo(const MachineInfo &) = delete; | ||||
57 | MachineInfo(MachineInfo &&) = delete; | ||||
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 | MachineInfo &operator=(const MachineInfo &) = delete; | ||||
59 | MachineInfo &operator=(MachineInfo &&) = delete; | ||||
60 | ~MachineInfo() = default; | ||||
patrickelectric: When you are a QObject copy is not allowed, this looks unnecessary. | |||||
61 | Q_INVOKABLE QVariantMap profile(const QString &profileName) const; | ||||
patrickelectric: why this is public ? | |||||
62 | Q_INVOKABLE void storeProfile(const QMap<MachineInfo::KEY, QVariant> &profile) const; | ||||
63 | Q_INVOKABLE QStringList profileNames() const; | ||||
64 | | ||||
65 | signals: | ||||
66 | /** | ||||
67 | * @brief A profile has changed | ||||
68 | * @param changedProfileName: name of changed profile. | ||||
69 | */ | ||||
70 | void profileChanged(const QString &changedProfileName) const; | ||||
71 | | ||||
72 | private: | ||||
73 | explicit MachineInfo(QObject *parent = nullptr); | ||||
74 | /** | ||||
75 | * @brief Map of MachineInfo::KEY -> QString | ||||
76 | */ | ||||
77 | static const QMap<MachineInfo::KEY, QString> nameMap; | ||||
78 | | ||||
79 | /** | ||||
80 | * @brief m_settings our settings object. | ||||
81 | */ | ||||
82 | QSettings *m_settings = nullptr; | ||||
83 | | ||||
84 | }; | ||||
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