-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintersetting.cpp
More file actions
80 lines (63 loc) · 2.34 KB
/
printersetting.cpp
File metadata and controls
80 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "printersetting.h"
#include <QFile>
#include <QJsonArray>
#include <QJsonObject>
#include <QDebug>
using namespace Hix::Common;
constexpr auto _filePath = "/opt/capsuleFW/capsuleSetting.json";
PrinterSetting::PrinterSetting() : Hix::Common::Json::JsonSetting (_filePath)
{
}
PrinterSetting::~PrinterSetting()
{
}
void PrinterSetting::parse()
{
try {
QJsonObject UVTimeSpendObject = Json::getValue<QJsonObject>(_object,"UV_time_spend");
for(auto &i : UVTimeSpendObject.keys()){
UVTimeSpend.insert(i,Json::getValue<int>(UVTimeSpendObject,i));
}
QJsonObject motorTimeSpendObject = Json::getValue<QJsonObject>(_object,"motor_time_spend");
for(auto &i : motorTimeSpendObject.keys()){
UVTimeSpend.insert(i,Json::getValue<int>(motorTimeSpendObject,i));
}
materialList = Json::getValueArray<QString>(_object,"material_list");
enableMaterialList = Json::getValueArray<QString>(_object,"enable_material_list");
defaultHeight = Json::getValue<int>(_object,"default_height");
heightOffset = Json::getValue<int>(_object,"height_offset");
ledOffset = Json::getValue<double>(_object,"led_offset");
} catch (std::runtime_error &e) {
qDebug() << e.what();
}
}
void PrinterSetting::save()
{
QJsonObject jo;
QFile saveFile(_path);
QJsonObject UVTimeSpendObject;
for(auto &i : UVTimeSpend.keys()){
Json::setValue<int>(UVTimeSpendObject,i,UVTimeSpend[i]);
}
Hix::Common::Json::setValue<QJsonObject>(jo,"UV_time_spend",UVTimeSpendObject);
QJsonObject motorTimeSpendObject;
for(auto &i : motorTimeSpend.keys()){
Json::setValue<int>(motorTimeSpendObject,i,motorTimeSpend[i]);
}
Hix::Common::Json::setValue<QJsonObject>(jo,"motor_time_spend",motorTimeSpendObject);
Json::setValueArray<QString>(jo,"material_list",materialList);
Json::setValueArray<QString>(jo,"enable_material_list",enableMaterialList);
Json::setValue(jo,"default_height",defaultHeight);
Json::setValue(jo,"height_offset",heightOffset);
Json::setValue(jo,"led_offset",ledOffset);
if(!saveFile.open(QIODevice::WriteOnly)){
qDebug() << "save file open error";
}
_object = jo;
QJsonDocument saveDoc(jo);
saveFile.write(saveDoc.toJson());
}
QString PrinterSetting::serialize()
{
return "";
}