diff --git a/doric-Qt/doric/DoricRegistry.cpp b/doric-Qt/doric/DoricRegistry.cpp index 399d8519..f1337941 100644 --- a/doric-Qt/doric/DoricRegistry.cpp +++ b/doric-Qt/doric/DoricRegistry.cpp @@ -1,11 +1,20 @@ #include "DoricRegistry.h" #include "plugin/DoricShaderPlugin.h" +#include "shader/DoricRootNode.h" +#include "shader/DoricStackNode.h" DoricRegistry::DoricRegistry() { registerNativePlugin("shader"); + + registerViewNode("Root"); + registerViewNode("Stack"); } bool DoricRegistry::acquirePluginInfo(QString name) { return plugins.acquireClass(name); } + +bool DoricRegistry::acquireNodeInfo(QString name) { + return nodes.acquireClass(name); +} diff --git a/doric-Qt/doric/DoricRegistry.h b/doric-Qt/doric/DoricRegistry.h index 60af22c0..a054a538 100644 --- a/doric-Qt/doric/DoricRegistry.h +++ b/doric-Qt/doric/DoricRegistry.h @@ -21,6 +21,8 @@ public: } bool acquirePluginInfo(QString name); + + bool acquireNodeInfo(QString name); }; #endif // REGISTRY_H diff --git a/doric-Qt/doric/doric.pro.user b/doric-Qt/doric/doric.pro.user index 6984e5ec..f4bbc561 100644 --- a/doric-Qt/doric/doric.pro.user +++ b/doric-Qt/doric/doric.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/doric-Qt/doric/resources/panel.qml b/doric-Qt/doric/resources/panel.qml index caceacaa..7aef5fee 100644 --- a/doric-Qt/doric/resources/panel.qml +++ b/doric-Qt/doric/resources/panel.qml @@ -1,5 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -StackView { +Rectangle { + color: 'red' } diff --git a/doric-Qt/doric/shader/DoricGroupNode.cpp b/doric-Qt/doric/shader/DoricGroupNode.cpp index 2d207fbb..a37f063c 100644 --- a/doric-Qt/doric/shader/DoricGroupNode.cpp +++ b/doric-Qt/doric/shader/DoricGroupNode.cpp @@ -29,6 +29,7 @@ void DoricGroupNode::configChildNode() { QJSValue model = getSubModel(id); if (model.isUndefined()) { DoricRegistry *registry = getContext()->getDriver()->getRegistry(); + qCritical() << "model.isUndefined()"; continue; } QString type = model.property("type").toString(); @@ -37,7 +38,77 @@ void DoricGroupNode::configChildNode() { if (id == oldNode->getId()) { // The same, skip if (mReusable) { + if (oldNode->getType() == type) { + oldNode->setId(id); + oldNode->blend(model.property("props")); + } else { + mChildNodes.remove(idx); + oldNode->getNodeView()->setParent(nullptr); + oldNode->getNodeView()->setParentItem(nullptr); + oldNode->getNodeView()->deleteLater(); + + DoricViewNode *newNode = DoricViewNode::create(getContext(), type); + if (newNode != nullptr) { + newNode->setId(id); + newNode->init(this); + newNode->blend(model.property("props")); + mChildNodes.insert(idx, newNode); + + int minIndex = qMin(idx, mView->childItems().size()); + newNode->getNodeView()->setParentItem(mView); + newNode->getNodeView()->stackBefore( + mView->childItems().at(minIndex)); + } + } } else { + // Find in remain nodes + int position = -1; + for (int start = idx + 1; start < mChildNodes.size(); start++) { + DoricViewNode *node = mChildNodes.at(start); + if (id == node->getId()) { + // Found + position = start; + break; + } + if (position >= 0) { + // Found swap idx,position + DoricViewNode *reused = mChildNodes.at(position); + mChildNodes.removeAt(position); + + DoricViewNode *abandoned = mChildNodes.at(idx); + mChildNodes.insert(idx, reused); + mChildNodes.insert(position, abandoned); + + // View swap index + reused->getNodeView()->setParent(nullptr); + reused->getNodeView()->setParentItem(nullptr); + int minIndex = qMin(idx, mView->childItems().size()); + reused->getNodeView()->setParentItem(mView); + reused->getNodeView()->stackBefore( + mView->childItems().at(minIndex)); + + abandoned->getNodeView()->setParent(nullptr); + abandoned->getNodeView()->setParentItem(nullptr); + abandoned->getNodeView()->setParentItem(mView); + abandoned->getNodeView()->stackBefore( + mView->childItems().at(position)); + } else { + // Not found,insert + DoricViewNode *newNode = + DoricViewNode::create(getContext(), type); + if (newNode != nullptr) { + newNode->setId(id); + newNode->init(this); + newNode->blend(model.property("props")); + mChildNodes.insert(idx, newNode); + + int minIndex = qMin(idx, mView->childItems().size()); + newNode->getNodeView()->setParentItem(mView); + newNode->getNodeView()->stackBefore( + mView->childItems().at(minIndex)); + } + } + } } } } else { diff --git a/doric-Qt/doric/shader/DoricSuperNode.cpp b/doric-Qt/doric/shader/DoricSuperNode.cpp index 6a8ab0bd..c53cb9c4 100644 --- a/doric-Qt/doric/shader/DoricSuperNode.cpp +++ b/doric-Qt/doric/shader/DoricSuperNode.cpp @@ -22,7 +22,7 @@ void DoricSuperNode::mixinSubNode(QJSValue subNode) { QString id = subNode.property("id").toString(); qCritical() << id; QList keys = subNodes.keys(); - if (keys.contains(id)) { + if (!keys.contains(id)) { subNodes.insert(id, subNode); } else { mixin(subNode, subNodes.value(id)); diff --git a/doric-Qt/doric/shader/DoricViewNode.cpp b/doric-Qt/doric/shader/DoricViewNode.cpp index d2d2d14e..d01f2a72 100644 --- a/doric-Qt/doric/shader/DoricViewNode.cpp +++ b/doric-Qt/doric/shader/DoricViewNode.cpp @@ -21,26 +21,24 @@ QString DoricViewNode::getId() { return mId; } void DoricViewNode::setId(QString id) { mId = id; } +QString DoricViewNode::getType() { return mType; } + +QQuickItem *DoricViewNode::getNodeView() { return mView; } + void DoricViewNode::blend(QJSValue jsValue) { QJSValueIterator it(jsValue); - QMap values; while (it.hasNext()) { it.next(); - 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)); + blend(mView, it.name(), it.value()); } } void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) { qCritical() << "view node blend"; if (name == "width") { - + view->setWidth(100); } else if (name == "height") { + view->setHeight(100); + } else if (name == "backgroundColor") { } } diff --git a/doric-Qt/doric/shader/DoricViewNode.h b/doric-Qt/doric/shader/DoricViewNode.h index 2679de28..4ad088d0 100644 --- a/doric-Qt/doric/shader/DoricViewNode.h +++ b/doric-Qt/doric/shader/DoricViewNode.h @@ -29,10 +29,29 @@ public: void init(DoricSuperNode *superNode); + static DoricViewNode *create(DoricContext *context, QString type) { + bool classRegistered = + context->getDriver()->getRegistry()->acquireNodeInfo(type); + if (classRegistered) { + QObject *node = + context->getDriver()->getRegistry()->nodes.createObject(type); + DoricViewNode *castNode = dynamic_cast(node); + castNode->setContext(context); + castNode->mType = type; + return castNode; + } else { + return nullptr; + } + } + QString getId(); void setId(QString id); + QString getType(); + + QQuickItem *getNodeView(); + virtual void blend(QJSValue jsValue); virtual void blend(QQuickItem *view, QString name, QJSValue prop);