modify path compath
This commit is contained in:
parent
3a6970b2d1
commit
5a3746b09d
@ -1,9 +1,14 @@
|
||||
#include "entities/PathComponent.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
|
||||
#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_ = path;
|
||||
}
|
||||
|
Binary file not shown.
@ -728,7 +728,7 @@
|
||||
<message>
|
||||
<location filename="../ui/ModelBrowser/ModelTreeWidget.cpp" line="271"/>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>删除</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
@ -849,12 +849,12 @@
|
||||
<context>
|
||||
<name>QFilePathEdit</name>
|
||||
<message>
|
||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="732"/>
|
||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="733"/>
|
||||
<source>Open File</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="732"/>
|
||||
<location filename="../ui/PropertyBrowser/qtpropertybrowserutils.cpp" line="733"/>
|
||||
<source>All Files (*)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@ -1715,7 +1715,7 @@
|
||||
<message>
|
||||
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="26"/>
|
||||
<source>new workspace</source>
|
||||
<translation type="unfinished">新建</translation>
|
||||
<translation>新建</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../ui/WorkSpace/WorkSpaceDlg.cpp" line="49"/>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,8 @@ public:
|
||||
void setInitialText(const QString&);
|
||||
|
||||
Q_SIGNALS:
|
||||
void dateTimeChanged(const QDateTime&);
|
||||
void textChanged(QString);
|
||||
void textEdited(QString);
|
||||
|
||||
protected:
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "workspace/WorkSpace.h"
|
||||
|
||||
#include <QUUID>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
#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) {
|
||||
|
@ -29,6 +29,8 @@ public:
|
||||
inline const QString& GetPath() const {
|
||||
return path_;
|
||||
}
|
||||
const QString GetDir() const;
|
||||
|
||||
inline void SetUUid(const QString& uuid) {
|
||||
uuid_ = uuid;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user