79 lines
2.2 KiB
C++
79 lines
2.2 KiB
C++
|
|
#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;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::shared_ptr<FileEntry> CreateFileEntryLight(const QString& filePath) {
|
||
|
|
auto fileEntry = std::make_shared<FileEntry>();
|
||
|
|
fileEntry->SetType(FileEntryType::Light);
|
||
|
|
|
||
|
|
if (!filePath.isEmpty()) {
|
||
|
|
fileEntry->SetPath(filePath);
|
||
|
|
}
|
||
|
|
|
||
|
|
return fileEntry;
|
||
|
|
}
|