From 5a3746b09d22593a06511673817741821a6c9b44 Mon Sep 17 00:00:00 2001 From: jiegeaiai Date: Sun, 5 Jan 2025 23:12:58 +0800 Subject: [PATCH] modify path compath --- src/entities/PathComponent.cpp | 17 +++++++++- src/translations/Dyt_zh_CN.qm | Bin 4139 -> 4134 bytes src/translations/Dyt_zh_CN.ts | 8 ++--- .../qtpropertybrowserutils.cpp | 11 ++++--- .../qtpropertybrowserutils_p.h | 3 +- src/utils/FileUtils.cpp | 30 ++++++++++++++++++ src/utils/FileUtils.h | 9 ++++++ src/utils/TransformPath.cpp | 3 +- src/workspace/WorkSpace.cpp | 6 ++++ src/workspace/WorkSpace.h | 2 ++ src/workspace/WorkSpaceManager.cpp | 1 + 11 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 src/utils/FileUtils.cpp create mode 100644 src/utils/FileUtils.h diff --git a/src/entities/PathComponent.cpp b/src/entities/PathComponent.cpp index c2432dce..052095c5 100644 --- a/src/entities/PathComponent.cpp +++ b/src/entities/PathComponent.cpp @@ -1,9 +1,14 @@ #include "entities/PathComponent.h" +#include +#include +#include + #include "common/SpdLogger.h" #include "common/RecourceHelper.h" #include "utils/TransformPath.h" #include "utils/OsgUtils.h" +#include "utils/FileUtils.h" #include "entities/Entity.h" #include "workspace/WorkSpace.h" #include "workspace/Timestep.h" @@ -107,7 +112,17 @@ void PathComponent::SetPath(const QString& path) { transformPath_->deleteLater(); } - const QString filePath = QString("%1/%2").arg(RecourceHelper::Get().GetBasePath()).arg(path); + const QString workPath = GetEntity()->GetWorkspace()->GetDir(); + QFileInfo fileInfo(path); + const QString filePath = QString("%1/%2").arg(workPath).arg(fileInfo.fileName()); + if (!FileUtils::CopyFileToPath(path, filePath, true)) { + LOG_ERROR("PathComponent::SetPath: Failed to copy file to workspace"); + QMessageBox::critical(nullptr, "Error", "Failed to copy file to workspace"); + return; + } + LOG_INFO("PathComponent::SetPath: {}", workPath.toStdString().c_str()); + + transformPath_ = TransformPath::LoadFromFile(filePath, this); path_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S&d)8#&r8iK*__R_n-u{4!+RzG diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index 612d9e94..f4dbcaaf 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -728,7 +728,7 @@ Delete - + 删除 @@ -849,12 +849,12 @@ QFilePathEdit - + Open File - + All Files (*) @@ -1715,7 +1715,7 @@ new workspace - 新建 + 新建 diff --git a/src/ui/PropertyBrowser/qtpropertybrowserutils.cpp b/src/ui/PropertyBrowser/qtpropertybrowserutils.cpp index c78faf21..5138f16e 100644 --- a/src/ui/PropertyBrowser/qtpropertybrowserutils.cpp +++ b/src/ui/PropertyBrowser/qtpropertybrowserutils.cpp @@ -704,10 +704,11 @@ QFilePathEdit::QFilePathEdit(QWidget* parent) : lt->setStretch(1, 0); setLayout(lt); - /* m_initialvalue = m_timeedit->dateTime(); - connect(m_timeedit, &QTimeEdit::dateTimeChanged, this, &QtDateTimeEdit::dateTimeChanged); - connect(m_timeedit, &QTimeEdit::dateTimeChanged, this, [&] { m_button->setEnabled(m_initialvalue != m_timeedit->dateTime()); }); - connect(m_button, &QPushButton::clicked, this, [&] { m_timeedit->setDateTime(m_initialvalue); });*/ + + connect(m_stringEdit, &QLineEdit::textChanged, this, &QFilePathEdit::textChanged); + connect(m_stringEdit, &QLineEdit::textEdited, this, &QFilePathEdit::textEdited); + connect(m_stringEdit, &QLineEdit::textChanged, this, [&] { m_button->setEnabled(m_initialvalue != m_stringEdit->text()); }); + connect(m_stringEdit, &QLineEdit::textEdited, this, [&] { m_button->setEnabled(m_initialvalue != m_stringEdit->text()); }); connect(m_button, &QPushButton::clicked, this, &QFilePathEdit::onFileSelect); setFocusProxy(m_stringEdit); } @@ -731,9 +732,9 @@ void QFilePathEdit::setInitialText(const QString& val) { void QFilePathEdit::onFileSelect() { QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), m_initialvalue, tr("All Files (*)")); if (!filePath.isEmpty()) { - m_stringEdit->setText(filePath); m_fileName = QFileInfo(filePath).fileName(); m_initialvalue = filePath; + m_stringEdit->setText(filePath); } } diff --git a/src/ui/PropertyBrowser/qtpropertybrowserutils_p.h b/src/ui/PropertyBrowser/qtpropertybrowserutils_p.h index c4f31bc8..c12c433b 100644 --- a/src/ui/PropertyBrowser/qtpropertybrowserutils_p.h +++ b/src/ui/PropertyBrowser/qtpropertybrowserutils_p.h @@ -299,7 +299,8 @@ public: void setInitialText(const QString&); Q_SIGNALS: - void dateTimeChanged(const QDateTime&); + void textChanged(QString); + void textEdited(QString); protected: void onFileSelect(); diff --git a/src/utils/FileUtils.cpp b/src/utils/FileUtils.cpp new file mode 100644 index 00000000..78a6094f --- /dev/null +++ b/src/utils/FileUtils.cpp @@ -0,0 +1,30 @@ +#include "utils/FileUtils.h" + +#include +#include + +#include "common/SpdLogger.h" + + +bool FileUtils::CopyFileToPath(const QString& sourceDir, QString toDir, bool coverFileIfExist) { + toDir.replace("\\", "/"); + LOG_INFO("copy file from {} to {}", sourceDir.toStdString(), toDir.toStdString()); + if (sourceDir == toDir) { + return true; + } + if (!QFile::exists(sourceDir)) { + return false; + } + QDir* createfile = new QDir; + bool exist = createfile->exists(toDir); + if (exist) { + if (coverFileIfExist) { + createfile->remove(toDir); + } + } + + if (!QFile::copy(sourceDir, toDir)) { + return false; + } + return true; +} diff --git a/src/utils/FileUtils.h b/src/utils/FileUtils.h new file mode 100644 index 00000000..2b6d1a86 --- /dev/null +++ b/src/utils/FileUtils.h @@ -0,0 +1,9 @@ +#pragma once + +#include + + +class FileUtils { +public: + static bool CopyFileToPath(const QString& sourceDir, QString toDir, bool coverFileIfExist); +}; \ No newline at end of file diff --git a/src/utils/TransformPath.cpp b/src/utils/TransformPath.cpp index bb071b45..9092ed34 100644 --- a/src/utils/TransformPath.cpp +++ b/src/utils/TransformPath.cpp @@ -25,7 +25,8 @@ TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent) QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - LOG_WARN("Cannot open file for reading: {}", file.errorString().toStdString()); + LOG_WARN("Cannot open file for reading: path:{} error:{}", + path.toStdString(), file.errorString().toStdString()); return nullptr; } diff --git a/src/workspace/WorkSpace.cpp b/src/workspace/WorkSpace.cpp index 4934959f..384f2942 100644 --- a/src/workspace/WorkSpace.cpp +++ b/src/workspace/WorkSpace.cpp @@ -1,6 +1,8 @@ #include "workspace/WorkSpace.h" #include +#include +#include #include "workspace/WorkSpaceXMLParse.h" #include "workspace/WorkSpaceXMLWrite.h" @@ -29,6 +31,10 @@ WorkSpace::WorkSpace(const QString& path, QObject* parent) uuid_ = QUuid::createUuid().toString(); } +const QString WorkSpace::GetDir() const { + QFileInfo info(path_); + return info.absolutePath(); +} void WorkSpace::AddEntity(Entity* entity) { if (nullptr == entity) { diff --git a/src/workspace/WorkSpace.h b/src/workspace/WorkSpace.h index a8bf718d..044ab9ab 100644 --- a/src/workspace/WorkSpace.h +++ b/src/workspace/WorkSpace.h @@ -29,6 +29,8 @@ public: inline const QString& GetPath() const { return path_; } + const QString GetDir() const; + inline void SetUUid(const QString& uuid) { uuid_ = uuid; } diff --git a/src/workspace/WorkSpaceManager.cpp b/src/workspace/WorkSpaceManager.cpp index b75ba818..b8190f4f 100644 --- a/src/workspace/WorkSpaceManager.cpp +++ b/src/workspace/WorkSpaceManager.cpp @@ -59,6 +59,7 @@ void WorkSpaceManager::SaveDefaultWorkspace() { return; } + current->Save(); const QString path = current->GetPath(); QSettings settings(iniFile, QSettings::IniFormat); settings.setValue("workspace/path", path);