impl blend in group, super & view
This commit is contained in:
parent
ea0b87df24
commit
65d6f97908
@ -66,8 +66,7 @@ QObject *DoricContext::obtainPlugin(QString name) {
|
|||||||
if (mPluginMap.keys().contains(name)) {
|
if (mPluginMap.keys().contains(name)) {
|
||||||
return mPluginMap.value(name);
|
return mPluginMap.value(name);
|
||||||
} else {
|
} else {
|
||||||
QObject *plugin =
|
QObject *plugin = getDriver()->getRegistry()->plugins.createObject(name);
|
||||||
getDriver()->getRegistry()->pluginInfoMap.createObject(name);
|
|
||||||
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
|
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
|
||||||
mPluginMap.insert(name, plugin);
|
mPluginMap.insert(name, plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
|
@ -7,5 +7,5 @@ DoricRegistry::DoricRegistry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DoricRegistry::acquirePluginInfo(QString name) {
|
bool DoricRegistry::acquirePluginInfo(QString name) {
|
||||||
return pluginInfoMap.acquireClass(name);
|
return plugins.acquireClass(name);
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,17 @@
|
|||||||
|
|
||||||
class DoricRegistry {
|
class DoricRegistry {
|
||||||
public:
|
public:
|
||||||
DoricObjectFactory pluginInfoMap;
|
DoricObjectFactory plugins;
|
||||||
|
DoricObjectFactory nodes;
|
||||||
|
|
||||||
DoricRegistry();
|
DoricRegistry();
|
||||||
|
|
||||||
template <typename T> void registerNativePlugin(QString name) {
|
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);
|
bool acquirePluginInfo(QString name);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!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>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -20,9 +20,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
|
|||||||
Q_ARG(QJSValue, jsValue),
|
Q_ARG(QJSValue, jsValue),
|
||||||
Q_ARG(QString, callbackId));
|
Q_ARG(QString, callbackId));
|
||||||
}
|
}
|
||||||
qDebug() << "contextId: " + contextId;
|
qDebug() << "contextId: " + contextId << "module: " + module
|
||||||
qDebug() << "module: " + module;
|
<< "methodName: " + methodName << "callbackId: " + callbackId
|
||||||
qDebug() << "methodName: " + methodName;
|
<< "jsValue: " + jsValue.toString();
|
||||||
qDebug() << "callbackId: " + callbackId;
|
|
||||||
qDebug() << "jsValue: " + jsValue.toString();
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "DoricShaderPlugin.h"
|
#include "DoricShaderPlugin.h"
|
||||||
|
|
||||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||||
qDebug() << getContext();
|
|
||||||
getContext()->getDriver()->asyncCall(
|
getContext()->getDriver()->asyncCall(
|
||||||
[this, jsValue] {
|
[this, jsValue] {
|
||||||
QString viewId = jsValue.property("id").toString();
|
QString viewId = jsValue.property("id").toString();
|
||||||
|
@ -4,9 +4,16 @@ void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|||||||
if (name == "children") {
|
if (name == "children") {
|
||||||
mChildViewIds.clear();
|
mChildViewIds.clear();
|
||||||
if (prop.isArray()) {
|
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 {
|
} else {
|
||||||
|
qCritical() << "group node blend";
|
||||||
DoricSuperNode::blend(view, name, prop);
|
DoricSuperNode::blend(view, name, prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16,4 +23,35 @@ void DoricGroupNode::blend(QJSValue jsValue) {
|
|||||||
configChildNode();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,6 +17,8 @@ protected:
|
|||||||
QList<QString> mChildViewIds;
|
QList<QString> mChildViewIds;
|
||||||
|
|
||||||
void configChildNode();
|
void configChildNode();
|
||||||
|
|
||||||
|
virtual void blendSubNode(QJSValue subProperties) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICGROUPNODE_H
|
#endif // DORICGROUPNODE_H
|
||||||
|
@ -1,11 +1,53 @@
|
|||||||
|
#include <QJSValueIterator>
|
||||||
|
|
||||||
#include "DoricSuperNode.h"
|
#include "DoricSuperNode.h"
|
||||||
|
|
||||||
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
||||||
if (name == "subviews") {
|
if (name == "subviews") {
|
||||||
if (prop.isArray()) {
|
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 {
|
} else {
|
||||||
|
qCritical() << "super node blend";
|
||||||
DoricViewNode::blend(view, name, prop);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,16 +4,27 @@
|
|||||||
#include "DoricViewNode.h"
|
#include "DoricViewNode.h"
|
||||||
|
|
||||||
class DoricSuperNode : public DoricViewNode {
|
class DoricSuperNode : public DoricViewNode {
|
||||||
|
private:
|
||||||
|
QMap<QString, QJSValue> subNodes;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJSValue prop) override;
|
||||||
|
|
||||||
void blendSubLayoutConfig(DoricViewNode *viewNode);
|
void blendSubLayoutConfig(DoricViewNode *viewNode);
|
||||||
|
|
||||||
|
virtual void blendSubNode(QJSValue subProperties) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using DoricViewNode::DoricViewNode;
|
using DoricViewNode::DoricViewNode;
|
||||||
|
|
||||||
bool mReusable = false;
|
bool mReusable = false;
|
||||||
|
|
||||||
|
QJSValue getSubModel(QString id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void mixinSubNode(QJSValue subNode);
|
||||||
|
|
||||||
|
void mixin(QJSValue src, QJSValue target);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSUPERNODE_H
|
#endif // DORICSUPERNODE_H
|
||||||
|
@ -23,14 +23,22 @@ void DoricViewNode::setId(QString id) { mId = id; }
|
|||||||
|
|
||||||
void DoricViewNode::blend(QJSValue jsValue) {
|
void DoricViewNode::blend(QJSValue jsValue) {
|
||||||
QJSValueIterator it(jsValue);
|
QJSValueIterator it(jsValue);
|
||||||
|
QMap<QString, QJSValue> values;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
qDebug() << it.name() << ": " << it.value().toString();
|
values.insert(it.name(), it.value());
|
||||||
blend(mView, 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) {
|
void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
||||||
|
qCritical() << "view node blend";
|
||||||
if (name == "width") {
|
if (name == "width") {
|
||||||
|
|
||||||
} else if (name == "height") {
|
} else if (name == "height") {
|
||||||
|
Reference in New Issue
Block a user