This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/shader/DoricSuperNode.cpp
2021-05-20 18:27:45 +08:00

54 lines
1.3 KiB
C++

#include <QJSValueIterator>
#include "DoricSuperNode.h"
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
if (name == "subviews") {
if (prop.isArray()) {
const int length = prop.property("length").toInt();
for (int i = 0; i < length; ++i) {
QJSValue subNode = prop.property(i);
mixinSubNode(subNode);
blendSubNode(subNode);
}
}
} else {
qCritical() << "super node blend";
DoricViewNode::blend(view, name, prop);
}
}
void DoricSuperNode::mixinSubNode(QJSValue subNode) {
QString id = subNode.property("id").toString();
qCritical() << id;
QList<QString> keys = subNodes.keys();
if (keys.contains(id)) {
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;
}
}