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-02-19 19:01:31 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoricViewNode::blend(view, name, prop);
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 16:20:18 +08:00
|
|
|
|
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();
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04-02 20:47:15 +08:00
|
|
|
|
|
|
|
QJsonValue DoricSuperNode::generateDefaultLayoutConfig() {
|
|
|
|
QJsonObject layoutConfig;
|
2021-04-06 11:19:48 +08:00
|
|
|
layoutConfig.insert("widthSpec", SpecMode::JUST);
|
|
|
|
layoutConfig.insert("heightSpec", SpecMode::JUST);
|
2021-04-02 20:47:15 +08:00
|
|
|
return layoutConfig;
|
|
|
|
}
|