modify path compath
This commit is contained in:
parent
3a6970b2d1
commit
5a3746b09d
@ -1,9 +1,14 @@
|
|||||||
#include "entities/PathComponent.h"
|
#include "entities/PathComponent.h"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
#include "common/RecourceHelper.h"
|
#include "common/RecourceHelper.h"
|
||||||
#include "utils/TransformPath.h"
|
#include "utils/TransformPath.h"
|
||||||
#include "utils/OsgUtils.h"
|
#include "utils/OsgUtils.h"
|
||||||
|
#include "utils/FileUtils.h"
|
||||||
#include "entities/Entity.h"
|
#include "entities/Entity.h"
|
||||||
#include "workspace/WorkSpace.h"
|
#include "workspace/WorkSpace.h"
|
||||||
#include "workspace/Timestep.h"
|
#include "workspace/Timestep.h"
|
||||||
@ -107,7 +112,17 @@ void PathComponent::SetPath(const QString& path) {
|
|||||||
transformPath_->deleteLater();
|
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);
|
transformPath_ = TransformPath::LoadFromFile(filePath, this);
|
||||||
path_ = path;
|
path_ = path;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -728,7 +728,7 @@
|
|||||||
<message>
|
<message>
|
||||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="271"/>
|
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="271"/>
|
||||||
<source>Delete</source>
|
<source>Delete</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation>删除</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
@ -849,12 +849,12 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>QFilePathEdit</name>
|
<name>QFilePathEdit</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="732"/>
|
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="733"/>
|
||||||
<source>Open File</source>
|
<source>Open File</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="732"/>
|
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="733"/>
|
||||||
<source>All Files (*)</source>
|
<source>All Files (*)</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
@ -1715,7 +1715,7 @@
|
|||||||
<message>
|
<message>
|
||||||
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="26"/>
|
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="26"/>
|
||||||
<source>new workspace</source>
|
<source>new workspace</source>
|
||||||
<translation type="unfinished">新建</translation>
|
<translation>新建</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="49"/>
|
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="49"/>
|
||||||
|
@ -704,10 +704,11 @@ QFilePathEdit::QFilePathEdit(QWidget* parent) :
|
|||||||
lt->setStretch(1, 0);
|
lt->setStretch(1, 0);
|
||||||
setLayout(lt);
|
setLayout(lt);
|
||||||
|
|
||||||
/* m_initialvalue = m_timeedit->dateTime();
|
|
||||||
connect(m_timeedit, &QTimeEdit::dateTimeChanged, this, &QtDateTimeEdit::dateTimeChanged);
|
connect(m_stringEdit, &QLineEdit::textChanged, this, &QFilePathEdit::textChanged);
|
||||||
connect(m_timeedit, &QTimeEdit::dateTimeChanged, this, [&] { m_button->setEnabled(m_initialvalue != m_timeedit->dateTime()); });
|
connect(m_stringEdit, &QLineEdit::textEdited, this, &QFilePathEdit::textEdited);
|
||||||
connect(m_button, &QPushButton::clicked, this, [&] { m_timeedit->setDateTime(m_initialvalue); });*/
|
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);
|
connect(m_button, &QPushButton::clicked, this, &QFilePathEdit::onFileSelect);
|
||||||
setFocusProxy(m_stringEdit);
|
setFocusProxy(m_stringEdit);
|
||||||
}
|
}
|
||||||
@ -731,9 +732,9 @@ void QFilePathEdit::setInitialText(const QString& val) {
|
|||||||
void QFilePathEdit::onFileSelect() {
|
void QFilePathEdit::onFileSelect() {
|
||||||
QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), m_initialvalue, tr("All Files (*)"));
|
QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), m_initialvalue, tr("All Files (*)"));
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
m_stringEdit->setText(filePath);
|
|
||||||
m_fileName = QFileInfo(filePath).fileName();
|
m_fileName = QFileInfo(filePath).fileName();
|
||||||
m_initialvalue = filePath;
|
m_initialvalue = filePath;
|
||||||
|
m_stringEdit->setText(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,8 @@ public:
|
|||||||
void setInitialText(const QString&);
|
void setInitialText(const QString&);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void dateTimeChanged(const QDateTime&);
|
void textChanged(QString);
|
||||||
|
void textEdited(QString);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onFileSelect();
|
void onFileSelect();
|
||||||
|
30
src/utils/FileUtils.cpp
Normal file
30
src/utils/FileUtils.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "utils/FileUtils.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
9
src/utils/FileUtils.h
Normal file
9
src/utils/FileUtils.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
class FileUtils {
|
||||||
|
public:
|
||||||
|
static bool CopyFileToPath(const QString& sourceDir, QString toDir, bool coverFileIfExist);
|
||||||
|
};
|
@ -25,7 +25,8 @@ TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent)
|
|||||||
QFile file(path);
|
QFile file(path);
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "workspace/WorkSpace.h"
|
#include "workspace/WorkSpace.h"
|
||||||
|
|
||||||
#include <QUUID>
|
#include <QUUID>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
#include "workspace/WorkSpaceXMLParse.h"
|
#include "workspace/WorkSpaceXMLParse.h"
|
||||||
#include "workspace/WorkSpaceXMLWrite.h"
|
#include "workspace/WorkSpaceXMLWrite.h"
|
||||||
@ -29,6 +31,10 @@ WorkSpace::WorkSpace(const QString& path, QObject* parent)
|
|||||||
uuid_ = QUuid::createUuid().toString();
|
uuid_ = QUuid::createUuid().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString WorkSpace::GetDir() const {
|
||||||
|
QFileInfo info(path_);
|
||||||
|
return info.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
void WorkSpace::AddEntity(Entity* entity) {
|
void WorkSpace::AddEntity(Entity* entity) {
|
||||||
if (nullptr == entity) {
|
if (nullptr == entity) {
|
||||||
|
@ -29,6 +29,8 @@ public:
|
|||||||
inline const QString& GetPath() const {
|
inline const QString& GetPath() const {
|
||||||
return path_;
|
return path_;
|
||||||
}
|
}
|
||||||
|
const QString GetDir() const;
|
||||||
|
|
||||||
inline void SetUUid(const QString& uuid) {
|
inline void SetUUid(const QString& uuid) {
|
||||||
uuid_ = uuid;
|
uuid_ = uuid;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ void WorkSpaceManager::SaveDefaultWorkspace() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current->Save();
|
||||||
const QString path = current->GetPath();
|
const QString path = current->GetPath();
|
||||||
QSettings settings(iniFile, QSettings::IniFormat);
|
QSettings settings(iniFile, QSettings::IniFormat);
|
||||||
settings.setValue("workspace/path", path);
|
settings.setValue("workspace/path", path);
|
||||||
|
Loading…
Reference in New Issue
Block a user