From 1c574f030cd8baa192ae782b433193e8a5fddac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 23 Feb 2021 10:27:28 +0800 Subject: [PATCH] config child nodes --- doric-Qt/doric/doric.pro.user | 2 +- doric-Qt/doric/shader/DoricGroupNode.cpp | 81 ++++++++++++++---------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/doric-Qt/doric/doric.pro.user b/doric-Qt/doric/doric.pro.user index f4bbc561..8139dfbc 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/shader/DoricGroupNode.cpp b/doric-Qt/doric/shader/DoricGroupNode.cpp index 46c079cb..2bcae8d5 100644 --- a/doric-Qt/doric/shader/DoricGroupNode.cpp +++ b/doric-Qt/doric/shader/DoricGroupNode.cpp @@ -36,11 +36,14 @@ void DoricGroupNode::configChildNode() { DoricViewNode *oldNode = mChildNodes.at(idx); if (id == oldNode->getId()) { // The same, skip + } else { if (mReusable) { if (oldNode->getType() == type) { + // Same type,can be reused oldNode->setId(id); oldNode->blend(model.property("props")); } else { + // Replace this view mChildNodes.remove(idx); oldNode->getNodeView()->setParent(nullptr); oldNode->getNodeView()->setParentItem(nullptr); @@ -69,51 +72,63 @@ void DoricGroupNode::configChildNode() { position = start; break; } - if (position >= 0) { - // Found swap idx,position - DoricViewNode *reused = mChildNodes.at(position); - mChildNodes.removeAt(position); + } + if (position >= 0) { + // Found swap idx,position + DoricViewNode *reused = mChildNodes.at(position); + DoricViewNode *abandoned = mChildNodes.at(idx); + mChildNodes.swapItemsAt(position, idx); - DoricViewNode *abandoned = mChildNodes.at(idx); - mChildNodes.insert(idx, reused); - mChildNodes.insert(position, abandoned); + // View swap index + reused->getNodeView()->setParentItem(nullptr); + int minIndex = qMin(idx, mView->childItems().size()); + reused->getNodeView()->setParentItem(mView); + reused->getNodeView()->stackBefore( + mView->childItems().at(minIndex)); + + 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); - // 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( + newNode->getNodeView()->setParentItem(mView); + newNode->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 { // Insert + DoricViewNode *newNode = DoricViewNode::create(getContext(), type); + if (newNode != nullptr) { + newNode->setId(id); + newNode->init(this); + newNode->blend(model.property("props")); + mChildNodes.append(newNode); + + int minIndex = qMin(idx, mView->childItems().size()); + newNode->getNodeView()->setParentItem(mView); + newNode->getNodeView()->stackBefore(mView->childItems().at(minIndex)); + } } } + + int size = mChildNodes.size(); + for (int idx = mChildViewIds.size(); idx < size; idx++) { + DoricViewNode *viewNode = mChildNodes.at(mChildViewIds.size()); + mChildNodes.remove(mChildViewIds.size()); + viewNode->getNodeView()->setParent(nullptr); + viewNode->getNodeView()->setParentItem(nullptr); + viewNode->getNodeView()->deleteLater(); + } } void DoricGroupNode::blendSubNode(QJSValue subProperties) {