DYTSrouce/src/workspace/FileEntry.cpp

82 lines
2.4 KiB
C++
Raw Normal View History

2025-10-26 07:55:41 +00:00
#include "workspace/FileEntry.h"
#include <QFileInfo>
#include "common/SpdLogger.h"
void FileEntry::SetPath(const QString& path) {
QFileInfo fileInfo(path);
if (!fileInfo.exists()) {
LOG_WARN("file not exist: {}", path.toLocal8Bit().constData());
return;
}
path_ = fileInfo.path();
fileName_ = fileInfo.fileName();
}
// Factory function implementations
std::shared_ptr<FileEntry> CreateFileEntry(FileEntryType type, const QString& filePath) {
switch (type) {
case FileEntryType::Curve:
return CreateFileEntryCurve(filePath);
case FileEntryType::Surface:
return CreateFileEntrySurface(filePath);
case FileEntryType::Table:
return CreateFileEntryTable(filePath);
case FileEntryType::Light:
return CreateFileEntryLight(filePath);
default:
LOG_ERROR("Unknown FileEntryType: {}", static_cast<int>(type));
return nullptr;
}
}
std::shared_ptr<FileEntryCurve> CreateFileEntryCurve(const QString& filePath) {
QFileInfo fileInfo(filePath);
if (!fileInfo.exists()) {
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
return nullptr;
}
auto fileEntry = std::make_shared<FileEntryCurve>();
fileEntry->SetPath(filePath);
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
return fileEntry;
}
std::shared_ptr<FileEntry> CreateFileEntrySurface(const QString& filePath) {
auto fileEntry = std::make_shared<FileEntry>();
fileEntry->SetType(FileEntryType::Surface);
if (!filePath.isEmpty()) {
fileEntry->SetPath(filePath);
}
return fileEntry;
}
std::shared_ptr<FileEntry> CreateFileEntryTable(const QString& filePath) {
auto fileEntry = std::make_shared<FileEntry>();
fileEntry->SetType(FileEntryType::Table);
if (!filePath.isEmpty()) {
fileEntry->SetPath(filePath);
}
return fileEntry;
}
2025-10-26 08:44:23 +00:00
std::shared_ptr<FileEntryLight> CreateFileEntryLight(const QString& filePath) {
QFileInfo fileInfo(filePath);
if (!fileInfo.exists()) {
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
return nullptr;
2025-10-26 07:55:41 +00:00
}
2025-10-26 08:44:23 +00:00
auto fileEntry = std::make_shared<FileEntryLight>();
fileEntry->SetPath(filePath);
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
2025-10-26 07:55:41 +00:00
return fileEntry;
}