impl blend in group, super & view

This commit is contained in:
王劲鹏 2021-02-20 16:20:18 +08:00 committed by osborn
parent ea0b87df24
commit 65d6f97908
11 changed files with 119 additions and 17 deletions

View File

@ -66,8 +66,7 @@ QObject *DoricContext::obtainPlugin(QString name) {
if (mPluginMap.keys().contains(name)) {
return mPluginMap.value(name);
} else {
QObject *plugin =
getDriver()->getRegistry()->pluginInfoMap.createObject(name);
QObject *plugin = getDriver()->getRegistry()->plugins.createObject(name);
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
mPluginMap.insert(name, plugin);
return plugin;

View File

@ -7,5 +7,5 @@ DoricRegistry::DoricRegistry() {
}
bool DoricRegistry::acquirePluginInfo(QString name) {
return pluginInfoMap.acquireClass(name);
return plugins.acquireClass(name);
}

View File

@ -7,12 +7,17 @@
class DoricRegistry {
public:
DoricObjectFactory pluginInfoMap;
DoricObjectFactory plugins;
DoricObjectFactory nodes;
DoricRegistry();
template <typename T> void registerNativePlugin(QString name) {
pluginInfoMap.registerClass<T>(name);
plugins.registerClass<T>(name);
}
template <typename T> void registerViewNode(QString name) {
nodes.registerClass<T>(name);
}
bool acquirePluginInfo(QString name);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.14.0, 2021-02-19T18:27:52. -->
<!-- Written by QtCreator 4.14.0, 2021-02-20T15:28:06. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -20,9 +20,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
Q_ARG(QJSValue, jsValue),
Q_ARG(QString, callbackId));
}
qDebug() << "contextId: " + contextId;
qDebug() << "module: " + module;
qDebug() << "methodName: " + methodName;
qDebug() << "callbackId: " + callbackId;
qDebug() << "jsValue: " + jsValue.toString();
qDebug() << "contextId: " + contextId << "module: " + module
<< "methodName: " + methodName << "callbackId: " + callbackId
<< "jsValue: " + jsValue.toString();
}

View File

@ -4,7 +4,6 @@
#include "DoricShaderPlugin.h"
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
qDebug() << getContext();
getContext()->getDriver()->asyncCall(
[this, jsValue] {
QString viewId = jsValue.property("id").toString();

View File

@ -4,9 +4,16 @@ void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) {
if (name == "children") {
mChildViewIds.clear();
if (prop.isArray()) {
qDebug() << prop.toString();
const int length = prop.property("length").toInt();
for (int i = 0; i < length; ++i) {
QJSValue value = prop.property(i);
if (value.isString()) {
mChildViewIds.append(value.toString());
}
}
}
} else {
qCritical() << "group node blend";
DoricSuperNode::blend(view, name, prop);
}
}
@ -16,4 +23,35 @@ void DoricGroupNode::blend(QJSValue jsValue) {
configChildNode();
}
void DoricGroupNode::configChildNode() {}
void DoricGroupNode::configChildNode() {
for (int idx = 0; idx < mChildViewIds.size(); idx++) {
QString id = mChildViewIds.at(idx);
QJSValue model = getSubModel(id);
if (model.isUndefined()) {
// getContext()->getDriver()->getRegistry();
continue;
}
QString type = model.property("type").toString();
if (idx < mChildNodes.size()) {
DoricViewNode *oldNode = mChildNodes.at(idx);
if (id == oldNode->getId()) {
// The same, skip
if (mReusable) {
} else {
}
}
} else {
// Insert
}
}
}
void DoricGroupNode::blendSubNode(QJSValue subProperties) {
QString subNodeId = subProperties.property("id").toString();
for (DoricViewNode *node : mChildNodes) {
if (subNodeId == node->getId()) {
node->blend(subProperties.property("props"));
break;
}
}
}

View File

@ -17,6 +17,8 @@ protected:
QList<QString> mChildViewIds;
void configChildNode();
virtual void blendSubNode(QJSValue subProperties) override;
};
#endif // DORICGROUPNODE_H

View File

@ -1,11 +1,53 @@
#include <QJSValueIterator>
#include "DoricSuperNode.h"
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
if (name == "subviews") {
if (prop.isArray()) {
qDebug() << prop.toString();
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;
}
}

View File

@ -4,16 +4,27 @@
#include "DoricViewNode.h"
class DoricSuperNode : public DoricViewNode {
private:
QMap<QString, QJSValue> subNodes;
protected:
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
void blendSubLayoutConfig(DoricViewNode *viewNode);
virtual void blendSubNode(QJSValue subProperties) = 0;
public:
using DoricViewNode::DoricViewNode;
bool mReusable = false;
QJSValue getSubModel(QString id);
private:
void mixinSubNode(QJSValue subNode);
void mixin(QJSValue src, QJSValue target);
};
#endif // DORICSUPERNODE_H

View File

@ -23,14 +23,22 @@ void DoricViewNode::setId(QString id) { mId = id; }
void DoricViewNode::blend(QJSValue jsValue) {
QJSValueIterator it(jsValue);
QMap<QString, QJSValue> values;
while (it.hasNext()) {
it.next();
qDebug() << it.name() << ": " << it.value().toString();
blend(mView, it.name(), it.value());
values.insert(it.name(), it.value());
}
auto keys = values.keys();
for (const QString &key : keys) {
qCritical() << key << ": " << values.value(key).toString();
qCritical() << mView;
blend(mView, key, values.value(key));
}
}
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
qCritical() << "view node blend";
if (name == "width") {
} else if (name == "height") {