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/example/doric/shader/DoricSuperNode.cpp

94 lines
2.6 KiB
C++
Raw Permalink Normal View History

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
2021-04-02 20:47:15 +08:00
void DoricSuperNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
2021-02-19 19:01:31 +08:00
if (name == "subviews") {
if (prop.isArray()) {
2021-04-02 20:47:15 +08:00
QJsonArray array = prop.toArray();
const int length = array.size();
2021-02-20 16:20:18 +08:00
for (int i = 0; i < length; ++i) {
2021-04-02 20:47:15 +08:00
QJsonValue subNode = array.at(i);
2021-02-20 16:20:18 +08:00
mixinSubNode(subNode);
blendSubNode(subNode);
}
2021-06-15 17:36:01 +08:00
getLayouts()->setResolved(false);
2021-02-19 19:01:31 +08:00
}
} else {
DoricViewNode::blend(view, name, prop);
}
}
2021-02-20 16:20:18 +08:00
2021-06-02 16:34:38 +08:00
void DoricSuperNode::blendSubNode(DoricViewNode *subNode,
QJsonValue layoutConfig) {
subNode->blendLayoutConfig(layoutConfig);
}
2021-04-02 20:47:15 +08:00
void DoricSuperNode::mixinSubNode(QJsonValue subNode) {
QString id = subNode["id"].toString();
2021-02-20 16:20:18 +08:00
QList<QString> keys = subNodes.keys();
if (!keys.contains(id)) {
2021-02-20 16:20:18 +08:00
subNodes.insert(id, subNode);
} else {
mixin(subNode, subNodes.value(id));
}
}
2021-04-02 20:47:15 +08:00
void DoricSuperNode::mixin(QJsonValue src, QJsonValue target) {
QJsonValue srcProps = src["props"];
QJsonValue targetProps = target["props"];
2021-02-20 16:20:18 +08:00
2021-04-02 20:47:15 +08:00
foreach (const QString &key, srcProps.toObject().keys()) {
QJsonValue value = srcProps[key];
if (key == "subviews" && value.isArray()) {
2021-02-20 16:20:18 +08:00
} else {
2021-04-02 20:47:15 +08:00
targetProps.toObject().insert(key, value);
2021-02-20 16:20:18 +08:00
}
}
}
2021-04-02 20:47:15 +08:00
QJsonValue DoricSuperNode::getSubModel(QString id) {
2021-02-20 16:20:18 +08:00
if (subNodes.keys().contains(id)) {
return subNodes.value(id);
} else {
2021-04-02 20:47:15 +08:00
return QJsonValue::Undefined;
2021-02-20 16:20:18 +08:00
}
}
2021-03-02 17:18:23 +08:00
void DoricSuperNode::blendSubLayoutConfig(DoricViewNode *viewNode,
2021-04-02 20:47:15 +08:00
QJsonValue jsValue) {
2021-03-02 17:18:23 +08:00
viewNode->blendLayoutConfig(jsValue);
}
2021-05-07 18:17:07 +08:00
bool DoricSuperNode::viewIdIsEqual(QJsonValue src, QJsonValue target) {
QString srcId = src["id"].toString();
QString targetId = target["id"].toString();
return srcId == targetId;
}
void DoricSuperNode::recursiveMixin(QJsonValue src, QJsonValue target) {
QJsonObject srcProps = src["props"].toObject();
QJsonObject targetProps = target["props"].toObject();
QJsonValue oriSubviews = targetProps["subviews"];
for (QString key : srcProps.keys()) {
QJsonValue jsValue = srcProps[key];
if ("subviews" == key && jsValue.isArray()) {
QJsonArray subviews = jsValue.toArray();
for (QJsonValue subview : subviews) {
if (oriSubviews.isArray()) {
for (QJsonValue targetSubview : oriSubviews.toArray()) {
if (viewIdIsEqual(subview, targetSubview)) {
recursiveMixin(subview, targetSubview);
break;
}
}
}
}
continue;
}
targetProps.insert(key, jsValue);
}
}