2021-02-20 16:20:18 +08:00
|
|
|
#include <QJSValueIterator>
|
|
|
|
|
2021-02-09 15:54:22 +08:00
|
|
|
#include "DoricSuperNode.h"
|
2021-02-19 19:01:31 +08:00
|
|
|
|
|
|
|
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|
|
|
if (name == "subviews") {
|
|
|
|
if (prop.isArray()) {
|
2021-02-20 16:20:18 +08:00
|
|
|
const int length = prop.property("length").toInt();
|
|
|
|
for (int i = 0; i < length; ++i) {
|
|
|
|
QJSValue subNode = prop.property(i);
|
|
|
|
mixinSubNode(subNode);
|
|
|
|
blendSubNode(subNode);
|
|
|
|
}
|
2021-02-19 19:01:31 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoricViewNode::blend(view, name, prop);
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 16:20:18 +08:00
|
|
|
|
|
|
|
void DoricSuperNode::mixinSubNode(QJSValue subNode) {
|
|
|
|
QString id = subNode.property("id").toString();
|
|
|
|
qCritical() << id;
|
|
|
|
QList<QString> keys = subNodes.keys();
|
2021-02-22 16:42:19 +08:00
|
|
|
if (!keys.contains(id)) {
|
2021-02-20 16:20:18 +08:00
|
|
|
subNodes.insert(id, subNode);
|
|
|
|
} else {
|
|
|
|
mixin(subNode, subNodes.value(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoricSuperNode::mixin(QJSValue src, QJSValue target) {
|
|
|
|
QJSValue srcProps = src.property("props");
|
|
|
|
QJSValue targetProps = target.property("props");
|
|
|
|
QJSValueIterator it(srcProps);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
|
|
|
|
if (it.name() == "subviews" && it.value().isArray()) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
targetProps.setProperty(it.name(), it.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QJSValue DoricSuperNode::getSubModel(QString id) {
|
|
|
|
if (subNodes.keys().contains(id)) {
|
|
|
|
return subNodes.value(id);
|
|
|
|
} else {
|
|
|
|
return QJSValue::UndefinedValue;
|
|
|
|
}
|
|
|
|
}
|