-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathComponent.cpp
45 lines (39 loc) · 1.01 KB
/
Component.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
#include "Component.h"
// 组件类
static std::map<QString, QVariant> defaultProp = {
{"enabled", true},
};
QVariant Component::getProp(const QString & key)
{
if (properties.count(key) > 0) {
return properties[key];
}
if (defaultProp.count(key) > 0) {
return defaultProp[key];
}
throw "no such property!";
}
void Component::setProp(const QString & key, const QVariant& value)
{
QVariant original = getProp(key);
if (original != value) {
properties[key] = value;
onPropertyChange(key, original);
}
}
std::vector<QString> Component::getPropKeys()
{
std::vector<QString> res;
for (auto& pair : defaultProp) {
res.push_back(pair.first);
}
res.insert(res.end(), propertyKeys.begin(), propertyKeys.end());
return res;
}
void Component::defProp(const QString & key, const QVariant & init)
{
assert(properties.count(key) == 0);
assert(defaultProp.count(key) == 0);
properties[key] = init;
propertyKeys.push_back(key);
}