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,51 +72,63 @@ void DoricGroupNode::configChildNode() {
position = start; position = start;
break; break;
} }
if (position >= 0) { }
// Found swap idx,position if (position >= 0) {
DoricViewNode *reused = mChildNodes.at(position); // Found swap idx,position
mChildNodes.removeAt(position); DoricViewNode *reused = mChildNodes.at(position);
DoricViewNode *abandoned = mChildNodes.at(idx);
mChildNodes.swapItemsAt(position, idx);
DoricViewNode *abandoned = mChildNodes.at(idx); // View swap index
mChildNodes.insert(idx, reused); reused->getNodeView()->setParentItem(nullptr);
mChildNodes.insert(position, abandoned); 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()); int minIndex = qMin(idx, mView->childItems().size());
reused->getNodeView()->setParentItem(mView); newNode->getNodeView()->setParentItem(mView);
reused->getNodeView()->stackBefore( newNode->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(
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 { } 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) {