From 00b909348159d91382630b7b675973ba5f97304d Mon Sep 17 00:00:00 2001 From: pimin <362371171@qq.com> Date: Sat, 1 Nov 2025 12:43:16 +0800 Subject: [PATCH] modified addPolarDlg --- src/ui/Menu/SimuRunMenu.cpp | 2 + src/ui/Panel/DataPanelManager.cpp | 16 +- src/ui/Panel/PolarPanel.cpp | 20 +- src/ui/Panel/PolarPanel.h | 4 +- src/ui/WorkSpace/AddCurveFileDlg.ui | 2 +- src/ui/WorkSpace/AddLightFileDlg.ui | 2 +- src/ui/WorkSpace/AddPolarDlg.ui | 540 +++++++++++++----------- src/ui/WorkSpace/AddPolarFileDlg.cpp | 610 +++++++++++++++++++++------ src/ui/WorkSpace/AddPolarFileDlg.h | 20 + src/ui/WorkSpace/AddTableFileDlg.ui | 2 +- 10 files changed, 824 insertions(+), 394 deletions(-) diff --git a/src/ui/Menu/SimuRunMenu.cpp b/src/ui/Menu/SimuRunMenu.cpp index ca859267..3cb296b4 100644 --- a/src/ui/Menu/SimuRunMenu.cpp +++ b/src/ui/Menu/SimuRunMenu.cpp @@ -29,6 +29,8 @@ SimuRunMenu::SimuRunMenu(QWidget *parent) // Initial population RefreshButtons(); + + setObjectName("SimuRunMenu"); } SimuRunMenu::~SimuRunMenu() { diff --git a/src/ui/Panel/DataPanelManager.cpp b/src/ui/Panel/DataPanelManager.cpp index 636259d1..7657e01d 100644 --- a/src/ui/Panel/DataPanelManager.cpp +++ b/src/ui/Panel/DataPanelManager.cpp @@ -310,14 +310,20 @@ int DataPanelManager::FindNextAvailableIndex(FileEntryType fileType) const QSet usedIndices; QString typeStr = FileEntryTypeToString(fileType); - for (auto it = dataPanels_.constBegin(); it != dataPanels_.constEnd(); ++it) { - if (it.value()->GetFileType() == fileType) { - usedIndices.insert(it.value()->GetIndex()); + for (auto it = dataPanels_.constBegin(); it != dataPanels_.constEnd(); ++it) + { + FileEntryType type = it.value()->GetFileType(); + if (type == fileType) + { + int nIndex = it.value()->GetIndex(); + usedIndices.insert(nIndex); } } - for (int i = 0; i < GetMaxPanelCount(); ++i) { - if (!usedIndices.contains(i)) { + for (int i = 0; i < GetMaxPanelCount(); ++i) + { + if (!usedIndices.contains(i)) + { return i; } } diff --git a/src/ui/Panel/PolarPanel.cpp b/src/ui/Panel/PolarPanel.cpp index 979e6470..56384fdb 100644 --- a/src/ui/Panel/PolarPanel.cpp +++ b/src/ui/Panel/PolarPanel.cpp @@ -122,9 +122,9 @@ void PolarPanel::OnTimeChanged(double time) { if (m_data.size() > 0) { - for (QMap::Iterator itSeries = m_seriesIDMap.begin(); itSeries != m_seriesIDMap.end(); itSeries++) + for (QMap::Iterator itSeries = m_seriesIDMap.begin(); itSeries != m_seriesIDMap.end(); itSeries++) { - QLineSeries * pSeries = itSeries.value(); + QScatterSeries * pSeries = itSeries.value(); if (pSeries) { pSeries->clear(); @@ -132,21 +132,21 @@ void PolarPanel::OnTimeChanged(double time) } QMap< double, QMap >::const_iterator ite = m_data.lowerBound(time); - if (ite != m_data.end()) + if (ite == m_data.end()) { - ite++; + ite--; } - for (QMap< double, QMap >::Iterator itA = m_data.begin(); itA != ite; itA++) + //for (QMap< double, QMap >::Iterator itA = m_data.begin(); itA != ite; itA++) { - double dTime = itA.key(); - QMap mapData = itA.value(); + double dTime = ite.key(); + QMap mapData = ite.value(); for (QMap::Iterator it = mapData.begin(); it != mapData.end(); it++) { int nIndex = it.key(); QPointF data = it.value(); - QLineSeries * pSeries = m_seriesIDMap.value(nIndex); + QScatterSeries * pSeries = m_seriesIDMap.value(nIndex); if (pSeries) { pSeries->append(data); @@ -244,6 +244,7 @@ void PolarPanel::updateParseFile(const QString& strFile, int nT, FileEntryPolar: return; } + m_pChart->removeAllSeries(); m_seriesIDMap.clear(); QFile file(strFile); @@ -324,9 +325,10 @@ void PolarPanel::updateParseFile(const QString& strFile, int nT, FileEntryPolar: { FileEntryPolar::LineProperty propCurve = listCurve.at(nI); - QLineSeries *pSeries = new QLineSeries(this); + QScatterSeries *pSeries = new QScatterSeries(this); pSeries->setName(propCurve.name); pSeries->setColor(propCurve.color); + pSeries->setMarkerSize(7); pSeries->setUseOpenGL(true); m_pChart->addSeries(pSeries); m_seriesIDMap.insert(nI, pSeries); diff --git a/src/ui/Panel/PolarPanel.h b/src/ui/Panel/PolarPanel.h index 2eb1653e..49aef83c 100644 --- a/src/ui/Panel/PolarPanel.h +++ b/src/ui/Panel/PolarPanel.h @@ -36,7 +36,7 @@ public: * @brief Get file type * @return File type (always Curve for this class) */ - FileEntryType GetFileType() const override { return FileEntryType::Table; } + FileEntryType GetFileType() const override { return FileEntryType::Polar; } /** * @brief Refresh panel content @@ -80,7 +80,7 @@ private: QString m_unitTheta; QString m_unitRadius; - QMap m_seriesIDMap; + QMap m_seriesIDMap; QMap< double, QMap > m_data; }; diff --git a/src/ui/WorkSpace/AddCurveFileDlg.ui b/src/ui/WorkSpace/AddCurveFileDlg.ui index a18c17d3..58a6b54b 100644 --- a/src/ui/WorkSpace/AddCurveFileDlg.ui +++ b/src/ui/WorkSpace/AddCurveFileDlg.ui @@ -531,7 +531,7 @@ - true + false diff --git a/src/ui/WorkSpace/AddLightFileDlg.ui b/src/ui/WorkSpace/AddLightFileDlg.ui index c45f4c23..22a35667 100644 --- a/src/ui/WorkSpace/AddLightFileDlg.ui +++ b/src/ui/WorkSpace/AddLightFileDlg.ui @@ -323,7 +323,7 @@ - true + false diff --git a/src/ui/WorkSpace/AddPolarDlg.ui b/src/ui/WorkSpace/AddPolarDlg.ui index 062e002d..ce040d40 100644 --- a/src/ui/WorkSpace/AddPolarDlg.ui +++ b/src/ui/WorkSpace/AddPolarDlg.ui @@ -6,15 +6,15 @@ 0 0 - 600 - 789 + 580 + 756 Add Polar - - + + File Selection @@ -117,14 +117,14 @@ - - + + - Chart Properties + Angular Axis - + - + 0 @@ -132,28 +132,25 @@ - Chart Name: + Title: - + 0 25 - - Chart 1 - - Enter chart name... + Enter axis title... - + 0 @@ -161,157 +158,12 @@ - Chart Type: + Min: - - - - 0 - 25 - - - - - - - - - 0 - 25 - - - - X Axis Title: - - - - - - - - 0 - 25 - - - - Enter X axis title... - - - - - - - - 0 - 25 - - - - Y Axis Title: - - - - - - - - 0 - 25 - - - - Enter Y axis title... - - - - - - - - 0 - 25 - - - - Time: - - - - - - - - 0 - 25 - - - - - - - - - - - Axis Range Settings - - - - - - - 0 - 25 - - - - -999999.000000000000000 - - - 999999.000000000000000 - - - 800.000000000000000 - - - - - - - - 0 - 25 - - - - 2 - - - 50 - - - 6 - - - - - - - - 0 - 25 - - - - X Tick Count: - - - - - + 0 @@ -329,33 +181,7 @@ - - - - - 0 - 25 - - - - X Min: - - - - - - - - 0 - 25 - - - - Y Max: - - - - + @@ -364,12 +190,44 @@ - Y Min: + Max: - - + + + + + 0 + 25 + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 360.000000000000000 + + + + + + + + 0 + 25 + + + + Count: + + + + + 0 @@ -383,50 +241,12 @@ 50 - 9 + 13 - - - - - 0 - 25 - - - - -999999.000000000000000 - - - 999999.000000000000000 - - - -800.000000000000000 - - - - - - - - 0 - 25 - - - - -999999.000000000000000 - - - 999999.000000000000000 - - - 250.000000000000000 - - - - - + + 0 @@ -434,11 +254,123 @@ - X Max: + Unit: - + + + + + 0 + 25 + + + + Enter axis Unit... + + + + + + + + + + Radial Axis + + + + + + + 0 + 25 + + + + Title: + + + + + + + + 0 + 25 + + + + Enter axis title... + + + + + + + + 0 + 25 + + + + Min: + + + + + + + + 0 + 25 + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 0.000000000000000 + + + + + + + + 0 + 25 + + + + Max: + + + + + + + + 0 + 25 + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 0.000000000000000 + + + + @@ -447,14 +379,59 @@ - Y Tick Count: + Count: + + + + + + + + 0 + 25 + + + + 2 + + + 50 + + + 6 + + + + + + + + 0 + 25 + + + + Unit: + + + + + + + + 0 + 25 + + + + Enter axis Unit... - + Curve Management @@ -497,7 +474,7 @@ - Add Curve + Add @@ -531,7 +508,7 @@ - true + false @@ -553,7 +530,7 @@ - Curve Name: + Name: @@ -579,7 +556,7 @@ - Curve Color: + Color: @@ -644,12 +621,12 @@ - Data Start: + Angular: - + 0 @@ -657,13 +634,13 @@ - 1 + 0 999999 - 1 + 0 @@ -676,12 +653,12 @@ - Data Stop: + Radial: - + 0 @@ -689,13 +666,13 @@ - 1 + 0 999999 - 241 + 0 @@ -757,7 +734,7 @@ - + @@ -803,6 +780,67 @@ + + + + Chart Properties + + + + + + + 0 + 25 + + + + + + + + + 0 + 25 + + + + Time: + + + + + + + + 0 + 25 + + + + Chart Name: + + + + + + + + 0 + 25 + + + + Chart 1 + + + Enter chart name... + + + + + + diff --git a/src/ui/WorkSpace/AddPolarFileDlg.cpp b/src/ui/WorkSpace/AddPolarFileDlg.cpp index 477f46a7..8eb15c3b 100644 --- a/src/ui/WorkSpace/AddPolarFileDlg.cpp +++ b/src/ui/WorkSpace/AddPolarFileDlg.cpp @@ -20,8 +20,7 @@ AddPolarFileDlg::AddPolarFileDlg(QWidget* parent) SetupUI(ui); SetTitle(getDialogTitle()); - //setupConnections(); - //updateCurvePropertiesUI(); // Initialize UI based on default chart type + setupConnections(); } AddPolarFileDlg::~AddPolarFileDlg() { @@ -29,177 +28,151 @@ AddPolarFileDlg::~AddPolarFileDlg() { } -QString AddPolarFileDlg::getFileFilter() const { +QString AddPolarFileDlg::getFileFilter() const +{ return "Data Files (*.txt *.csv *.dat);;All Files (*.*)"; } -QString AddPolarFileDlg::getDialogTitle() const { - return "Add Polar Data File"; +QString AddPolarFileDlg::getDialogTitle() const +{ + return "Add Polar"; } -bool AddPolarFileDlg::validateSpecificParams() { +bool AddPolarFileDlg::validateSpecificParams() +{ // File path validation const QString& selectFilePath = getSelectedFilePath(); - if (selectFilePath.isEmpty()) { + if (selectFilePath.isEmpty()) + { QMessageBox::warning(this, tr("Validation Error"), tr("Please select a data file.")); return false; } // File existence validation QFileInfo fileInfo(selectFilePath); - if (!fileInfo.exists()) { + if (!fileInfo.exists()) + { QMessageBox::warning(this, tr("Validation Error"), tr("Selected file does not exist.")); return false; } // File readability validation - if (!fileInfo.isReadable()) { + if (!fileInfo.isReadable()) + { QMessageBox::warning(this, tr("Validation Error"), tr("Selected file is not readable. Please check file permissions.")); return false; } // File size validation (avoid memory issues with large files) - if (fileInfo.size() > 100 * 1024 * 1024) { // 100MB limit + if (fileInfo.size() > 100 * 1024 * 1024) + { // 100MB limit QMessageBox::warning(this, tr("Validation Error"), tr("File is too large (over 100MB). Please select a smaller file.")); return false; } // Curve count validation - if (curves_.isEmpty()) { + if (curves_.isEmpty()) + { QMessageBox::warning(this, tr("Validation Error"), tr("At least one curve must be defined.")); return false; } - //// Save current curve properties - //if (currentCurveIndex_ >= 0) { - // saveCurveProperties(); - //} + // Save current curve properties + if (currentCurveIndex_ >= 0) + { + saveCurveProperties(); + } - //// Curve name uniqueness validation - //QStringList curveNames; - //for (int i = 0; i < curves_.size(); ++i) { - // const FileEntryCurve::CurveProperty& curve = curves_[i]; + // Curve name uniqueness validation + QStringList curveNames; + for (int i = 0; i < curves_.size(); ++i) + { + const FileEntryPolar::LineProperty& curve = curves_[i]; - // if (curve.name.isEmpty()) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve %1 name cannot be empty.").arg(i + 1)); - // return false; - // } + if (curve.name.isEmpty()) + { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve %1 name cannot be empty.").arg(i + 1)); + return false; + } - // if (curveNames.contains(curve.name)) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve name '%1' is duplicated. Please use different names.").arg(curve.name)); - // return false; - // } - // curveNames.append(curve.name); + if (curveNames.contains(curve.name)) + { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve name '%1' is duplicated. Please use different names.").arg(curve.name)); + return false; + } + curveNames.append(curve.name); - // // Curve name length validation - // if (curve.name.length() > 50) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve name '%1' is too long. Please limit to 50 characters.").arg(curve.name)); - // return false; - // } + // Curve name length validation + if (curve.name.length() > 50) + { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve name '%1' is too long. Please limit to 50 characters.").arg(curve.name)); + return false; + } - // // Data range validation based on chart type - // if (chartProperties_.chartType == ChartType::Wave) { - // if (curve.data.wave.start < 1 || curve.data.wave.stop < 1) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' start and stop values must be greater than 0.").arg(curve.name)); - // return false; - // } + // Report type validation - ensure x and y values are reasonable + if (curve.Angular < -1000000 || curve.Angular > 1000000) + { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' X value is out of range. Please ensure it is between -1000000 and 1000000.").arg(curve.name)); + return false; + } - // if (curve.data.wave.start > curve.data.wave.stop) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' start value cannot be greater than stop value.").arg(curve.name)); - // return false; - // } + if (curve.Radial < -1000000 || curve.Radial > 1000000) + { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' Y value is out of range. Please ensure it is between -1000000 and 1000000.").arg(curve.name)); + return false; + } + } - // // Data range reasonableness validation - // if (curve.data.wave.stop - curve.data.wave.start < 1) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' data range is too small. At least 2 data points are required.").arg(curve.name)); - // return false; - // } + // Chart properties validation + if (ui->chartNameEdit->text().isEmpty()) + { + QMessageBox::warning(this, tr("Validation Error"), tr("Chart name cannot be empty.")); + return false; + } - // if (curve.data.wave.stop > 1000000) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' stop value is too large. Please ensure it does not exceed 1000000.").arg(curve.name)); - // return false; - // } - // } - // else { - // // Report type validation - ensure x and y values are reasonable - // if (curve.data.report.x < -1000000 || curve.data.report.x > 1000000) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' X value is out of range. Please ensure it is between -1000000 and 1000000.").arg(curve.name)); - // return false; - // } + if (ui->chartNameEdit->text().length() > 100) + { + QMessageBox::warning(this, tr("Validation Error"), tr("Chart name is too long. Please limit to 100 characters.")); + return false; + } - // if (curve.data.report.y < -1000000 || curve.data.report.y > 1000000) { - // QMessageBox::warning(this, tr("Validation Error"), - // tr("Curve '%1' Y value is out of range. Please ensure it is between -1000000 and 1000000.").arg(curve.name)); - // return false; - // } - // } - //} + // Axis range validation + double AngularMin = ui->SpinBox_Min_Angular->value(); + double AngularMax = ui->SpinBox_Max_Angular->value(); + double RadialMin = ui->SpinBox_Min_Radial->value(); + double RadialMax = ui->SpinBox_Max_Radial->value(); - //// Chart properties validation - //if (ui->chartNameEdit->text().isEmpty()) { - // QMessageBox::warning(this, tr("Validation Error"), tr("Chart name cannot be empty.")); - // return false; - //} + if (AngularMin > AngularMax) + { + QMessageBox::warning(this, tr("Validation Error"), tr("Angular axis minimum value must be less than maximum value.")); + return false; + } - //if (ui->chartNameEdit->text().length() > 100) { - // QMessageBox::warning(this, tr("Validation Error"), tr("Chart name is too long. Please limit to 100 characters.")); - // return false; - //} - - //// Axis title validation - //if (ui->xTitleEdit->text().length() > 50) { - // QMessageBox::warning(this, tr("Validation Error"), tr("X axis title is too long. Please limit to 50 characters.")); - // return false; - //} - - //if (ui->yTitleEdit->text().length() > 50) { - // QMessageBox::warning(this, tr("Validation Error"), tr("Y axis title is too long. Please limit to 50 characters.")); - // return false; - //} - - //// Axis range validation - //double xMin = ui->xMinSpinBox->value(); - //double xMax = ui->xMaxSpinBox->value(); - //double yMin = ui->yMinSpinBox->value(); - //double yMax = ui->yMaxSpinBox->value(); - - //if (xMin >= xMax) { - // QMessageBox::warning(this, tr("Validation Error"), tr("X axis minimum value must be less than maximum value.")); - // return false; - //} - - //if (yMin >= yMax) { - // QMessageBox::warning(this, tr("Validation Error"), tr("Y axis minimum value must be less than maximum value.")); - // return false; - //} + if (RadialMin > RadialMax) + { + QMessageBox::warning(this, tr("Validation Error"), tr("Radial axis minimum value must be less than maximum value.")); + return false; + } - //// Time parameter validation - //double timeParam = ui->timeParamSpinBox->value(); - //if (timeParam < 0) { - // QMessageBox::warning(this, tr("Validation Error"), tr("Time parameter cannot be negative.")); - // return false; - //} - - //// X axis tick count validation - //int xTickCount = ui->xCountSpinBox->value(); - //if (xTickCount < 2) { - // QMessageBox::warning(this, tr("Validation Error"), tr("X axis tick count must be at least 2.")); - // return false; - //} + // Time parameter validation + double timeParam = ui->SpinBox_time->value(); + if (timeParam < 0) + { + QMessageBox::warning(this, tr("Validation Error"), tr("Time parameter cannot be negative.")); + return false; + } return true; } -void AddPolarFileDlg::updateFileInfo(const QString& filePath) { +void AddPolarFileDlg::updateFileInfo(const QString& filePath) +{ QFileInfo fileInfo(filePath); if (fileInfo.exists()) { ui->fileNameValue->setText(fileInfo.fileName()); @@ -222,4 +195,393 @@ void AddPolarFileDlg::updateFileInfo(const QString& filePath) { } ui->filePathEdit->setText(filePath); +} + +void AddPolarFileDlg::setupConnections() +{ + // File selection connections + connect(ui->selectFileBtn, &QToolButton::clicked, this, &AddPolarFileDlg::OnSelectFile); + + // Curve management connections + connect(ui->addCurveBtn, &QPushButton::clicked, this, &AddPolarFileDlg::onAddCurveClicked); + connect(ui->removeCurveBtn, &QPushButton::clicked, this, &AddPolarFileDlg::onRemoveCurveClicked); + connect(ui->curveListWidget, &QListWidget::currentRowChanged, this, &AddPolarFileDlg::onCurveSelectionChanged); + connect(ui->curveListWidget, &QListWidget::itemClicked, this, &AddPolarFileDlg::onCurveListWidgetItemClicked); + + // Curve properties connections + connect(ui->colorButton, &QPushButton::clicked, this, &AddPolarFileDlg::onColorButtonClicked); + connect(ui->curveNameEdit, &QLineEdit::textChanged, this, &AddPolarFileDlg::onCurveNameChanged); + connect(ui->SpinBox_Angular, QOverload::of(&QSpinBox::valueChanged), this, &AddPolarFileDlg::onCurveDataChanged); + connect(ui->SpinBox_Radial, QOverload::of(&QSpinBox::valueChanged), this, &AddPolarFileDlg::onCurveDataChanged); + + // Dialog buttons + connect(ui->addBtn, &QPushButton::clicked, this, &AddPolarFileDlg::onSure); + connect(ui->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); +} + +void AddPolarFileDlg::onColorButtonClicked() +{ + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + QColor color = QColorDialog::getColor(curves_[currentCurveIndex_].color, this, "Select Curve Color"); + if (color.isValid()) + { + curves_[currentCurveIndex_].color = color; + selectedColor_ = color; + updateColorPreview(color); + + // Update list item text + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) + { + QString itemText = QString("%1 (%2,%3) (%4,%5,%6)") + .arg(curves_[currentCurveIndex_].name) + .arg(curves_[currentCurveIndex_].Angular) + .arg(curves_[currentCurveIndex_].Radial) + .arg(color.red()) + .arg(color.green()) + .arg(color.blue()); + + item->setText(itemText); + } + } + } +} + +void AddPolarFileDlg::updateColorPreview(const QColor& color) +{ + QString styleSheet = QString("background-color: rgb(%1, %2, %3); border: 1px solid black;") + .arg(color.red()) + .arg(color.green()) + .arg(color.blue()); + ui->colorPreview->setStyleSheet(styleSheet); +} + +void AddPolarFileDlg::onAddCurveClicked() +{ + // Save current curve properties if any curve is selected + if (currentCurveIndex_ >= 0) + { + saveCurveProperties(); + } + + // Create new curve with default properties based on chart type + FileEntryPolar::LineProperty newCurve; + newCurve.name = generateCurveName(); + newCurve.color = generateCurveColor(); + newCurve.Angular = 0.0; + newCurve.Radial = 0.0; + + // Add to curves list and UI + curves_.append(newCurve); + + // Add to UI list widget with appropriate display format + QString displayText = QString("%1 (%2,%3) (%4,%5,%6)") + .arg(newCurve.name) + .arg(newCurve.Angular) + .arg(newCurve.Radial) + .arg(newCurve.color.red()) + .arg(newCurve.color.green()) + .arg(newCurve.color.blue()); + + QListWidgetItem* item = new QListWidgetItem(displayText); + ui->curveListWidget->addItem(item); + ++currentCurveIndex_; + + ui->curveNameEdit->setText(newCurve.name); + + // Select the new curve + ui->curveListWidget->setCurrentRow(curves_.size() - 1); +} + +void AddPolarFileDlg::onRemoveCurveClicked() +{ + int currentRow = ui->curveListWidget->currentRow(); + if (currentRow < 0 || currentRow >= curves_.size()) + { + return; + } + + // Don't allow removing the last curve + if (curves_.size() <= 0) + { + QMessageBox::information(this, "Information", "At least one curve must remain."); + return; + } + + // Remove from curves list and UI + curves_.removeAt(currentRow); + delete ui->curveListWidget->takeItem(currentRow); + + // Update current index + if (currentRow >= curves_.size()) + { + currentRow = curves_.size() - 1; + } + + if (currentRow >= 0) + { + ui->curveListWidget->setCurrentRow(currentRow); + } + else + { + currentCurveIndex_ = -1; + clearCurveProperties(); + enableCurveProperties(false); + } +} + +void AddPolarFileDlg::onCurveListWidgetItemClicked(QListWidgetItem* item) +{ + if (!item) + { + return; + } + + int clickedIndex = ui->curveListWidget->row(item); + + if (clickedIndex == currentCurveIndex_) + { + ui->curveNameEdit->setText(curves_[currentCurveIndex_].name); + + ui->SpinBox_Angular->blockSignals(true); + ui->SpinBox_Angular->setValue(curves_[currentCurveIndex_].Angular); + ui->SpinBox_Angular->blockSignals(false); + + ui->SpinBox_Radial->blockSignals(true); + ui->SpinBox_Radial->setValue(curves_[currentCurveIndex_].Radial); + ui->SpinBox_Radial->blockSignals(false); + + updateColorPreview(curves_[currentCurveIndex_].color); + enableCurveProperties(true); + + ui->curveNameEdit->setFocus(); + ui->curveNameEdit->selectAll(); + } + else + { + onCurveSelectionChanged(); + } +} + +void AddPolarFileDlg::onCurveSelectionChanged() +{ + int currentRow = ui->curveListWidget->currentRow(); + + // Save previous curve properties + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + saveCurveProperties(); + } + + currentCurveIndex_ = currentRow; + + if (currentRow >= 0 && currentRow < curves_.size()) + { + // Load selected curve properties + updateCurveProperties(); + enableCurveProperties(true); + } + else + { + clearCurveProperties(); + enableCurveProperties(false); + } +} + +void AddPolarFileDlg::onCurveNameChanged() +{ + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + QString newName = ui->curveNameEdit->text(); + curves_[currentCurveIndex_].name = newName; + + // Update list item text with appropriate format + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) + { + QString displayText = QString("%1 (%2,%3) (%4,%5,%6)") + .arg(newName) + .arg(curves_[currentCurveIndex_].Angular) + .arg(curves_[currentCurveIndex_].Radial) + .arg(curves_[currentCurveIndex_].color.red()) + .arg(curves_[currentCurveIndex_].color.green()) + .arg(curves_[currentCurveIndex_].color.blue()); + + item->setText(displayText); + } + } +} + +void AddPolarFileDlg::saveCurveProperties() +{ + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + curves_[currentCurveIndex_].name = ui->curveNameEdit->text(); + + // Save properties based on chart type + curves_[currentCurveIndex_].Angular = ui->SpinBox_Angular->value(); + curves_[currentCurveIndex_].Radial = ui->SpinBox_Radial->value(); + + curves_[currentCurveIndex_].color = selectedColor_; + } +} + +void AddPolarFileDlg::clearCurveProperties() +{ + ui->curveNameEdit->clear(); + + // Clear properties based on chart type + ui->SpinBox_Angular->setValue(0.0); + ui->SpinBox_Radial->setValue(0.0); + + selectedColor_ = QColor(255, 0, 0); + updateColorPreview(selectedColor_); +} + +void AddPolarFileDlg::enableCurveProperties(bool enabled) +{ + ui->curvePropertiesGroupBox->setEnabled(enabled); +} + +QString AddPolarFileDlg::generateCurveName() +{ + return tr("Curve %1").arg(curves_.size() + 1); +} + +QColor AddPolarFileDlg::generateCurveColor() const +{ + // Generate different colors for each curve + static const QColor colors[] = { + QColor(255, 0, 0), // Red + QColor(0, 255, 0), // Green + QColor(0, 0, 255), // Blue + QColor(255, 255, 0), // Yellow + QColor(255, 0, 255), // Magenta + QColor(0, 255, 255), // Cyan + QColor(255, 128, 0), // Orange + QColor(128, 0, 255), // Purple + }; + + int colorIndex = curves_.size() % (sizeof(colors) / sizeof(colors[0])); + return colors[colorIndex]; +} + +void AddPolarFileDlg::updateCurveProperties() +{ + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + const FileEntryPolar::LineProperty& curve = curves_[currentCurveIndex_]; + + ui->curveNameEdit->setText(curve.name); + + ui->SpinBox_Angular->blockSignals(true); + ui->SpinBox_Angular->setValue(curve.Angular); + ui->SpinBox_Angular->blockSignals(false); + + ui->SpinBox_Radial->blockSignals(true); + ui->SpinBox_Radial->setValue(curve.Radial); + ui->SpinBox_Radial->blockSignals(false); + + selectedColor_ = curve.color; + updateColorPreview(curve.color); + } +} + +void AddPolarFileDlg::onSure() +{ + if (validateSpecificParams()) + { + // Create FileEntryCurve object using factory function + auto fileEntryPolar = CreateFileEntryPolar(getSelectedFilePath()); + if (!fileEntryPolar) + { + QMessageBox::warning(this, tr("Error"), tr("Failed to create file entry")); + return; + } + + // Set curve properties + fileEntryPolar->SetName(ui->chartNameEdit->text()); + + // Set chart properties + FileEntryPolar::ChartProperties chartProps; + chartProps.AngularCount = ui->SpinBox_Count_Angular->value(); + chartProps.RadialCount = ui->SpinBox_Count_Radial->value(); + chartProps.AngularTitle = ui->TitleEdit_Angular->text(); + chartProps.RadialTitle = ui->TitleEdit_Radial->text(); + chartProps.AngularUnit = ui->TitleEdit_Unit_Angular->text(); + chartProps.RadialUnit = ui->TitleEdit_Unit_Radial->text(); + chartProps.AngularMin = ui->SpinBox_Min_Angular->value(); + chartProps.AngularMax = ui->SpinBox_Max_Angular->value(); + chartProps.RadialMin = ui->SpinBox_Min_Radial->value(); + chartProps.RadialMax = ui->SpinBox_Max_Radial->value(); + chartProps.timeParam = ui->SpinBox_time->value(); + fileEntryPolar->SetChartProperties(chartProps); + + // Add curve properties + for (const auto& curve : curves_) + { + fileEntryPolar->AddLineProperty(curve); + } + + // Get current workspace + WorkSpace* workspace = WorkSpaceManager::Get().GetCurrent(); + if (!workspace) + { + QMessageBox::warning(this, tr("Error"), tr("Unable to get current workspace")); + return; + } + + // Add FileEntryCurve to workspace using new SetFileEntry method + auto result = workspace->SetFileEntry(fileEntryPolar); + if (result != WorkSpace::FileEntryResult::Ok) + { + QString errorMsg; + switch (result) { + case WorkSpace::FileEntryResult::LimitExceeded: + errorMsg = tr("Curve file count has reached the limit (9 files)"); + 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; + } + + accept(); + } +} + +void AddPolarFileDlg::onCurveDataChanged() +{ + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) + { + curves_[currentCurveIndex_].Angular = ui->SpinBox_Angular->value(); + curves_[currentCurveIndex_].Radial = ui->SpinBox_Radial->value(); + + // Update display text in list widget + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) + { + QString itemText = QString("%1 (%2,%3) (%4,%5,%6)") + .arg(curves_[currentCurveIndex_].name) + .arg(curves_[currentCurveIndex_].Angular) + .arg(curves_[currentCurveIndex_].Radial) + .arg(curves_[currentCurveIndex_].color.red()) + .arg(curves_[currentCurveIndex_].color.green()) + .arg(curves_[currentCurveIndex_].color.blue()); + + item->setText(itemText); + } + } } \ No newline at end of file diff --git a/src/ui/WorkSpace/AddPolarFileDlg.h b/src/ui/WorkSpace/AddPolarFileDlg.h index e12fa42a..dec73d7c 100644 --- a/src/ui/WorkSpace/AddPolarFileDlg.h +++ b/src/ui/WorkSpace/AddPolarFileDlg.h @@ -31,6 +31,26 @@ protected: bool validateSpecificParams() override; void updateFileInfo(const QString& filePath) override; +private slots: + void onColorButtonClicked(); + void onAddCurveClicked(); + void onRemoveCurveClicked(); + void onCurveListWidgetItemClicked(class QListWidgetItem* item); + void onCurveSelectionChanged(); + void onCurveNameChanged(); + void onCurveDataChanged(); + void onSure(); + +private: + void setupConnections(); + void updateColorPreview(const QColor& color); + void updateCurveProperties(); + void saveCurveProperties(); + void clearCurveProperties(); + void enableCurveProperties(bool enabled); + QString generateCurveName(); + QColor generateCurveColor() const; + private: Ui::AddPolarDlg* ui; int currentCurveIndex_; diff --git a/src/ui/WorkSpace/AddTableFileDlg.ui b/src/ui/WorkSpace/AddTableFileDlg.ui index d05c4d1e..5b8fa377 100644 --- a/src/ui/WorkSpace/AddTableFileDlg.ui +++ b/src/ui/WorkSpace/AddTableFileDlg.ui @@ -372,7 +372,7 @@ - true + false