-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
94 lines (77 loc) · 2.44 KB
/
Copy pathproject.cpp
File metadata and controls
94 lines (77 loc) · 2.44 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "project.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
ProjectParametrs::ProjectParametrs()
{
}
bool ProjectParametrs::saveProject(QString path)
{
QFile saveFile(path);
if (!saveFile.open(QIODevice::WriteOnly))
{
qWarning("Couldn't open save file.");
return false;
}
QJsonObject gameObject;
write(gameObject);
QJsonDocument saveDoc(gameObject);
saveFile.write(saveDoc.toJson());
return true;
}
bool ProjectParametrs::loadProject(QString path)
{
QFile loadFile(path);
if (!loadFile.open(QIODevice::ReadOnly))
{
qWarning("Couldn't open save file.");
return false;
}
QByteArray saveData = loadFile.readAll();
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
read(loadDoc.object());
return true;
}
void ProjectParametrs::read(const QJsonObject &json)
{
this->modelPath = json["modelPath"].toString();
this->heimapPath = json["heimapPath"].toString();
this->texturePath = json["texturePath"].toString();
this->texture2Path = json["texture2Path"].toString();
this->step = json["step"].toInt();
this->imgMinVal = json["imgMinVal"].toDouble();
this->imgMaxVal = json["imgMaxVal"].toDouble();
this->materialType = json["materialType"].toInt();
QJsonObject setts = json["searchingSettings"].toObject();
searchSetts.coof = setts["coof"].toDouble();
searchSetts.setDiametrMin(setts["diametrMin"].toInt());
searchSetts.setDiametrMax(setts["diametrMax"].toInt());
searchSetts.setHeightMin(setts["heightMin"].toDouble());
searchSetts.setHeightMax(setts["heightMax"].toDouble());
searchSetts.bottomProc = setts["bottom"].toDouble();
}
void ProjectParametrs::write(QJsonObject &json) const
{
json["modelPath"] = this->modelPath;
json["heimapPath"] = this->heimapPath;
json["texturePath"] = this->texturePath;
json["texture2Path"] = this->texture2Path;
json["step"] = this->step;
json["imgMaxVal"] = this->imgMaxVal;
json["imgMinVal"] = this->imgMinVal;
json["materialType"] = this->materialType;
QJsonObject setts;
setts["coof"] = searchSetts.coof;
setts["diametrMin"] = searchSetts.diamert.start;
setts["diametrMax"] = searchSetts.diamert.end;
setts["heightMin"] = searchSetts.height.start;
setts["heightMax"] = searchSetts.height.end;
setts["bottom"] = searchSetts.bottomProc;
json["searchingSettings"] = setts;
// QJsonObject setts;
// setts["coof"] = coof;
// setts.coof = coof;
// setts.diamert = {minD, maxD};
// setts.height = {minHei, maxHei};
// setts.bottomProc = bottomLineProc;
}