config child nodes

This commit is contained in:
王劲鹏 2021-02-23 10:27:28 +08:00 committed by osborn
parent 66649fe0f0
commit 1c574f030c
2 changed files with 49 additions and 34 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.14.0, 2021-02-22T16:31:33. -->
<!-- Written by QtCreator 4.14.0, 2021-02-23T10:26:39. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -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,32 +72,25 @@ void DoricGroupNode::configChildNode() {
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);
mChildNodes.swapItemsAt(position, idx);
// 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);
DoricViewNode *newNode = DoricViewNode::create(getContext(), type);
if (newNode != nullptr) {
newNode->setId(id);
newNode->init(this);
@ -109,11 +105,30 @@ void DoricGroupNode::configChildNode() {
}
}
}
}
} 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) {