Skip to content

Commit

Permalink
Fix paste
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Jan 21, 2023
1 parent d9babba commit f75e61a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
1 change: 1 addition & 0 deletions application/sources/component_list_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ComponentListModel::ComponentListModel(const Document* document, QObject* parent
return;
this->reload();
});
connect(this, &ComponentListModel::listingComponentChanged, m_document, &Document::setCurrentCanvasComponentId);
}

void ComponentListModel::reload()
Expand Down
79 changes: 54 additions & 25 deletions application/sources/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,23 @@ dust3d::Uuid Document::createNode(dust3d::Uuid nodeId, float x, float y, float z
emit nodeAdded(node.id);

if (nullptr != fromNode) {
bool reverse = false;
if (!fromNode->edgeIds.empty()) {
const Document::Edge* fromEdge = findEdge(fromNode->edgeIds[0]);
if (nullptr != fromEdge) {
if (!fromEdge->nodeIds.empty() && fromNode->id == fromEdge->nodeIds.front())
reverse = true;
}
}
Document::Edge edge;
edge.partId = partId;
edge.nodeIds.push_back(fromNode->id);
edge.nodeIds.push_back(node.id);
if (reverse) {
edge.nodeIds.push_back(node.id);
edge.nodeIds.push_back(fromNode->id);
} else {
edge.nodeIds.push_back(fromNode->id);
edge.nodeIds.push_back(node.id);
}
edgeMap[edge.id] = edge;

nodeMap[node.id].edgeIds.push_back(edge.id);
Expand Down Expand Up @@ -1957,6 +1970,10 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
for (const auto& componentKv : snapshot.components) {
QString linkData = dust3d::String::valueOrEmpty(componentKv.second, "linkData").c_str();
QString linkDataType = dust3d::String::valueOrEmpty(componentKv.second, "linkDataType").c_str();
if (SnapshotSource::Paste == source) {
if ("partId" != linkDataType)
continue;
}
Document::Component component(dust3d::Uuid(), linkData, linkDataType);
auto componentId = component.id;
oldNewIdMap[dust3d::Uuid(componentKv.first)] = componentId;
Expand Down Expand Up @@ -1988,31 +2005,43 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
componentMap.emplace(componentId, std::move(component));
newAddedComponentIds.insert(componentId);
}
const auto& rootComponentChildren = snapshot.rootComponent.find("children");
if (rootComponentChildren != snapshot.rootComponent.end()) {
for (const auto& childId : dust3d::String::split(rootComponentChildren->second, ',')) {
if (childId.empty())
continue;
dust3d::Uuid componentId = oldNewIdMap[dust3d::Uuid(childId)];
if (componentMap.find(componentId) == componentMap.end())
continue;
//qDebug() << "Add root component:" << componentId;
rootComponent.addChild(componentId);
if (SnapshotSource::Paste == source) {
if (m_currentCanvasComponentId.isNull()) {
for (const auto& childComponentId : newAddedComponentIds)
rootComponent.addChild(childComponentId);
} else {
for (const auto& childComponentId : newAddedComponentIds) {
componentMap[m_currentCanvasComponentId].addChild(childComponentId);
componentMap[childComponentId].parentId = m_currentCanvasComponentId;
}
}
}
for (const auto& componentKv : snapshot.components) {
dust3d::Uuid componentId = oldNewIdMap[dust3d::Uuid(componentKv.first)];
if (componentMap.find(componentId) == componentMap.end())
continue;
for (const auto& childId : dust3d::String::split(dust3d::String::valueOrEmpty(componentKv.second, "children"), ',')) {
if (childId.empty())
continue;
dust3d::Uuid childComponentId = oldNewIdMap[dust3d::Uuid(childId)];
if (componentMap.find(childComponentId) == componentMap.end())
} else {
const auto& rootComponentChildren = snapshot.rootComponent.find("children");
if (rootComponentChildren != snapshot.rootComponent.end()) {
for (const auto& childId : dust3d::String::split(rootComponentChildren->second, ',')) {
if (childId.empty())
continue;
dust3d::Uuid componentId = oldNewIdMap[dust3d::Uuid(childId)];
if (componentMap.find(componentId) == componentMap.end())
continue;
//qDebug() << "Add root component:" << componentId;
rootComponent.addChild(componentId);
}
}
for (const auto& componentKv : snapshot.components) {
dust3d::Uuid componentId = oldNewIdMap[dust3d::Uuid(componentKv.first)];
if (componentMap.find(componentId) == componentMap.end())
continue;
//qDebug() << "Add child component:" << childComponentId << "to" << componentId;
componentMap[componentId].addChild(childComponentId);
componentMap[childComponentId].parentId = componentId;
for (const auto& childId : dust3d::String::split(dust3d::String::valueOrEmpty(componentKv.second, "children"), ',')) {
if (childId.empty())
continue;
dust3d::Uuid childComponentId = oldNewIdMap[dust3d::Uuid(childId)];
if (componentMap.find(childComponentId) == componentMap.end())
continue;
//qDebug() << "Add child component:" << childComponentId << "to" << componentId;
componentMap[componentId].addChild(childComponentId);
componentMap[childComponentId].parentId = componentId;
}
}
}

Expand Down

0 comments on commit f75e61a

Please sign in to comment.