modified addPolarDlg

This commit is contained in:
pimin 2025-11-01 12:43:16 +08:00
parent 0fb6395f06
commit 00b9093481
10 changed files with 824 additions and 394 deletions

View File

@ -29,6 +29,8 @@ SimuRunMenu::SimuRunMenu(QWidget *parent)
// Initial population
RefreshButtons();
setObjectName("SimuRunMenu");
}
SimuRunMenu::~SimuRunMenu() {

View File

@ -310,14 +310,20 @@ int DataPanelManager::FindNextAvailableIndex(FileEntryType fileType) const
QSet<int> 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;
}
}

View File

@ -122,9 +122,9 @@ void PolarPanel::OnTimeChanged(double time)
{
if (m_data.size() > 0)
{
for (QMap<int, QLineSeries *>::Iterator itSeries = m_seriesIDMap.begin(); itSeries != m_seriesIDMap.end(); itSeries++)
for (QMap<int, QScatterSeries *>::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<int, QPointF> >::const_iterator ite = m_data.lowerBound(time);
if (ite != m_data.end())
if (ite == m_data.end())
{
ite++;
ite--;
}
for (QMap< double, QMap<int, QPointF> >::Iterator itA = m_data.begin(); itA != ite; itA++)
//for (QMap< double, QMap<int, QPointF> >::Iterator itA = m_data.begin(); itA != ite; itA++)
{
double dTime = itA.key();
QMap<int, QPointF> mapData = itA.value();
double dTime = ite.key();
QMap<int, QPointF> mapData = ite.value();
for (QMap<int, QPointF>::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);

View File

@ -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<int, QLineSeries *> m_seriesIDMap;
QMap<int, QScatterSeries *> m_seriesIDMap;
QMap< double, QMap<int, QPointF> > m_data;
};

View File

@ -531,7 +531,7 @@
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>

View File

@ -323,7 +323,7 @@
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>

View File

@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>789</height>
<width>580</width>
<height>756</height>
</rect>
</property>
<property name="windowTitle">
<string>Add Polar</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="fileGroupBox">
<property name="title">
<string>File Selection</string>
@ -117,14 +117,14 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="chartGroupBox">
<item row="2" column="0">
<widget class="QGroupBox" name="axisRangeGroupBox">
<property name="title">
<string>Chart Properties</string>
<string>Angular Axis</string>
</property>
<layout class="QGridLayout" name="chartGridLayout">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="chartNameLabel">
<widget class="QLabel" name="xTitleLabel_2">
<property name="minimumSize">
<size>
<width>0</width>
@ -132,28 +132,25 @@
</size>
</property>
<property name="text">
<string>Chart Name:</string>
<string>Title:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="chartNameEdit">
<widget class="QLineEdit" name="TitleEdit_Angular">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Chart 1</string>
</property>
<property name="placeholderText">
<string>Enter chart name...</string>
<string>Enter axis title...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="chartTypeLabel">
<widget class="QLabel" name="xMinLabel">
<property name="minimumSize">
<size>
<width>0</width>
@ -161,157 +158,12 @@
</size>
</property>
<property name="text">
<string>Chart Type:</string>
<string>Min:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="chartTypeComboBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="xTitleLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>X Axis Title:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="xTitleEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="placeholderText">
<string>Enter X axis title...</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="yTitleLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Y Axis Title:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="yTitleEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="placeholderText">
<string>Enter Y axis title...</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="timeParamLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="timeParamSpinBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="axisRangeGroupBox">
<property name="title">
<string>Axis Range Settings</string>
</property>
<layout class="QGridLayout" name="axisRangeGridLayout">
<item row="1" column="3">
<widget class="QDoubleSpinBox" name="yMaxSpinBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>800.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="xCountSpinBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>6</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="xCountLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>X Tick Count:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="xMinSpinBox">
<widget class="QDoubleSpinBox" name="SpinBox_Min_Angular">
<property name="minimumSize">
<size>
<width>0</width>
@ -329,33 +181,7 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="xMinLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>X Min:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="yMaxLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Y Max:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="yMinLabel">
<property name="minimumSize">
<size>
@ -364,12 +190,44 @@
</size>
</property>
<property name="text">
<string>Y Min:</string>
<string>Max:</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QSpinBox" name="yCountSpinBox">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="SpinBox_Max_Angular">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>360.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="xCountLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Count:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="SpinBox_Count_Angular">
<property name="minimumSize">
<size>
<width>0</width>
@ -383,50 +241,12 @@
<number>50</number>
</property>
<property name="value">
<number>9</number>
<number>13</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="yMinSpinBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>-800.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QDoubleSpinBox" name="xMaxSpinBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>250.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="xMaxLabel">
<item row="4" column="0">
<widget class="QLabel" name="xTitleLabel_3">
<property name="minimumSize">
<size>
<width>0</width>
@ -434,11 +254,123 @@
</size>
</property>
<property name="text">
<string>X Max:</string>
<string>Unit:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<item row="4" column="1">
<widget class="QLineEdit" name="TitleEdit_Unit_Angular">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="placeholderText">
<string>Enter axis Unit...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
<widget class="QGroupBox" name="axisRangeGroupBox_2">
<property name="title">
<string>Radial Axis</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="xTitleLabel_4">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Title:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="TitleEdit_Radial">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="placeholderText">
<string>Enter axis title...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="xMinLabel_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="SpinBox_Min_Radial">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="yMinLabel_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="SpinBox_Max_Radial">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<double>-999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="xCountLabel_2">
<property name="minimumSize">
<size>
@ -447,14 +379,59 @@
</size>
</property>
<property name="text">
<string>Y Tick Count:</string>
<string>Count:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="SpinBox_Count_Radial">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>6</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="xTitleLabel_5">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Unit:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="TitleEdit_Unit_Radial">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="placeholderText">
<string>Enter axis Unit...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="curveGroupBox">
<property name="title">
<string>Curve Management</string>
@ -497,7 +474,7 @@
</size>
</property>
<property name="text">
<string>Add Curve</string>
<string>Add</string>
</property>
</widget>
</item>
@ -531,7 +508,7 @@
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -553,7 +530,7 @@
</size>
</property>
<property name="text">
<string>Curve Name:</string>
<string>Name:</string>
</property>
</widget>
</item>
@ -579,7 +556,7 @@
</size>
</property>
<property name="text">
<string>Curve Color:</string>
<string>Color:</string>
</property>
</widget>
</item>
@ -644,12 +621,12 @@
</size>
</property>
<property name="text">
<string>Data Start:</string>
<string>Angular:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="dataStartSpinBox">
<widget class="QSpinBox" name="SpinBox_Angular">
<property name="minimumSize">
<size>
<width>0</width>
@ -657,13 +634,13 @@
</size>
</property>
<property name="minimum">
<number>1</number>
<number>0</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
<property name="value">
<number>1</number>
<number>0</number>
</property>
</widget>
</item>
@ -676,12 +653,12 @@
</size>
</property>
<property name="text">
<string>Data Stop:</string>
<string>Radial:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="dataStopSpinBox">
<widget class="QSpinBox" name="SpinBox_Radial">
<property name="minimumSize">
<size>
<width>0</width>
@ -689,13 +666,13 @@
</size>
</property>
<property name="minimum">
<number>1</number>
<number>0</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
<property name="value">
<number>241</number>
<number>0</number>
</property>
</widget>
</item>
@ -757,7 +734,7 @@
</layout>
</widget>
</item>
<item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="buttonLayout">
<item>
<spacer name="horizontalSpacer">
@ -803,6 +780,67 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="chartGroupBox">
<property name="title">
<string>Chart Properties</string>
</property>
<layout class="QGridLayout" name="chartGridLayout">
<item row="1" column="1">
<widget class="QSpinBox" name="SpinBox_time">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="timeParamLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="chartNameLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Chart Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="chartNameEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Chart 1</string>
</property>
<property name="placeholderText">
<string>Enter chart name...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -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<int>::of(&QSpinBox::valueChanged), this, &AddPolarFileDlg::onCurveDataChanged);
connect(ui->SpinBox_Radial, QOverload<int>::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);
}
}
}

View File

@ -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_;

View File

@ -372,7 +372,7 @@
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>