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"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -36,11 +36,14 @@ void DoricGroupNode::configChildNode() {
DoricViewNode *oldNode = mChildNodes.at(idx); DoricViewNode *oldNode = mChildNodes.at(idx);
if (id == oldNode->getId()) { if (id == oldNode->getId()) {
// The same, skip // The same, skip
} else {
if (mReusable) { if (mReusable) {
if (oldNode->getType() == type) { if (oldNode->getType() == type) {
// Same type,can be reused
oldNode->setId(id); oldNode->setId(id);
oldNode->blend(model.property("props")); oldNode->blend(model.property("props"));
} else { } else {
// Replace this view
mChildNodes.remove(idx); mChildNodes.remove(idx);
oldNode->getNodeView()->setParent(nullptr); oldNode->getNodeView()->setParent(nullptr);
oldNode->getNodeView()->setParentItem(nullptr); oldNode->getNodeView()->setParentItem(nullptr);
@ -69,32 +72,25 @@ void DoricGroupNode::configChildNode() {
position = start; position = start;
break; break;
} }
}
if (position >= 0) { if (position >= 0) {
// Found swap idx,position // Found swap idx,position
DoricViewNode *reused = mChildNodes.at(position); DoricViewNode *reused = mChildNodes.at(position);
mChildNodes.removeAt(position);
DoricViewNode *abandoned = mChildNodes.at(idx); DoricViewNode *abandoned = mChildNodes.at(idx);
mChildNodes.insert(idx, reused); mChildNodes.swapItemsAt(position, idx);
mChildNodes.insert(position, abandoned);
// View swap index // View swap index
reused->getNodeView()->setParent(nullptr);
reused->getNodeView()->setParentItem(nullptr); reused->getNodeView()->setParentItem(nullptr);
int minIndex = qMin(idx, mView->childItems().size()); int minIndex = qMin(idx, mView->childItems().size());
reused->getNodeView()->setParentItem(mView); reused->getNodeView()->setParentItem(mView);
reused->getNodeView()->stackBefore( reused->getNodeView()->stackBefore(
mView->childItems().at(minIndex)); mView->childItems().at(minIndex));
abandoned->getNodeView()->setParent(nullptr);
abandoned->getNodeView()->setParentItem(nullptr);
abandoned->getNodeView()->setParentItem(mView);
abandoned->getNodeView()->stackBefore( abandoned->getNodeView()->stackBefore(
mView->childItems().at(position)); mView->childItems().at(position));
} else { } else {
// Not found,insert // Not found,insert
DoricViewNode *newNode = DoricViewNode *newNode = DoricViewNode::create(getContext(), type);
DoricViewNode::create(getContext(), type);
if (newNode != nullptr) { if (newNode != nullptr) {
newNode->setId(id); newNode->setId(id);
newNode->init(this); newNode->init(this);
@ -109,11 +105,30 @@ void DoricGroupNode::configChildNode() {
} }
} }
} }
}
} else { } else {
// Insert // 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) { void DoricGroupNode::blendSubNode(QJSValue subProperties) {