modify workspace

This commit is contained in:
jiegeaiai 2025-01-05 11:33:33 +08:00
parent 6b9d56a3cf
commit 8b94963f39
7 changed files with 43 additions and 13 deletions

View File

@ -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;

View File

@ -1740,11 +1740,12 @@
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="49"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="57"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="64"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="55"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="66"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="79"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="82"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="88"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="97"/>
<source>warning</source>
<translation type="unfinished"></translation>
</message>
@ -1754,32 +1755,37 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="57"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="55"/>
<source>save current workspace?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="66"/>
<source>current path is contains current folder, do you want to overwrite it?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="64"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<source>removeRecursively failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="73"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="82"/>
<source>mkpath failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="79"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="88"/>
<source>name is exits</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="88"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="97"/>
<source>create workSpace failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="98"/>
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="107"/>
<source>save spaceWork directory</source>
<translation type="unfinished"></translation>
</message>

View File

@ -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);

View File

@ -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()) {

View File

@ -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() {

View File

@ -87,6 +87,7 @@ private:
QString describe_;
QString path_;
bool leaded_{ false };
std::vector<class Entity*> entities_;
osg::ref_ptr<OEScene> activeScene_;
class OsgView* view_{ nullptr };

View File

@ -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) {