-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsobject.cpp
88 lines (74 loc) · 1.99 KB
/
sobject.cpp
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
#include "sobject.h"
#include <QMetaProperty>
#include <QVariant>
#include "smanager.h"
#include <QDebug>
SObject::SObject(QObject *parent) : QObject(parent)
{
}
class_id_t SObject::getClassId()
{
auto meta_object = this->metaObject();
return meta_object->className();
}
QString SObject::label() const
{
return this->property("objectName").toString();
}
void SObject::setLabel(const QString &label)
{
this->setProperty("objectName", label);
}
void SObject::serialize(QDataStream &out) const
{
this->writeProperties(out);
this->doWrite(out);
}
void SObject::deserialize(QDataStream &in)
{
this->readProperties(in);
this->doRead(in);
}
void SObject::dumpProperties() const
{
auto meta_object = this->metaObject();
auto property_count = meta_object->propertyCount();
for (int i = 0; i < property_count; ++i) {
auto property = meta_object->property(i);
auto property_name = property.name();
qDebug() << i + 1 << property_name << this->property(property_name);
}
}
SManager *SObject::manager() const
{
return qobject_cast<SManager *>(this->parent());
}
void SObject::writeProperties(QDataStream &out) const
{
auto meta_object = this->metaObject();
auto property_count = meta_object->propertyCount();
for (int i = 0; i < property_count; ++i) {
auto property = meta_object->property(i);
auto value = this->property(property.name());
out << value;
}
}
void SObject::doWrite(QDataStream &out) const
{
Q_UNUSED(out)
}
void SObject::readProperties(QDataStream &in)
{
auto meta_object = this->metaObject();
auto property_count = meta_object->propertyCount();
for (int i = 0; i < property_count; ++i) {
auto property = meta_object->property(i);
QVariant value;
in >> value;
this->setProperty(property.name(), value);
}
}
void SObject::doRead(QDataStream &in)
{
Q_UNUSED(in);
}