diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index d3b49af1..b6a4a1c6 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -936,6 +936,26 @@ Add Table Data File + + + Basic Information + + + + + Table Name: + + + + + Enter table name... + + + + + Time Parameter: + + File Selection @@ -947,7 +967,7 @@ - + Select table data file... @@ -973,100 +993,137 @@ - - Table Parameters - - - - - Separator: - - - - - Comma (,) - - - - - Tab - - - - - Space - - - - - Semicolon (;) - - - - + Encoding: - + UTF-8 - + GBK - + ASCII - + ISO-8859-1 - + Skip Rows: - + File has header row - + + Table Headers Configuration + + + + + Headers (comma-separated): + + + + + e.g., Time, Value1, Value2, Value3... + + + + + Tip: Headers will be auto-detected if file has header row + + + + + Parsing Parameters + + + + Auto-detect parameters - + Preview - - Description (Optional) - - - - - Enter file description... - - - - + Add File - + Cancel + + + Warning + + + + + Please enter a table name. + + + + + + + Error + + + + + Failed to create table file entry. + + + + + Unable to get current workspace + + + + + Table file count has reached the limit + + + + + File already exists + + + + + File copy failed + + + + + Invalid file + + + + + Failed to add file + + ChartPlotMenuClass diff --git a/src/ui/Panel/CurvePanel.cpp b/src/ui/Panel/CurvePanel.cpp index daa01a73..8c2f32ac 100644 --- a/src/ui/Panel/CurvePanel.cpp +++ b/src/ui/Panel/CurvePanel.cpp @@ -47,6 +47,10 @@ void CurvePanel::RefreshPanel() { // Implement curve-specific refresh logic here DataPanel::RefreshPanel(); + + if (auto fileEntry = std::dynamic_pointer_cast(fileEntry_)) { + OnDataPanelUpdated(fileEntry.get()); + } if (hasChartData_) { UpdateCurveDisplay(); @@ -348,4 +352,8 @@ void CurvePanel::initQChartView() { QHBoxLayout* pLayout = new QHBoxLayout(this); pLayout->addWidget(curveChartView); -} \ No newline at end of file +} + +void CurvePanel::OnDataPanelUpdated(FileEntryCurve* fileEntry) { + int a = 0; +} diff --git a/src/ui/Panel/CurvePanel.h b/src/ui/Panel/CurvePanel.h index f1b321b0..71f32185 100644 --- a/src/ui/Panel/CurvePanel.h +++ b/src/ui/Panel/CurvePanel.h @@ -2,6 +2,7 @@ #include "DataPanel.h" #include "workspace/ChartData.h" +#include "workspace/FileEntry.h" #include #include "ui/chartPlot/FitCurveChartView.h" @@ -79,8 +80,11 @@ protected: */ QString GetTypeDisplayName() const override; + void initQChartView(); + void OnDataPanelUpdated(FileEntryCurve* fileEntry); + private: /** * @brief Update curve display based on chart data diff --git a/src/ui/Panel/DataPanel.h b/src/ui/Panel/DataPanel.h index 32f2404d..56c8bea2 100644 --- a/src/ui/Panel/DataPanel.h +++ b/src/ui/Panel/DataPanel.h @@ -40,6 +40,12 @@ public: */ int GetIndex() const { return index_; } + /** + * @brief Set associated file entry + * @param fileEntry Shared pointer to FileEntry + */ + void SetFileEntry(std::shared_ptr fileEntry) { fileEntry_ = fileEntry; } + /** * @brief Get file type (virtual function, implemented by derived classes) * @return File type @@ -111,4 +117,6 @@ protected: QString filePath_; // Associated file path QString title_; // Panel title DockWidget* dockWidget_; // Dock widget reference + + std::shared_ptr fileEntry_; // Associated file entry }; \ No newline at end of file diff --git a/src/ui/Panel/DataPanelManager.cpp b/src/ui/Panel/DataPanelManager.cpp index 1df0a594..1670bab3 100644 --- a/src/ui/Panel/DataPanelManager.cpp +++ b/src/ui/Panel/DataPanelManager.cpp @@ -193,7 +193,12 @@ DataPanel* DataPanelManager::CreateDataPanel(FileEntryType fileType, const QStri return nullptr; } - panel->InitUI(); + //panel->InitUI(); + + auto fileEntries = currentWorkspace_->GetFileEntries(fileType); + if (index < fileEntries.size()) { + panel->SetFileEntry(fileEntries[index]); + } dockWidget->setWidget(panel); diff --git a/src/ui/WorkSpace/AddTableFileDlg.cpp b/src/ui/WorkSpace/AddTableFileDlg.cpp index 8f666f4d..25dbb4fa 100644 --- a/src/ui/WorkSpace/AddTableFileDlg.cpp +++ b/src/ui/WorkSpace/AddTableFileDlg.cpp @@ -6,6 +6,8 @@ #include "app/Application.h" #include "common/SpdLogger.h" +#include "workspace/WorkSpaceManager.h" +#include "workspace/WorkSpace.h" #include "ui_AddTableFileDlg.h" @@ -14,7 +16,7 @@ AddTableFileDlg::AddTableFileDlg(QWidget* parent) : BaseAddFileDlg(FileEntryType::Table, parent) , ui(new Ui::AddTableFileDlg) { - ui->setupUi(this); + SetupUI(ui); SetTitle(getDialogTitle()); setupConnections(); } @@ -27,8 +29,7 @@ void AddTableFileDlg::setupConnections() { // Connect file selection connect(ui->selectFileBtn, &QToolButton::clicked, this, &AddTableFileDlg::onSelectFileClicked); connect(ui->filePathEdit, &QLineEdit::textChanged, this, &AddTableFileDlg::onFilePathChanged); - connect(ui->separatorComboBox, QOverload::of(&QComboBox::currentIndexChanged), - this, &AddTableFileDlg::onDelimiterChanged); + connect(ui->hasHeaderCheckBox, &QCheckBox::toggled, this, &AddTableFileDlg::onHeaderToggled); connect(ui->addBtn, &QPushButton::clicked, this, [this]() { OnSure(); }); connect(ui->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); @@ -105,26 +106,77 @@ QString AddTableFileDlg::getSelectedFilePath() const { return ui->filePathEdit->text(); } -QString AddTableFileDlg::getDescription() const { - return ui->descriptionEdit->toPlainText().trimmed(); -} - -AddTableFileDlg::TableParams AddTableFileDlg::getTableParams() const { - TableParams params; - - // Get delimiter from combo box - int index = ui->separatorComboBox->currentIndex(); - switch (index) { - case 0: params.delimiter = ","; break; - case 1: params.delimiter = "\t"; break; - case 2: params.delimiter = " "; break; - case 3: params.delimiter = ";"; break; - default: params.delimiter = ","; break; +void AddTableFileDlg::accept() +{ + // Validate parameters + if (!validateSpecificParams()) { + return; } - params.hasHeader = ui->hasHeaderCheckBox->isChecked(); - params.xColumn = 1; // Default values - params.yColumn = 2; - params.description = ui->descriptionEdit->toPlainText().trimmed(); - return params; -} \ No newline at end of file + // Validate table-specific parameters + if (ui->tableNameEdit->text().isEmpty()) { + QMessageBox::warning(this, tr("Warning"), tr("Please enter a table name.")); + return; + } + + + // Create FileEntryTable using factory function + auto fileEntry = CreateFileEntryTable(getSelectedFilePath()); + if (!fileEntry) { + QMessageBox::critical(this, tr("Error"), tr("Failed to create table file entry.")); + return; + } + + // Set table headers if provided + QString headersText = ui->headersEdit->text().trimmed(); + if (!headersText.isEmpty()) { + QStringList headers = headersText.split(',', Qt::SkipEmptyParts); + for (QString& header : headers) { + header = header.trimmed(); + } + fileEntry->SetTableHeaders(headers); + } + + // Set chart properties + FileEntryTable::ChartProperties chartProps; + chartProps.timeParam = ui->timeParamSpinBox->value(); + fileEntry->SetChartProperties(chartProps); + + // Set description (using table name as description for now) + fileEntry->SetDescription(ui->tableNameEdit->text()); + + // Add to workspace + WorkSpace* workspace = WorkSpaceManager::Get().GetCurrent(); + if (!workspace) { + QMessageBox::critical(this, tr("Error"), tr("Unable to get current workspace")); + return; + } + + // Add FileEntryTable to workspace using SetFileEntry method + auto result = workspace->SetFileEntry(fileEntry); + if (result != WorkSpace::FileEntryResult::Ok) { + QString errorMsg; + switch (result) { + case WorkSpace::FileEntryResult::LimitExceeded: + errorMsg = tr("Table file count has reached the limit"); + break; + case WorkSpace::FileEntryResult::Duplicate: + errorMsg = tr("File already exists"); + break; + case WorkSpace::FileEntryResult::CopyFailed: + errorMsg = tr("File copy failed"); + break; + case WorkSpace::FileEntryResult::InvalidFile: + errorMsg = tr("Invalid file"); + break; + default: + errorMsg = tr("Failed to add file"); + break; + } + QMessageBox::warning(this, tr("Error"), errorMsg); + return; + } + + LOG_INFO("Added table file to workspace: {}", getSelectedFilePath().toUtf8().constData()); + QDialog::accept(); +} diff --git a/src/ui/WorkSpace/AddTableFileDlg.h b/src/ui/WorkSpace/AddTableFileDlg.h index 8ed648b3..8bc6b34b 100644 --- a/src/ui/WorkSpace/AddTableFileDlg.h +++ b/src/ui/WorkSpace/AddTableFileDlg.h @@ -21,9 +21,7 @@ public: explicit AddTableFileDlg(QWidget* parent = nullptr); ~AddTableFileDlg() override; - TableParams getTableParams() const; QString getSelectedFilePath() const; - QString getDescription() const; protected: QString getFileFilter() const override; @@ -36,6 +34,9 @@ private slots: void onDelimiterChanged(); void onHeaderToggled(bool hasHeader); +public slots: + void accept() override; + private: void setupConnections(); void updateFileInfo(const QString& filePath); diff --git a/src/ui/WorkSpace/AddTableFileDlg.ui b/src/ui/WorkSpace/AddTableFileDlg.ui index 9dac6bdc..55192b32 100644 --- a/src/ui/WorkSpace/AddTableFileDlg.ui +++ b/src/ui/WorkSpace/AddTableFileDlg.ui @@ -6,8 +6,8 @@ 0 0 - 480 - 450 + 676 + 683 @@ -29,12 +29,12 @@ - - Select table data file... - true + + Select table data file... + @@ -76,50 +76,125 @@ - + - Table Parameters + Basic Information - - - - - Separator: + + + + + 3 + + + 0.000000000000000 + + + 999999.000000000000000 + + + 1.000000000000000 - - - - - Comma (,) - - - - - Tab - - - - - Space - - - - - Semicolon (;) - - + + + + Enter table name... + + + + + + + Table Name: + + + + Time Parameter: + + + + + + + + + + Table Headers Configuration + + + + + + File has header row + + + true + + + + + + + Headers (comma-separated): + + + + + + + e.g., Time, Value1, Value2, Value3... + + + + + + + color: gray; font-size: 11px; + + + Tip: Headers will be auto-detected if file has header row + + + + + + + + + + Parsing Parameters + + + + + + Skip Rows: + + + + + + + Auto-detect parameters + + + true + + + + Encoding: - + @@ -143,14 +218,7 @@ - - - - Skip Rows: - - - - + 0 @@ -163,26 +231,6 @@ - - - - File has header row - - - true - - - - - - - Auto-detect parameters - - - true - - - @@ -212,46 +260,21 @@ 5 + + + + + + + + + + - - - - Description (Optional) - - - - - - - 16777215 - 60 - - - - Enter file description... - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -290,4 +313,4 @@ - \ No newline at end of file + diff --git a/src/workspace/FileEntry.cpp b/src/workspace/FileEntry.cpp index 9598ecc5..aa3ea179 100644 --- a/src/workspace/FileEntry.cpp +++ b/src/workspace/FileEntry.cpp @@ -59,14 +59,17 @@ std::shared_ptr CreateFileEntrySurface(const QString& 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); +std::shared_ptr CreateFileEntryTable(const QString& filePath) { + QFileInfo fileInfo(filePath); + if (!filePath.isEmpty() && !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; } @@ -123,4 +126,61 @@ void FileEntrySurface::SetDescription(const QString& description) { const QString& FileEntrySurface::GetDescription() const { return description_; +} + +// 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_; } \ No newline at end of file diff --git a/src/workspace/FileEntry.h b/src/workspace/FileEntry.h index a3791cfe..acb5f64e 100644 --- a/src/workspace/FileEntry.h +++ b/src/workspace/FileEntry.h @@ -32,6 +32,7 @@ inline bool FileEntryTypeFromString(const char* s, FileEntryType& out) { class FileEntryCurve; class FileEntryLight; class FileEntrySurface; +class FileEntryTable; class FileEntry { public: @@ -52,6 +53,7 @@ public: virtual FileEntryCurve* AsCurve() { return nullptr; } virtual FileEntryLight* AsLight() { return nullptr; } virtual FileEntrySurface* AsSurface() { return nullptr; } + virtual FileEntryTable* AsTable() { return nullptr; } protected: FileEntryType type_; @@ -64,7 +66,7 @@ protected: std::shared_ptr CreateFileEntry(FileEntryType type, const QString& filePath); std::shared_ptr CreateFileEntryCurve(const QString& filePath); std::shared_ptr CreateFileEntrySurface(const QString& filePath); -std::shared_ptr CreateFileEntryTable(const QString& filePath); +std::shared_ptr CreateFileEntryTable(const QString& filePath); std::shared_ptr CreateFileEntryLight(const QString& filePath); @@ -163,6 +165,54 @@ private: QString description_; }; +class FileEntryTable : public FileEntry { +public: + struct ChartProperties { + QString name; + QString path; + double timeParam; + }; + + struct TableProperty { + QString name; + QColor color; + QList datas; + }; + + using TableProperties = QList; + +public: + FileEntryTable() { type_ = FileEntryType::Table; } + + // Chart properties management + void SetChartProperties(const ChartProperties& properties); + const ChartProperties& GetChartProperties() const; + + // Table properties management + void AddTableProperty(const TableProperty& table); + void RemoveTableProperty(int index); + void SetTableProperty(int index, const TableProperty& table); + const TableProperties& GetTableProperties() const; + + // Table headers management + void SetTableHeaders(const QStringList& headers); + void SetTableHeaders(const QString& headerString); // Parse from comma-separated string + const QStringList& GetTableHeaders() const; + + // Type conversion + FileEntryTable* AsTable() override; + + // Description management + void SetDescription(const QString& description); + const QString& GetDescription() const; + +private: + ChartProperties chartProperties_; + QStringList tableHeaders_; + TableProperties tableProperties_; + QString description_; +}; + class FileEntryLight : public FileEntry { public: struct ColorProperties {