#include "workspace/FileEntry.h" #include #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 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(type)); return nullptr; } } std::shared_ptr 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(); fileEntry->SetPath(filePath); fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name return fileEntry; } std::shared_ptr CreateFileEntrySurface(const QString& filePath) { auto fileEntry = std::make_shared(); fileEntry->SetType(FileEntryType::Surface); if (!filePath.isEmpty()) { fileEntry->SetPath(filePath); } return fileEntry; } std::shared_ptr CreateFileEntryTable(const QString& filePath) { auto fileEntry = std::make_shared(); fileEntry->SetType(FileEntryType::Table); if (!filePath.isEmpty()) { fileEntry->SetPath(filePath); } return fileEntry; } std::shared_ptr CreateFileEntryLight(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(); fileEntry->SetPath(filePath); fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name return fileEntry; }