-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJsonHelpers.h
89 lines (68 loc) · 2.17 KB
/
JsonHelpers.h
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
#ifndef JSONHELPERS_H
#define JSONHELPERS_H
#include "metamodel/ConfigurationBitDescriptor.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QPointF>
namespace q2d {
// forward declarations
class Document;
class DocumentEntry;
class Project;
namespace gui {
class SchematicElement;
}
namespace metamodel {
class Category;
class ConfigBitGroupDescriptor;
class PortDescriptor;
}
// TODO move this to namespace json
// TODO adapt naming
QJsonObject SchematicsSceneChildToJson(gui::SchematicElement* ssc);
// TODO include document name in JSON
namespace json {
void writeJsonFile(QString path, QJsonDocument doc);
QJsonDocument readJsonFile(QString path);
QJsonDocument exportComponentHierarchy(QStandardItemModel* componentHierarchy);
// json -> *
metamodel::ConfigBitGroupDescriptor* toConfigBitGroupDescriptor(QJsonObject json);
metamodel::PortDescriptor* toPortDescriptor(QJsonObject json);
/**
* @brief toPoint converts a QJsonObject into a QPoint.
* If a coordinate is not present it will default to 0.
* @param json
* @return
*/
QPoint toPoint(QJsonObject json);
/**
* @brief toPointF converts a QJsonObject into a QPointF.
* If a coordinate is not present it will default to 0.
* @param json
* @return
*/
QPointF toPointF(QJsonObject json);
Document* toDocument(QJsonObject json, QString name, Project* parent);
/**
* @brief q2d::parseDocumentEntry
* The parsed DocumentEntry will automatically be added to the given document.
* @param json
* @param document
*/
void toDocumentEntry(QJsonObject json, Document* document); // TODO should return DocumentEntry*
// TODO fix parameters
metamodel::ComponentDescriptor* toComponentDescriptor (
const QJsonDocument jsonSource,
const QString filePath,
metamodel::Category* parent);
// * -> json
QJsonObject fromPoint(QPoint point);
QJsonObject fromPointF(QPointF point);
QJsonObject fromDocument(Document* doc);
QJsonObject fromDocumentEntry(DocumentEntry* entry);
QJsonObject fromHierarchyEntry(QStandardItem* item);
QJsonObject fromCategoryEntry(metamodel::Category* category);
QJsonObject fromTypeEntry(metamodel::ComponentDescriptor* descriptor);
} // namespace json
} // namespace q2d
#endif // JSONHELPERS_H