From 8b94963f39d3391c5aa226316c1a43c5463506c4 Mon Sep 17 00:00:00 2001 From: jiegeaiai Date: Sun, 5 Jan 2025 11:33:33 +0800 Subject: [PATCH] modify workspace --- src/entities/Entity.cpp | 1 + src/translations/Dyt_zh_CN.ts | 24 +++++++++++++++--------- src/ui/ModelBrowser/ModelTreeWidget.cpp | 2 +- src/ui/WorkSpace/WorkSpaceDlg.cpp | 9 +++++++++ src/workspace/WorkSpace.cpp | 17 ++++++++++++++--- src/workspace/WorkSpace.h | 1 + src/workspace/WorkSpaceManager.cpp | 2 ++ 7 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 1fcb5053..bc8f329b 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -125,6 +125,7 @@ void Entity::End() { } void Entity::Destory() { + LOG_INFO("destory entity, {}", name_.toLocal8Bit().constData()); if (nullptr == workspace_) { LOG_WARN("workspace is nullptr"); return; diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index 1602e815..0080a8d7 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -1740,11 +1740,12 @@ - - + + - + + warning @@ -1754,32 +1755,37 @@ - + + save current workspace? + + + + current path is contains current folder, do you want to overwrite it? - + removeRecursively failed - + mkpath failed - + name is exits - + create workSpace failed - + save spaceWork directory diff --git a/src/ui/ModelBrowser/ModelTreeWidget.cpp b/src/ui/ModelBrowser/ModelTreeWidget.cpp index 5b44fabd..8d06eff2 100644 --- a/src/ui/ModelBrowser/ModelTreeWidget.cpp +++ b/src/ui/ModelBrowser/ModelTreeWidget.cpp @@ -293,7 +293,7 @@ bool ModelTreeWidget::RemoveItemFromParent(QTreeWidgetItem* parentItem, const QS if (uuid == itemToRemove) { while (childItem->childCount() > 0) { QTreeWidgetItem* grandChildItem = childItem->child(0); - parentItem->addChild(grandChildItem); + childItem->removeChild(grandChildItem); } parentItem->removeChild(childItem); diff --git a/src/ui/WorkSpace/WorkSpaceDlg.cpp b/src/ui/WorkSpace/WorkSpaceDlg.cpp index df3d4283..b9104d72 100644 --- a/src/ui/WorkSpace/WorkSpaceDlg.cpp +++ b/src/ui/WorkSpace/WorkSpaceDlg.cpp @@ -50,6 +50,15 @@ void WorkSpaceDlg::OnSure() { return; } + WorkSpace* current = WorkSpaceManager::Get().GetCurrent(); + if (nullptr != current) { + if (QMessageBox::Yes == QMessageBox::question(this, tr("warning"), tr("save current workspace?"))) { + current->Save(); + } + current->Unlaod(); + } + + QString workspacePath = QString("%1/%2").arg(savePath).arg(name); QDir dir(workspacePath); if (dir.exists()) { diff --git a/src/workspace/WorkSpace.cpp b/src/workspace/WorkSpace.cpp index 74cf36c0..97a3b105 100644 --- a/src/workspace/WorkSpace.cpp +++ b/src/workspace/WorkSpace.cpp @@ -75,7 +75,7 @@ void WorkSpace::AddEntity(Entity* entity) { LOG_WARN("entity is nullptr"); return; } - + LOG_INFO("add entity: {}", entity->GetName().toLocal8Bit().constData()); entities_.push_back(entity); entity->SetWorkspace(this); @@ -158,18 +158,29 @@ bool WorkSpace::Save() { } bool WorkSpace::Load(const QString& dyt) { + if (leaded_) { + LOG_INFO("dyt {} loaded", dyt.toStdString()); + return true; + } WorkSpaceXMLParse parse(this); bool success = parse.Load(dyt); if (success) { path_ = dyt; } + leaded_ = success; return success; } void WorkSpace::Unlaod() { - for (auto& entity : entities_) { - entity->End(); + if (!leaded_) { + LOG_INFO("dyt {} unloaded", name_.toStdString()); + return; } + while (!entities_.empty()) { + auto entity = entities_.front(); + entity->Destory(); + } + leaded_ = false; } void WorkSpace::Begin() { diff --git a/src/workspace/WorkSpace.h b/src/workspace/WorkSpace.h index 5301f331..01bdf3c1 100644 --- a/src/workspace/WorkSpace.h +++ b/src/workspace/WorkSpace.h @@ -87,6 +87,7 @@ private: QString describe_; QString path_; + bool leaded_{ false }; std::vector entities_; osg::ref_ptr activeScene_; class OsgView* view_{ nullptr }; diff --git a/src/workspace/WorkSpaceManager.cpp b/src/workspace/WorkSpaceManager.cpp index aa8d9c87..21b98581 100644 --- a/src/workspace/WorkSpaceManager.cpp +++ b/src/workspace/WorkSpaceManager.cpp @@ -36,9 +36,11 @@ bool WorkSpaceManager::Remove(const QString& name) { WorkSpace* workspace = itor->second; if (nullptr != workspace) { + workspace->Unlaod(); workspace->deleteLater(); } workSpaces_.erase(itor); + return true; } WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt, class OsgView* view) {