-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasset.cpp
More file actions
166 lines (146 loc) · 3.44 KB
/
asset.cpp
File metadata and controls
166 lines (146 loc) · 3.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "asset.h"
Asset::Asset()
{
props = new DOMNode();
SetS("_type", "asset");
// qDebug() << "Asset::Asset()" << props;
}
void Asset::SetV(const char * name, const QVector3D p)
{
if (props) {
props->SetV(name, p);
}
}
QVector3D Asset::GetV(const char * name) const
{
if (props) {
return props->GetV(name);
}
return QVector3D();
}
void Asset::SetV4(const char * name, const QVector4D p)
{
if (props) {
props->SetV4(name, p);
}
}
QVector4D Asset::GetV4(const char * name) const
{
if (props) {
return props->GetV4(name);
}
return QVector4D();
}
void Asset::SetF(const char * name, const float f)
{
if (props) {
props->setProperty(name, QString::number(f));
}
}
float Asset::GetF(const char * name) const
{
if (props) {
return props->property(name).toFloat();
}
return 0.0f;
}
void Asset::SetI(const char * name, const int i)
{
if (props) {
props->setProperty(name, QString::number(i));
}
}
int Asset::GetI(const char * name) const
{
if (props) {
return props->property(name).toInt();
}
return 0;
}
void Asset::SetB(const char * name, const bool b)
{
if (props) {
props->setProperty(name, b ? "true" : "false");
}
}
bool Asset::GetB(const char * name) const
{
if (props) {
return props->property(name).toString().toLower() == "true";
}
return false;
}
void Asset::SetS(const char * name, const QString s)
{
if (props) {
props->setProperty(name, s);
}
}
QString Asset::GetS(const char * name) const
{
if (props) {
return props->property(name).toString();
}
return QString();
}
void Asset::SetC(const char * name, const QColor c)
{
if (props) {
props->setProperty(name, MathUtil::GetColourAsString(c, false));
}
}
QColor Asset::GetC(const char * name) const
{
if (props) {
return MathUtil::GetStringAsColour(props->property(name).toString());
}
return QColor(255,255,255);
}
void Asset::SetSrc(const QString & base, const QString & src_str)
{
// qDebug() << "Asset::SetSrc" << base << src_str;
SetS("_base_url", base);
if (src_str.right(5) == "data:") {
SetS("src", src_str);
SetS("_src_url", "");
SetURL(src_str);
}
else {
SetS("src", src_str.trimmed());
SetS("_src_url", QUrl(base).resolved(src_str).toString());
SetURL(GetS("_src_url"));
}
}
void Asset::SetProperties(const QVariantMap & d)
{
QVariantMap::const_iterator it;
for (it=d.begin(); it!=d.end(); ++it) {
// qDebug() << " " << it.key() << it.value().toString();
if (!it.key().isEmpty()) {
props->setProperty(it.key().trimmed().toLower().toLatin1().data(), it.value());
}
}
}
QString Asset::GetXMLCode() const
{
QString s = QString("<") + GetS("_type");
QList <QByteArray> p = props->dynamicPropertyNames();
for (int i=0; i<p.size(); ++i) {
if (props->GetSaveAttribute(p[i].data(), false)) {
s += QString(" ") + QString(p[i]) + "=\"" + props->property(p[i]).toString() + "\"";
}
}
s += " />";
return s;
}
QVariantMap Asset::GetJSONCode() const
{
QVariantMap m;
QList <QByteArray> p = props->dynamicPropertyNames();
for (int i=0; i<p.size(); ++i) {
if (props->GetSaveAttribute(p[i].data(), false)) {
m[p[i]] = props->property(p[i]);
}
}
return m;
}