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) {
|
2025-10-26 09:48:34 +00:00
|
|
|
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 09:48:34 +00:00
|
|
|
auto fileEntry = std::make_shared<FileEntrySurface>();
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
|
|
|
|
|
|
2025-10-26 07:55:41 +00:00
|
|
|
return fileEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-26 12:14:06 +00:00
|
|
|
std::shared_ptr<FileEntryTable> CreateFileEntryTable(const QString& filePath) {
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if (!filePath.isEmpty() && !fileInfo.exists()) {
|
|
|
|
|
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
|
|
|
|
|
return nullptr;
|
2025-10-26 07:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-26 12:14:06 +00:00
|
|
|
auto fileEntry = std::make_shared<FileEntryTable>();
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
|
|
|
|
|
|
2025-10-26 07:55:41 +00:00
|
|
|
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;
|
2025-10-26 09:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FileEntrySurface method implementations
|
|
|
|
|
void FileEntrySurface::SetChartProperties(const ChartProperties& properties) {
|
|
|
|
|
chartProperties_ = properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntrySurface::ChartProperties& FileEntrySurface::GetChartProperties() const {
|
|
|
|
|
return chartProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::AddSurfaceProperty(const SurfaceProperty& surface) {
|
|
|
|
|
surfaceProperties_.append(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::RemoveSurfaceProperty(int index) {
|
|
|
|
|
if (index >= 0 && index < surfaceProperties_.size()) {
|
|
|
|
|
surfaceProperties_.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::SetSurfaceProperty(int index, const SurfaceProperty& surface) {
|
|
|
|
|
if (index >= 0 && index < surfaceProperties_.size()) {
|
|
|
|
|
surfaceProperties_[index] = surface;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntrySurface::SurfaceProperties& FileEntrySurface::GetSurfaceProperties() const {
|
|
|
|
|
return surfaceProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileEntrySurface* FileEntrySurface::AsSurface() {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::SetDescription(const QString& description) {
|
|
|
|
|
description_ = description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& FileEntrySurface::GetDescription() const {
|
|
|
|
|
return description_;
|
2025-10-26 12:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FileEntryTable method implementations
|
|
|
|
|
void FileEntryTable::SetChartProperties(const ChartProperties& properties) {
|
|
|
|
|
chartProperties_ = properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntryTable::ChartProperties& FileEntryTable::GetChartProperties() const {
|
|
|
|
|
return chartProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::AddTableProperty(const TableProperty& table) {
|
|
|
|
|
tableProperties_.append(table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::RemoveTableProperty(int index) {
|
|
|
|
|
if (index >= 0 && index < tableProperties_.size()) {
|
|
|
|
|
tableProperties_.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::SetTableProperty(int index, const TableProperty& table) {
|
|
|
|
|
if (index >= 0 && index < tableProperties_.size()) {
|
|
|
|
|
tableProperties_[index] = table;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntryTable::TableProperties& FileEntryTable::GetTableProperties() const {
|
|
|
|
|
return tableProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::SetTableHeaders(const QStringList& headers) {
|
|
|
|
|
tableHeaders_ = headers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::SetTableHeaders(const QString& headerString) {
|
|
|
|
|
tableHeaders_ = headerString.split(',', Qt::SkipEmptyParts);
|
|
|
|
|
// Trim whitespace from each header
|
|
|
|
|
for (QString& header : tableHeaders_) {
|
|
|
|
|
header = header.trimmed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList& FileEntryTable::GetTableHeaders() const {
|
|
|
|
|
return tableHeaders_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileEntryTable* FileEntryTable::AsTable() {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntryTable::SetDescription(const QString& description) {
|
|
|
|
|
description_ = description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& FileEntryTable::GetDescription() const {
|
|
|
|
|
return description_;
|
2025-10-26 07:55:41 +00:00
|
|
|
}
|