From 9dd5b1f1f099093835899c8a27f1f37f4bf8bbd1 Mon Sep 17 00:00:00 2001 From: pimin <362371171@qq.com> Date: Tue, 11 Nov 2025 17:44:56 +0800 Subject: [PATCH] modified prop --- src/ui/Panel/SurfacePanel.cpp | 485 +++++++++++----- src/ui/Panel/SurfacePanel.h | 51 +- src/ui/PropertyBrowser.cpp | 892 ++++++++++++++++++++++++++---- src/ui/PropertyBrowser.h | 4 + src/workspace/CommandExecutor.cpp | 6 +- src/workspace/FileEntry.cpp | 62 +++ src/workspace/FileEntry.h | 5 + 7 files changed, 1277 insertions(+), 228 deletions(-) diff --git a/src/ui/Panel/SurfacePanel.cpp b/src/ui/Panel/SurfacePanel.cpp index a4c7aa0f..222afb8a 100644 --- a/src/ui/Panel/SurfacePanel.cpp +++ b/src/ui/Panel/SurfacePanel.cpp @@ -14,6 +14,25 @@ SurfacePanel::SurfacePanel(int index, const QString& filePath, QWidget* parent) m_iMinY = 0; m_iMaxY = 0; m_iMinZ = 0; m_iMaxZ = 0; + m_surfaceContainer = nullptr; + m_surface = nullptr; + m_p3DXAxis = nullptr; + m_p3DYAxis = nullptr; + m_p3DZAxis = nullptr; + m_pSeries = nullptr; + + m_countX = 0; + m_countY = 0; + m_countZ = 0; + + m_xTitle = ""; + m_yTitle = ""; + m_zTitle = ""; + + m_time = -1.0; + + m_thread = nullptr; + LOG_INFO("Created SurfacePanel {} for file: {}", index, filePath.toStdString()); } @@ -24,6 +43,25 @@ SurfacePanel::SurfacePanel(int index, std::shared_ptr fileEntr m_iMinY = 0; m_iMaxY = 0; m_iMinZ = 0; m_iMaxZ = 0; + m_surfaceContainer = nullptr; + m_surface = nullptr; + m_p3DXAxis = nullptr; + m_p3DYAxis = nullptr; + m_p3DZAxis = nullptr; + m_pSeries = nullptr; + + m_countX = 0; + m_countY = 0; + m_countZ = 0; + + m_xTitle = ""; + m_yTitle = ""; + m_zTitle = ""; + + m_time = -1.0; + + m_thread = nullptr; + if (fileEntry) { LOG_INFO("Created SurfacePanel {} for chart: {}", index, fileEntry->GetName().toStdString()); // Override the title with chart name @@ -37,6 +75,50 @@ SurfacePanel::SurfacePanel(int index, std::shared_ptr fileEntr SurfacePanel::~SurfacePanel() { LOG_INFO("Destroyed SurfacePanel {}", GetIndex()); + + if (m_pSeries) + { + m_surface->removeSeries(m_pSeries); + m_pSeries->deleteLater(); + m_pSeries = nullptr; + } + + if (m_surface) + { + m_surface->deleteLater(); + m_surface = nullptr; + } + + if (m_surfaceContainer) + { + m_surfaceContainer->deleteLater(); + m_surfaceContainer = nullptr; + } + + if (auto* layout = qobject_cast(this->layout())) + { + while (layout->count() > 0) + { + QLayoutItem* item = layout->takeAt(0); + if (item) + { + delete item; + } + } + } + + if (m_mutex) + { + delete m_mutex; + } + + if (m_thread) + { + m_thread->requestExit(); + m_thread->wait(); + m_thread->deleteLater(); + m_thread = nullptr; + } } void SurfacePanel::RefreshPanel() @@ -53,51 +135,14 @@ void SurfacePanel::RefreshPanel() void SurfacePanel::InitUI() { - m_Surface.setFlags(m_Surface.flags()); - m_Surface.setFlipHorizontalGrid(false); - - m_p3DXAxis = new QValue3DAxis; - m_p3DXAxis->setSegmentCount(10); - m_p3DXAxis->setRange(-10, 10); - - m_p3DYAxis = new QValue3DAxis; - m_p3DYAxis->setSegmentCount(10); - m_p3DYAxis->setRange(-10, 10); - - m_p3DZAxis = new QValue3DAxis; - m_p3DZAxis->setSegmentCount(10); - m_p3DZAxis->setRange(-10, 10); - - m_Surface.setAxisX(m_p3DXAxis); - m_Surface.setAxisY(m_p3DYAxis); - m_Surface.setAxisZ(m_p3DZAxis); - - m_Surface.activeTheme()->setType(Q3DTheme::Theme(2)); - - m_pSeries = new QSurface3DSeries; - m_pSeries->setDrawMode(QSurface3DSeries::DrawSurface); - m_Surface.addSeries(m_pSeries); - - QWidget* containerHandle = QWidget::createWindowContainer(&m_Surface); - containerHandle->setAutoFillBackground(true); - containerHandle->setAttribute(Qt::WA_OpaquePaintEvent, true); - containerHandle->setAttribute(Qt::WA_NoSystemBackground, false); - containerHandle->setUpdatesEnabled(false); - containerHandle->setMinimumHeight(100); - - m_pSeries->setBaseColor(Qt::green); - m_pSeries->setColorStyle(Q3DTheme::ColorStyleUniform); - m_pSeries->setSingleHighlightColor(Qt::green); - - m_pSeries->setMeshSmooth(false); - m_pSeries->setFlatShadingEnabled(false); - - m_Surface.scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPreset(13)); + createSurface(); QHBoxLayout* mainLayout = new QHBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); - mainLayout->addWidget(containerHandle); + mainLayout->addWidget(m_surfaceContainer); setLayout(mainLayout); + + m_mutex = new QMutex; } QString SurfacePanel::GetTypeDisplayName() const @@ -124,43 +169,50 @@ void SurfacePanel::OnDataPanelUpdated(FileEntrySurface* fileEntry) void SurfacePanel::OnTimeChanged(double time) { - if (m_data.size() > 0) + m_time = time; + + if (m_surface) { - m_pSeries->dataProxy()->resetArray(nullptr); + QMutexLocker locker(m_mutex); - QMap< double, QMap< int, QVector< QVector > > >::const_iterator ite = m_data.lowerBound(time); - if (ite == m_data.end()) + if (m_data.size() > 0) { - ite--; - } + m_pSeries->dataProxy()->resetArray(nullptr); - QMap< int, QVector< QVector > > mapData = ite.value(); - for (QMap< int, QVector< QVector > >::Iterator it = mapData.begin(); it != mapData.end(); it++) - { - int nIndex = it.key(); - QVector< QVector > listRowData = it.value(); - - QSurfaceDataArray* data = new QSurfaceDataArray; - - for (int nI = 0; nI < listRowData.size(); nI++) + QMap< double, QMap< int, QVector< QVector > > >::const_iterator ite = m_data.lowerBound(time); + if (ite == m_data.end()) { - QSurfaceDataRow* dataRow = new QSurfaceDataRow; - - QVector listColData = listRowData[nI]; - for (int nJ = 0; nJ < listColData.size(); nJ++) - { - QVector3D v3d = listColData[nJ]; - *dataRow << v3d; - } - - *data << dataRow; + ite--; } - m_pSeries->dataProxy()->resetArray(data); - } - } + QMap< int, QVector< QVector > > mapData = ite.value(); + for (QMap< int, QVector< QVector > >::Iterator it = mapData.begin(); it != mapData.end(); it++) + { + int nIndex = it.key(); + QVector< QVector > listRowData = it.value(); - m_Surface.setShadowQuality(QAbstract3DGraph::ShadowQuality::ShadowQualityNone); + QSurfaceDataArray* data = new QSurfaceDataArray; + + for (int nI = 0; nI < listRowData.size(); nI++) + { + QSurfaceDataRow* dataRow = new QSurfaceDataRow; + + QVector listColData = listRowData[nI]; + for (int nJ = 0; nJ < listColData.size(); nJ++) + { + QVector3D v3d = listColData[nJ]; + *dataRow << v3d; + } + + *data << dataRow; + } + + m_pSeries->dataProxy()->resetArray(data); + } + } + + m_surface->setShadowQuality(QAbstract3DGraph::ShadowQuality::ShadowQualityNone); + } } void SurfacePanel::updateTitle(const QString & title) @@ -168,11 +220,18 @@ void SurfacePanel::updateTitle(const QString & title) if (nullptr != dockWidget_) { dockWidget_->setWindowTitle(title); + + connect(dockWidget_, &QDockWidget::visibilityChanged, + this, &SurfacePanel::onVisibilityChanged); } } void SurfacePanel::updateTitleAxis(const QString & xTitle, const QString & yTitle, const QString & zTitle) { + m_xTitle = xTitle; + m_yTitle = yTitle; + m_zTitle = zTitle; + m_p3DXAxis->setTitle(xTitle); m_p3DXAxis->setTitleVisible(true); m_p3DYAxis->setTitle(yTitle); @@ -190,6 +249,7 @@ void SurfacePanel::updateMinMaxX(float min, float max, int count) if (count > 0) { + m_countX = count; m_p3DXAxis->setSegmentCount(count); } m_p3DXAxis->setRange(min, max); @@ -205,6 +265,7 @@ void SurfacePanel::updateMinMaxY(float min, float max, int count) if (count > 0) { + m_countY = count; m_p3DYAxis->setSegmentCount(count); } m_p3DYAxis->setRange(min, max); @@ -220,6 +281,7 @@ void SurfacePanel::updateMinMaxZ(float min, float max, int count) if (count > 0) { + m_countZ = count; m_p3DZAxis->setSegmentCount(count); } m_p3DZAxis->setRange(min, max); @@ -234,55 +296,236 @@ void SurfacePanel::updateParseFile(const QString & strFile, int nT, FileEntrySur return; } - m_data.clear(); - m_pSeries->dataProxy()->resetArray(nullptr); + { + QMutexLocker locker(m_mutex); + m_data.clear(); + m_pSeries->dataProxy()->resetArray(nullptr); + } - QFile file(strFile); + for (int nI = 0; nI < listCurve.size(); nI++) + { + FileEntrySurface::SurfaceProperty surface = listCurve.at(nI); + + m_color = surface.color; + + QLinearGradient gr; + gr.setColorAt(0.0, surface.color); + gr.setColorAt(0.5, Qt::yellow); + gr.setColorAt(0.8, Qt::red); + gr.setColorAt(1.0, Qt::darkRed); + + m_pSeries->setBaseGradient(gr); + m_pSeries->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + //m_pSeries->setSingleHighlightColor(Qt::green); + } + + if (m_thread) + { + m_thread->requestExit(); + m_thread->wait(); + m_thread->deleteLater(); + m_thread = nullptr; + } + + m_thread = new LoadDataThread(this, strFile, nT, listCurve); + m_thread->setMutex(m_mutex); + m_thread->start(); + + FinalParseFile(); +} + +void SurfacePanel::onVisibilityChanged(bool visible) +{ + if (visible) + { + if (!m_surfaceContainer) + { + createSurface(); + + updateTitleAxis(m_xTitle, m_yTitle, m_zTitle); + + if (m_iMaxX == m_iMinX) + { + m_p3DXAxis->setAutoAdjustRange(true); + } + else + { + updateMinMaxX(m_iMinX, m_iMaxX, m_countX); + } + + if (m_iMaxZ == m_iMinZ) + { + m_p3DZAxis->setAutoAdjustRange(true); + } + else + { + updateMinMaxZ(m_iMinZ, m_iMaxZ, m_countZ); + } + + if (m_iMaxY == m_iMinY) + { + m_p3DYAxis->setAutoAdjustRange(true); + } + else + { + updateMinMaxY(m_iMaxY, m_iMinY, m_countY); + } + + { + QLinearGradient gr; + gr.setColorAt(0.0, m_color); + gr.setColorAt(0.5, Qt::yellow); + gr.setColorAt(0.8, Qt::red); + gr.setColorAt(1.0, Qt::darkRed); + + m_pSeries->setBaseGradient(gr); + m_pSeries->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + } + + m_surface->setHorizontalAspectRatio(1.0); + + QHBoxLayout* layout = qobject_cast(this->layout()); + if (layout) + { + layout->addWidget(m_surfaceContainer); + } + + if (m_time > -1.0) + { + OnTimeChanged(m_time); + } + } + } + else + { + if (m_pSeries) + { + m_surface->removeSeries(m_pSeries); + m_pSeries->deleteLater(); + m_pSeries = nullptr; + } + + if (m_surface) + { + m_surface->deleteLater(); + m_surface = nullptr; + } + + if (m_surfaceContainer) + { + m_surfaceContainer->deleteLater(); + m_surfaceContainer = nullptr; + } + + if (auto* layout = qobject_cast(this->layout())) + { + while (layout->count() > 0) + { + QLayoutItem* item = layout->takeAt(0); + if (item) + { + delete item; + } + } + } + } +} + +void SurfacePanel::createSurface() +{ + m_surface = new Q3DSurface(); + m_surface->setFlags(m_surface->flags()); + m_surface->setFlipHorizontalGrid(false); + + m_p3DXAxis = new QValue3DAxis; + m_p3DXAxis->setSegmentCount(10); + m_p3DXAxis->setRange(-10, 10); + + m_p3DYAxis = new QValue3DAxis; + m_p3DYAxis->setSegmentCount(10); + m_p3DYAxis->setRange(-10, 10); + + m_p3DZAxis = new QValue3DAxis; + m_p3DZAxis->setSegmentCount(10); + m_p3DZAxis->setRange(-10, 10); + + m_surface->setAxisX(m_p3DXAxis); + m_surface->setAxisY(m_p3DYAxis); + m_surface->setAxisZ(m_p3DZAxis); + + m_surface->activeTheme()->setType(Q3DTheme::Theme(2)); + + m_pSeries = new QSurface3DSeries; + m_pSeries->setDrawMode(QSurface3DSeries::DrawSurface); + m_surface->addSeries(m_pSeries); + + m_surfaceContainer = QWidget::createWindowContainer(m_surface); + m_surfaceContainer->setAutoFillBackground(true); + m_surfaceContainer->setAttribute(Qt::WA_OpaquePaintEvent, true); + m_surfaceContainer->setAttribute(Qt::WA_NoSystemBackground, false); + m_surfaceContainer->setUpdatesEnabled(true); + m_surfaceContainer->setMinimumHeight(100); + + m_pSeries->setBaseColor(Qt::green); + m_pSeries->setColorStyle(Q3DTheme::ColorStyleUniform); + m_pSeries->setSingleHighlightColor(Qt::green); + + m_pSeries->setMeshSmooth(false); + m_pSeries->setFlatShadingEnabled(false); + + m_surface->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPreset(13)); +} + +void SurfacePanel::FinalParseFile() +{ + if (m_iMaxX == m_iMinX) + { + m_p3DXAxis->setAutoAdjustRange(true); + } + if (m_iMaxZ == m_iMinZ) + { + m_p3DZAxis->setAutoAdjustRange(true); + } + if (m_iMaxY == m_iMinY) + { + m_p3DYAxis->setAutoAdjustRange(true); + } + + m_surface->setHorizontalAspectRatio(1.0); +} + + + +LoadDataThread::LoadDataThread(SurfacePanel *panel, QString file, int nT, FileEntrySurface::SurfaceProperties listCurve) +{ + m_panel = panel; + m_file = file; + m_nT = nT; + m_listCurve = listCurve; + m_exit = false; +} + +void LoadDataThread::run() +{ + QFile file(m_file); if (file.open(QIODevice::ReadOnly)) { - for (int nI = 0; nI < listCurve.size(); nI++) - { - FileEntrySurface::SurfaceProperty surface = listCurve.at(nI); - - QLinearGradient gr; - gr.setColorAt(0.0, surface.color); - gr.setColorAt(0.5, Qt::yellow); - gr.setColorAt(0.8, Qt::red); - gr.setColorAt(1.0, Qt::darkRed); - - m_pSeries->setBaseGradient(gr); - m_pSeries->setColorStyle(Q3DTheme::ColorStyleRangeGradient); - //m_pSeries->setSingleHighlightColor(Qt::green); - } - - bool bResetAxisX = false; - if (m_iMaxX == m_iMinX) - { - bResetAxisX = true; - } - bool bResetAxisY = false; - if (m_iMaxZ == m_iMinZ) - { - bResetAxisY = true; - } - bool bResetAxisZ = false; - if (m_iMaxY == m_iMinY) - { - bResetAxisZ = true; - } - - while (!file.atEnd()) + while (!file.atEnd() && !m_exit) { QString strLine = file.readLine().simplified(); if (!strLine.isEmpty()) { QStringList listLine = strLine.split(" "); - double t = listLine.at(nT).toDouble(); + double t = listLine.at(m_nT).toDouble(); QMap< int, QVector< QVector > > mapData; - for (int nI = 0; nI < listCurve.size(); nI++) + for (int nI = 0; nI < m_listCurve.size(); nI++) { - FileEntrySurface::SurfaceProperty surface = listCurve.at(nI); + if (m_exit) + { + break; + } + FileEntrySurface::SurfaceProperty surface = m_listCurve.at(nI); int nStart = surface.start; int nStop = surface.stop; if (nStart == 0) @@ -305,6 +548,11 @@ void SurfacePanel::updateParseFile(const QString & strFile, int nT, FileEntrySur int nCol = 0; for (int nJ = nStart; nJ < nStop; nJ += 3) { + if (m_exit) + { + break; + } + int x = listLine.at(nJ).toDouble(); int y = listLine.at(nJ + 1).toDouble(); double z = listLine.at(nJ + 2).toDouble(); @@ -368,25 +616,14 @@ void SurfacePanel::updateParseFile(const QString & strFile, int nT, FileEntrySur } mapData.insert(nI, listRowData); } - m_data.insert(t, mapData); + + { + QMutexLocker locker(m_mutex); + m_panel->m_data.insert(t, mapData); + } } } - if (m_iMaxX == m_iMinX) - { - m_p3DXAxis->setAutoAdjustRange(true); - } - if (m_iMaxZ == m_iMinZ) - { - m_p3DZAxis->setAutoAdjustRange(true); - } - if (m_iMaxY == m_iMinY) - { - m_p3DYAxis->setAutoAdjustRange(true); - } - - m_Surface.setHorizontalAspectRatio(1.0); - file.close(); } } \ No newline at end of file diff --git a/src/ui/Panel/SurfacePanel.h b/src/ui/Panel/SurfacePanel.h index 5a367c93..d9665df6 100644 --- a/src/ui/Panel/SurfacePanel.h +++ b/src/ui/Panel/SurfacePanel.h @@ -6,9 +6,12 @@ #include #include +#include using namespace QtDataVisualization; +class LoadDataThread; + class SurfacePanel : public DataPanel { Q_OBJECT @@ -46,6 +49,8 @@ public: */ void RefreshPanel() override; + void FinalParseFile(); + protected: /** * @brief Initialize UI for curve-specific layout @@ -70,8 +75,12 @@ private: void updateMinMaxZ(float min, float max, int count); void updateParseFile(const QString& strFile, int nT, FileEntrySurface::SurfaceProperties listCurve); + void onVisibilityChanged(bool visible); + void createSurface(); + private: - Q3DSurface m_Surface; + Q3DSurface *m_surface; + QWidget *m_surfaceContainer; QSurface3DSeries* m_pSeries; @@ -86,6 +95,46 @@ private: float m_iMinZ = 0; float m_iMaxZ = 10; + int m_countX; + int m_countY; + int m_countZ; + + QString m_xTitle; + QString m_yTitle; + QString m_zTitle; + + QColor m_color; + + double m_time; + + QMutex *m_mutex; + LoadDataThread *m_thread; + +public: QMap< double, QMap< int, QVector< QVector > > > m_data; }; +#include +class LoadDataThread : public QThread +{ + Q_OBJECT + +public: + LoadDataThread(SurfacePanel *panel, QString file, int nT, FileEntrySurface::SurfaceProperties listCurve); + virtual void run(); + + void setMutex(QMutex *mutex) + { + m_mutex = mutex; + } + + void requestExit() { m_exit = true; } + +private: + SurfacePanel *m_panel; + QString m_file; + int m_nT; + FileEntrySurface::SurfaceProperties m_listCurve; + QMutex *m_mutex; + bool m_exit; +}; \ No newline at end of file diff --git a/src/ui/PropertyBrowser.cpp b/src/ui/PropertyBrowser.cpp index 5b04c3df..66ddc610 100644 --- a/src/ui/PropertyBrowser.cpp +++ b/src/ui/PropertyBrowser.cpp @@ -148,6 +148,11 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { idToProperty_.clear(); idToExpanded_.clear(); colorSetters_.clear(); + + stringSetters_.clear(); + intSetters_.clear(); + doubleSetters_.clear(); + return; } @@ -157,47 +162,299 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { propertyToId_.clear(); idToProperty_.clear(); idToExpanded_.clear(); + colorSetters_.clear(); + stringSetters_.clear(); + intSetters_.clear(); + doubleSetters_.clear(); // Compute our id and ensure the property exists (create if missing) - const QString id = QString("CurveEntry:%1").arg(entry->GetFileName()); - auto curve = entry->AsCurve(); - if (!curve) { + //const QString id = QString("CurveEntry:%1").arg(entry->GetFileName()); + //auto curve = entry->AsCurve(); + //if (!curve) + { LOG_WARN("file entry not a curve: %s", entry->GetFileName().toStdString().c_str()); // 基础信息组 const QString idBasic = QString("FileEntry:%1").arg(entry->GetFileName()); const QString titleBasic = QString("File Entry - %1").arg(entry->GetName()); - QtProperty* groupBasic = groupManager_->addProperty(titleBasic); + QtProperty* groupBasic = groupManager_->addProperty(tr("Basic")); QtProperty* typeProp = stringManager_->addProperty(tr("Type")); stringManager_->setValue(typeProp, QString::fromStdString(FileEntryTypeToString(entry->GetType()))); + typeProp->setEnabled(false); groupBasic->addSubProperty(typeProp); QtProperty* nameProp = stringManager_->addProperty(tr("Name")); stringManager_->setValue(nameProp, entry->GetName()); groupBasic->addSubProperty(nameProp); + stringSetters_[nameProp] = [entry](const QString& s) + { + entry->SetName(s); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + QtProperty* fileProp = stringManager_->addProperty(tr("FileName")); stringManager_->setValue(fileProp, entry->GetFileName()); + fileProp->setEnabled(false); groupBasic->addSubProperty(fileProp); QtProperty* pathProp = stringManager_->addProperty(tr("Path")); stringManager_->setValue(pathProp, entry->GetPath()); + pathProp->setEnabled(false); groupBasic->addSubProperty(pathProp); addProperty(groupBasic, idBasic); // 类型专属属性显示 - switch (entry->GetType()) { - case FileEntryType::Surface: { + switch (entry->GetType()) + { + case FileEntryType::Curve: + { + auto curve = entry->AsCurve(); + if (curve) + { + const QString titleChart = QString(tr("Chart")); + QtProperty* chartGroup = groupManager_->addProperty(titleChart); + + const auto& chart = curve->GetChartProperties(); + QtProperty* typeProp = enumManager_->addProperty(tr("Curve Type")); + enumManager_->setEnumNames(typeProp, QStringList() << ("Wave") << ("Report")); + int enumVal = (chart.chartType == ChartType::Report) ? 1 : 0; + enumManager_->setValue(typeProp, enumVal); + typeProp->setEnabled(false); + chartGroup->addSubProperty(typeProp); + QtProperty* xCountProp = intManager_->addProperty(tr("xCount")); + intManager_->setValue(xCountProp, chart.xCount); + chartGroup->addSubProperty(xCountProp); + + intSetters_[xCountProp] = [curve, entry](const int& value) + { + auto prop = curve->GetChartProperties(); + prop.xCount = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* yCountProp = intManager_->addProperty(tr("yCount")); + intManager_->setValue(yCountProp, chart.yCount); + chartGroup->addSubProperty(yCountProp); + + intSetters_[yCountProp] = [curve, entry](const int& value) + { + auto prop = curve->GetChartProperties(); + prop.yCount = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* xTitleProp = stringManager_->addProperty(tr("xTitle")); + stringManager_->setValue(xTitleProp, chart.xTitle); + chartGroup->addSubProperty(xTitleProp); + + stringSetters_[xTitleProp] = [curve, entry](const QString& s) + { + auto prop = curve->GetChartProperties(); + prop.xTitle = s; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* yTitleProp = stringManager_->addProperty(tr("yTitle")); + stringManager_->setValue(yTitleProp, chart.yTitle); + chartGroup->addSubProperty(yTitleProp); + + stringSetters_[yTitleProp] = [curve, entry](const QString& s) + { + auto prop = curve->GetChartProperties(); + prop.yTitle = s; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* xMinProp = doubleManager_->addProperty(tr("xMin")); + doubleManager_->setValue(xMinProp, chart.xMin); + chartGroup->addSubProperty(xMinProp); + + doubleSetters_[xMinProp] = [curve, entry](const double& value) + { + auto prop = curve->GetChartProperties(); + prop.xMin = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* xMaxProp = doubleManager_->addProperty(tr("xMax")); + doubleManager_->setValue(xMaxProp, chart.xMax); + chartGroup->addSubProperty(xMaxProp); + + doubleSetters_[xMaxProp] = [curve, entry](const double& value) + { + auto prop = curve->GetChartProperties(); + prop.xMax = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* yMinProp = doubleManager_->addProperty(tr("yMin")); + doubleManager_->setValue(yMinProp, chart.yMin); + chartGroup->addSubProperty(yMinProp); + + doubleSetters_[yMinProp] = [curve, entry](const double& value) + { + auto prop = curve->GetChartProperties(); + prop.yMin = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* yMaxProp = doubleManager_->addProperty(tr("yMax")); + doubleManager_->setValue(yMaxProp, chart.yMax); + chartGroup->addSubProperty(yMaxProp); + + doubleSetters_[yMaxProp] = [curve, entry](const double& value) + { + auto prop = curve->GetChartProperties(); + prop.yMax = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* tProp = intManager_->addProperty(tr("timeParam")); + intManager_->setValue(tProp, chart.timeParam); + chartGroup->addSubProperty(tProp); + + intSetters_[tProp] = [curve, entry](const int& value) + { + auto prop = curve->GetChartProperties(); + prop.timeParam = value; + curve->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + addProperty(chartGroup, "CurveChart"); + + QtProperty* itemsGroup = groupManager_->addProperty(tr("CurveProperty")); + const auto& items = curve->GetCurveProperties(); + for (int i = 0; i < items.size(); ++i) + { + const auto& s = items[i]; + QtProperty* itemGroup = groupManager_->addProperty(QString("Curve[%1]").arg(i)); + + QtProperty* nm = stringManager_->addProperty(tr("name")); + stringManager_->setValue(nm, s.name); + itemGroup->addSubProperty(nm); + + stringSetters_[nm] = [curve, entry, i](const QString& s) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.name = s; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + + QtProperty* col = colorManager_->addProperty(tr("color")); + colorManager_->setValue(col, s.color); + itemGroup->addSubProperty(col); + + colorSetters_[col] = [curve, entry, i](const QColor& c) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.color = c; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + + if (chart.chartType == ChartType::Wave) + { + QtProperty* st = intManager_->addProperty(tr("start")); + intManager_->setValue(st, s.data.wave.start); + itemGroup->addSubProperty(st); + QtProperty* sp = intManager_->addProperty(tr("stop")); + intManager_->setValue(sp, s.data.wave.stop); + itemGroup->addSubProperty(sp); + + intSetters_[st] = [curve, entry, i](const int& value) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.data.wave.start = value; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + intSetters_[sp] = [curve, entry, i](const int& value) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.data.wave.stop = value; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + } + else if (chart.chartType == ChartType::Report) + { + QtProperty* st = intManager_->addProperty(tr("x")); + intManager_->setValue(st, s.data.report.x); + itemGroup->addSubProperty(st); + QtProperty* sp = intManager_->addProperty(tr("y")); + intManager_->setValue(sp, s.data.report.y); + itemGroup->addSubProperty(sp); + + intSetters_[st] = [curve, entry, i](const int& value) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.data.report.x = value; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + intSetters_[sp] = [curve, entry, i](const int& value) + { + auto props = curve->GetCurveProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.data.report.y = value; + curve->SetCurveProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + } + + itemsGroup->addSubProperty(itemGroup); + } + addProperty(itemsGroup, "CurveItems"); + } + break; + } + case FileEntryType::Surface: + { auto surf = entry->AsSurface(); - if (surf) { + if (surf) + { const QString idChart = QString("SurfaceChart:%1").arg(entry->GetFileName()); const QString idItems = QString("SurfaceItems:%1").arg(entry->GetFileName()); const QString titleChart = QString("Surface Chart - %1").arg(entry->GetName()); const QString titleItems = QString("Surfaces - %1").arg(entry->GetName()); // Chart 属性 - QtProperty* chartGroup = groupManager_->addProperty(titleChart); + QtProperty* chartGroup = groupManager_->addProperty(tr("Chart")); const auto& chart = surf->GetChartProperties(); QtProperty* xCountProp = intManager_->addProperty(tr("xCount")); intManager_->setValue(xCountProp, chart.xCount); @@ -208,6 +465,29 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { QtProperty* zCountProp = intManager_->addProperty(tr("zCount")); intManager_->setValue(zCountProp, chart.zCount); chartGroup->addSubProperty(zCountProp); + + intSetters_[xCountProp] = [surf, entry](const int& value) + { + auto prop = surf->GetChartProperties(); + prop.xCount = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + intSetters_[yCountProp] = [surf, entry](const int& value) + { + auto prop = surf->GetChartProperties(); + prop.yCount = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + intSetters_[zCountProp] = [surf, entry](const int& value) + { + auto prop = surf->GetChartProperties(); + prop.zCount = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + QtProperty* xTitleProp = stringManager_->addProperty(tr("xTitle")); stringManager_->setValue(xTitleProp, chart.xTitle); chartGroup->addSubProperty(xTitleProp); @@ -217,45 +497,141 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { QtProperty* zTitleProp = stringManager_->addProperty(tr("zTitle")); stringManager_->setValue(zTitleProp, chart.zTitle); chartGroup->addSubProperty(zTitleProp); + + stringSetters_[xTitleProp] = [surf, entry](const QString& s) + { + auto prop = surf->GetChartProperties(); + prop.xTitle = s; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + stringSetters_[yTitleProp] = [surf, entry](const QString& s) + { + auto prop = surf->GetChartProperties(); + prop.yTitle = s; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + stringSetters_[zTitleProp] = [surf, entry](const QString& s) + { + auto prop = surf->GetChartProperties(); + prop.zTitle = s; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + QtProperty* xMinProp = doubleManager_->addProperty(tr("xMin")); doubleManager_->setValue(xMinProp, chart.xMin); chartGroup->addSubProperty(xMinProp); QtProperty* xMaxProp = doubleManager_->addProperty(tr("xMax")); doubleManager_->setValue(xMaxProp, chart.xMax); chartGroup->addSubProperty(xMaxProp); + + doubleSetters_[xMinProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.xMin = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + doubleSetters_[xMaxProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.xMax = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + QtProperty* yMinProp = doubleManager_->addProperty(tr("yMin")); doubleManager_->setValue(yMinProp, chart.yMin); chartGroup->addSubProperty(yMinProp); QtProperty* yMaxProp = doubleManager_->addProperty(tr("yMax")); doubleManager_->setValue(yMaxProp, chart.yMax); chartGroup->addSubProperty(yMaxProp); + + doubleSetters_[yMinProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.yMin = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + doubleSetters_[yMaxProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.yMax = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + QtProperty* zMinProp = doubleManager_->addProperty(tr("zMin")); doubleManager_->setValue(zMinProp, chart.zMin); chartGroup->addSubProperty(zMinProp); QtProperty* zMaxProp = doubleManager_->addProperty(tr("zMax")); doubleManager_->setValue(zMaxProp, chart.zMax); chartGroup->addSubProperty(zMaxProp); - QtProperty* tProp = doubleManager_->addProperty(tr("timeParam")); - doubleManager_->setValue(tProp, chart.timeParam); + + doubleSetters_[zMinProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.zMin = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + doubleSetters_[zMaxProp] = [surf, entry](const double& value) + { + auto prop = surf->GetChartProperties(); + prop.zMax = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* tProp = intManager_->addProperty(tr("timeParam")); + intManager_->setValue(tProp, chart.timeParam); chartGroup->addSubProperty(tProp); + + intSetters_[zCountProp] = [surf, entry](const int& value) + { + auto prop = surf->GetChartProperties(); + prop.timeParam = value; + surf->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + addProperty(chartGroup, idChart); // Surface 列表 - QtProperty* itemsGroup = groupManager_->addProperty(titleItems); + QtProperty* itemsGroup = groupManager_->addProperty(tr("SurfacesProp")); const auto& items = surf->GetSurfaceProperties(); - for (int i = 0; i < items.size(); ++i) { + for (int i = 0; i < items.size(); ++i) + { const auto& s = items[i]; QtProperty* itemGroup = groupManager_->addProperty(QString("Surface[%1]").arg(i)); QtProperty* nm = stringManager_->addProperty(tr("name")); stringManager_->setValue(nm, s.name); itemGroup->addSubProperty(nm); + + stringSetters_[nm] = [surf, entry, i](const QString& s) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.name = s; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* col = colorManager_->addProperty(tr("color")); colorManager_->setValue(col, s.color); itemGroup->addSubProperty(col); // 写回 Surface 条目颜色 - colorSetters_[col] = [surf, entry, i](const QColor& c){ + colorSetters_[col] = [surf, entry, i](const QColor& c) + { auto props = surf->GetSurfaceProperties(); - if (i >= 0 && i < props.size()) { + if (i >= 0 && i < props.size()) + { auto item = props[i]; item.color = c; surf->SetSurfaceProperty(i, item); @@ -268,6 +644,30 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { QtProperty* sp = intManager_->addProperty(tr("stop")); intManager_->setValue(sp, s.stop); itemGroup->addSubProperty(sp); + + intSetters_[st] = [surf, entry, i](const int& value) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.start = value; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + intSetters_[sp] = [surf, entry, i](const int& value) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.stop = value; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* x = stringManager_->addProperty(tr("x")); stringManager_->setValue(x, s.x); itemGroup->addSubProperty(x); @@ -277,73 +677,131 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { QtProperty* z = stringManager_->addProperty(tr("z")); stringManager_->setValue(z, s.z); itemGroup->addSubProperty(z); + + stringSetters_[x] = [surf, entry, i](const QString& s) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.x = s; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + stringSetters_[y] = [surf, entry, i](const QString& s) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.y = s; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + stringSetters_[z] = [surf, entry, i](const QString& s) + { + auto props = surf->GetSurfaceProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.z = s; + surf->SetSurfaceProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + itemsGroup->addSubProperty(itemGroup); } addProperty(itemsGroup, idItems); } break; } - case FileEntryType::Table: { + case FileEntryType::Table: + { auto tbl = entry->AsTable(); - if (tbl) { + if (tbl) + { const QString idChart = QString("TableChart:%1").arg(entry->GetFileName()); const QString idItems = QString("TableItems:%1").arg(entry->GetFileName()); const QString titleChart = QString("Table Chart - %1").arg(entry->GetName()); const QString titleItems = QString("Tables - %1").arg(entry->GetName()); - QtProperty* chartGroup = groupManager_->addProperty(titleChart); + QtProperty* chartGroup = groupManager_->addProperty(tr("Chart")); const auto& chart = tbl->GetChartProperties(); QtProperty* headerProp = stringManager_->addProperty(tr("headerString")); stringManager_->setValue(headerProp, chart.headerString); chartGroup->addSubProperty(headerProp); - QtProperty* tProp = doubleManager_->addProperty(tr("timeParam")); - doubleManager_->setValue(tProp, chart.timeParam); + + stringSetters_[headerProp] = [tbl, entry](const QString& s) + { + auto prop = tbl->GetChartProperties(); + prop.headerString = s; + tbl->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + + QtProperty* tProp = intManager_->addProperty(tr("timeParam")); + intManager_->setValue(tProp, chart.timeParam); chartGroup->addSubProperty(tProp); + + intSetters_[tProp] = [tbl, entry](const int& value) + { + auto prop = tbl->GetChartProperties(); + prop.timeParam = value; + tbl->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + addProperty(chartGroup, idChart); - QtProperty* itemsGroup = groupManager_->addProperty(titleItems); - const auto& items = tbl->GetTableProperties(); - for (int i = 0; i < items.size(); ++i) { - const auto& t = items[i]; - QtProperty* itemGroup = groupManager_->addProperty(QString("Table[%1]").arg(i)); - QtProperty* nm = stringManager_->addProperty(tr("name")); - stringManager_->setValue(nm, t.name); - itemGroup->addSubProperty(nm); - QtProperty* col = colorManager_->addProperty(tr("color")); - colorManager_->setValue(col, t.color); - itemGroup->addSubProperty(col); - // 写回 Table 条目颜色 - colorSetters_[col] = [tbl, entry, i](const QColor& c){ - auto props = tbl->GetTableProperties(); - if (i >= 0 && i < props.size()) { - auto item = props[i]; - item.color = c; - tbl->SetTableProperty(i, item); - if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); - } - }; - // datas 展示为拼接字符串 - QStringList values; - for (const auto& v : t.datas) values << QString::number(v); - QtProperty* ds = stringManager_->addProperty(tr("datas")); - stringManager_->setValue(ds, values.join(", ")); - itemGroup->addSubProperty(ds); - itemsGroup->addSubProperty(itemGroup); - } - addProperty(itemsGroup, idItems); + // QtProperty* itemsGroup = groupManager_->addProperty(titleItems); + // const auto& items = tbl->GetTableProperties(); + // for (int i = 0; i < items.size(); ++i) + //{ + // const auto& t = items[i]; + // QtProperty* itemGroup = groupManager_->addProperty(QString("Table[%1]").arg(i)); + // QtProperty* nm = stringManager_->addProperty(tr("name")); + // stringManager_->setValue(nm, t.name); + // itemGroup->addSubProperty(nm); + // QtProperty* col = colorManager_->addProperty(tr("color")); + // colorManager_->setValue(col, t.color); + // itemGroup->addSubProperty(col); + // // 写回 Table 条目颜色 + // colorSetters_[col] = [tbl, entry, i](const QColor& c){ + // auto props = tbl->GetTableProperties(); + // if (i >= 0 && i < props.size()) { + // auto item = props[i]; + // item.color = c; + // tbl->SetTableProperty(i, item); + // if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + // } + // }; + // // datas 展示为拼接字符串 + // QStringList values; + // for (const auto& v : t.datas) values << QString::number(v); + // QtProperty* ds = stringManager_->addProperty(tr("datas")); + // stringManager_->setValue(ds, values.join(", ")); + // itemGroup->addSubProperty(ds); + // itemsGroup->addSubProperty(itemGroup); + // } + // addProperty(itemsGroup, idItems); } break; } - case FileEntryType::Light: { + case FileEntryType::Light: + { auto lt = entry->AsLight(); - if (lt) { + if (lt) + { const QString idColor = QString("LightColors:%1").arg(entry->GetFileName()); const QString idRows = QString("LightRows:%1").arg(entry->GetFileName()); const QString titleColor = QString("Light Colors - %1").arg(entry->GetName()); const QString titleRows = QString("Light Rows - %1").arg(entry->GetName()); // 颜色与时间 - QtProperty* colorGroup = groupManager_->addProperty(titleColor); + QtProperty* colorGroup = groupManager_->addProperty(tr("Chart")); const auto& colorProps = lt->GetColorProperties(); QtProperty* oc = colorManager_->addProperty(tr("openColor")); colorManager_->setValue(oc, colorProps.openColor); @@ -351,18 +809,29 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { QtProperty* cc = colorManager_->addProperty(tr("closeColor")); colorManager_->setValue(cc, colorProps.closeColor); colorGroup->addSubProperty(cc); - QtProperty* tProp = doubleManager_->addProperty(tr("timeParam")); - doubleManager_->setValue(tProp, colorProps.timeParam); + QtProperty* tProp = intManager_->addProperty(tr("timeParam")); + intManager_->setValue(tProp, colorProps.timeParam); colorGroup->addSubProperty(tProp); + + intSetters_[tProp] = [lt, entry](const int& value) + { + auto prop = lt->GetColorProperties(); + prop.timeParam = value; + lt->SetColorProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + addProperty(colorGroup, idColor); // 写回处理:颜色变化更新到 FileEntryLight 并通知 Workspace - colorSetters_[oc] = [lt, entry](const QColor& c){ + colorSetters_[oc] = [lt, entry](const QColor& c) + { auto props = lt->GetColorProperties(); props.openColor = c; lt->SetColorProperties(props); if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); }; - colorSetters_[cc] = [lt, entry](const QColor& c){ + colorSetters_[cc] = [lt, entry](const QColor& c) + { auto props = lt->GetColorProperties(); props.closeColor = c; lt->SetColorProperties(props); @@ -370,120 +839,321 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { }; // 行数据 - QtProperty* rowsGroup = groupManager_->addProperty(titleRows); + QtProperty* rowsGroup = groupManager_->addProperty(tr("Light Rows")); const auto& rows = lt->GetLightProperties(); - for (int i = 0; i < rows.size(); ++i) { + for (int i = 0; i < rows.size(); ++i) + { const auto& r = rows[i]; QtProperty* row = groupManager_->addProperty(QString("Row[%1]").arg(i)); QtProperty* names = stringManager_->addProperty(tr("names")); stringManager_->setValue(names, r.name.join(", ")); row->addSubProperty(names); + + stringSetters_[names] = [lt, entry, i](const QString& s) + { + auto props = lt->GetLightProperties(); + if (i >= 0 && i < props.size()) + { + QStringList names = s.split(",", Qt::SkipEmptyParts); + for (int i = 0; i < names.size(); ++i) { + names[i] = names[i].trimmed(); + } + + auto item = props[i]; + item.name = names; + lt->SetLightProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QStringList values; for (const auto& v : r.data) values << QString::number(v); QtProperty* ds = stringManager_->addProperty(tr("data")); stringManager_->setValue(ds, values.join(", ")); row->addSubProperty(ds); + + stringSetters_[ds] = [lt, entry, i](const QString& s) + { + auto props = lt->GetLightProperties(); + if (i >= 0 && i < props.size()) + { + QStringList dataStrings = s.split(",", Qt::SkipEmptyParts); + QList dataValues; + for (const QString& str : dataStrings) + { + bool ok; + int dataValue = str.trimmed().toInt(&ok); + if (ok) { + dataValues.append(dataValue); + } + } + + auto item = props[i]; + item.data = dataValues; + lt->SetLightProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + rowsGroup->addSubProperty(row); } addProperty(rowsGroup, idRows); } break; } - case FileEntryType::Polar: { + case FileEntryType::Polar: + { auto pl = entry->AsPolar(); - if (pl) { + if (pl) + { const QString idChart = QString("PolarChart:%1").arg(entry->GetFileName()); const QString idLines = QString("PolarLines:%1").arg(entry->GetFileName()); const QString titleChart = QString("Polar Chart - %1").arg(entry->GetName()); const QString titleLines = QString("Lines - %1").arg(entry->GetName()); - QtProperty* chartGroup = groupManager_->addProperty(titleChart); + QtProperty* chartGroup = groupManager_->addProperty(tr("Chart")); const auto& chart = pl->GetChartProperties(); - auto addInt = [&](const QString& label, int v){ QtProperty* p=intManager_->addProperty(label); intManager_->setValue(p, v); chartGroup->addSubProperty(p); }; - auto addStr = [&](const QString& label, const QString& v){ QtProperty* p=stringManager_->addProperty(label); stringManager_->setValue(p, v); chartGroup->addSubProperty(p); }; - auto addDbl = [&](const QString& label, double v){ QtProperty* p=doubleManager_->addProperty(label); doubleManager_->setValue(p, v); chartGroup->addSubProperty(p); }; - addInt(tr("AngularCount"), chart.AngularCount); - addInt(tr("RadialCount"), chart.RadialCount); - addStr(tr("AngularTitle"), chart.AngularTitle); - addStr(tr("RadialTitle"), chart.RadialTitle); - addDbl(tr("AngularMin"), chart.AngularMin); - addDbl(tr("AngularMax"), chart.AngularMax); - addDbl(tr("RadialMin"), chart.RadialMin); - addDbl(tr("RadialMax"), chart.RadialMax); - addStr(tr("AngularUnit"), chart.AngularUnit); - addStr(tr("RadialUnit"), chart.RadialUnit); - addDbl(tr("timeParam"), chart.timeParam); + auto addInt = [&](const QString& label, int v, const QString& key) + { + QtProperty* p=intManager_->addProperty(label); + intManager_->setValue(p, v); + chartGroup->addSubProperty(p); + + intSetters_[p] = [pl, entry, key](const int& value) + { + pl->UpdateChartProperties(key, QVariant(value)); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + }; + auto addStr = [&](const QString& label, const QString& v, const QString& key) + { + QtProperty* p=stringManager_->addProperty(label); + stringManager_->setValue(p, v); + chartGroup->addSubProperty(p); + + stringSetters_[p] = [pl, entry, key](const QString& value) + { + pl->UpdateChartProperties(key, QVariant(value)); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + }; + auto addDbl = [&](const QString& label, double v, const QString& key) + { + QtProperty* p=doubleManager_->addProperty(label); + doubleManager_->setValue(p, v); + chartGroup->addSubProperty(p); + + doubleSetters_[p] = [pl, entry, key](const double& value) + { + pl->UpdateChartProperties(key, QVariant(value)); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + }; + addInt(tr("AngularCount"), chart.AngularCount, "AngularCount"); + addInt(tr("RadialCount"), chart.RadialCount, "RadialCount"); + addStr(tr("AngularTitle"), chart.AngularTitle, "AngularTitle"); + addStr(tr("RadialTitle"), chart.RadialTitle, "RadialTitle"); + addDbl(tr("AngularMin"), chart.AngularMin, "AngularMin"); + addDbl(tr("AngularMax"), chart.AngularMax, "AngularMax"); + addDbl(tr("RadialMin"), chart.RadialMin, "RadialMin"); + addDbl(tr("RadialMax"), chart.RadialMax, "RadialMax"); + addStr(tr("AngularUnit"), chart.AngularUnit, "AngularUnit"); + addStr(tr("RadialUnit"), chart.RadialUnit, "RadialUnit"); + addInt(tr("timeParam"), chart.timeParam, "timeParam"); addProperty(chartGroup, idChart); - QtProperty* linesGroup = groupManager_->addProperty(titleLines); + QtProperty* linesGroup = groupManager_->addProperty(tr("Lines Prop")); const auto& lines = pl->GetLineProperties(); - for (int i = 0; i < lines.size(); ++i) { + for (int i = 0; i < lines.size(); ++i) + { const auto& ln = lines[i]; QtProperty* line = groupManager_->addProperty(QString("Line[%1]").arg(i)); QtProperty* nm = stringManager_->addProperty(tr("name")); stringManager_->setValue(nm, ln.name); line->addSubProperty(nm); + + stringSetters_[nm] = [pl, entry, i](const QString& s) + { + auto props = pl->GetLineProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.name = s; + pl->SetLineProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* col = colorManager_->addProperty(tr("color")); colorManager_->setValue(col, ln.color); line->addSubProperty(col); // 写回 Polar 线颜色 - colorSetters_[col] = [pl, entry, i](const QColor& c){ + colorSetters_[col] = [pl, entry, i](const QColor& c) + { auto props = pl->GetLineProperties(); - if (i >= 0 && i < props.size()) { + if (i >= 0 && i < props.size()) + { auto item = props[i]; item.color = c; pl->SetLineProperty(i, item); if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); } }; + QtProperty* ag = intManager_->addProperty(tr("Angular")); intManager_->setValue(ag, ln.Angular); line->addSubProperty(ag); + + intSetters_[ag] = [pl, entry, i](const int& value) + { + auto props = pl->GetLineProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.Angular = value; + pl->SetLineProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* rd = intManager_->addProperty(tr("Radial")); intManager_->setValue(rd, ln.Radial); line->addSubProperty(rd); + + intSetters_[rd] = [pl, entry, i](const int& value) + { + auto props = pl->GetLineProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.Radial = value; + pl->SetLineProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + linesGroup->addSubProperty(line); } addProperty(linesGroup, idLines); } break; } - case FileEntryType::Image: { + case FileEntryType::Image: + { auto img = entry->AsImage(); - if (img) { + if (img) + { const QString idChart = QString("ImageChart:%1").arg(entry->GetFileName()); const QString idItems = QString("Images:%1").arg(entry->GetFileName()); const QString titleChart = QString("Image Chart - %1").arg(entry->GetName()); const QString titleItems = QString("Image Set - %1").arg(entry->GetName()); - QtProperty* chartGroup = groupManager_->addProperty(titleChart); + QtProperty* chartGroup = groupManager_->addProperty(tr("Chart")); const auto& chart = img->GetChartProperties(); - QtProperty* tProp = doubleManager_->addProperty(tr("timeParam")); - doubleManager_->setValue(tProp, chart.timeParam); + QtProperty* tProp = intManager_->addProperty(tr("timeParam")); + intManager_->setValue(tProp, chart.timeParam); chartGroup->addSubProperty(tProp); + + intSetters_[tProp] = [img, entry](const int& value) + { + auto prop = img->GetChartProperties(); + prop.timeParam = value; + img->SetChartProperties(prop); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + }; + addProperty(chartGroup, idChart); - QtProperty* itemsGroup = groupManager_->addProperty(titleItems); + QtProperty* itemsGroup = groupManager_->addProperty(tr("Image Prop")); const auto& items = img->GetImageProperties(); - for (int i = 0; i < items.size(); ++i) { + for (int i = 0; i < items.size(); ++i) + { const auto& im = items[i]; QtProperty* item = groupManager_->addProperty(QString("Image[%1]").arg(i)); QtProperty* names = stringManager_->addProperty(tr("names")); names->setToolTip(tr("File name list")); stringManager_->setValue(names, im.names.join(", ")); item->addSubProperty(names); + + stringSetters_[names] = [img, entry, i](const QString& s) + { + auto props = img->GetImageProperties(); + if (i >= 0 && i < props.size()) + { + QStringList names = s.split(",", Qt::SkipEmptyParts); + for (int i = 0; i < names.size(); ++i) { + names[i] = names[i].trimmed(); + } + + auto item = props[i]; + item.names = names; + img->SetImageProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QStringList values; for (const auto& v : im.datas) values << QString::number(v); QtProperty* ds = stringManager_->addProperty(tr("datas")); ds->setToolTip(tr("Image data per file")); stringManager_->setValue(ds, values.join(", ")); item->addSubProperty(ds); + + stringSetters_[ds] = [img, entry, i](const QString& s) + { + auto props = img->GetImageProperties(); + if (i >= 0 && i < props.size()) + { + QStringList dataStrings = s.split(",", Qt::SkipEmptyParts); + QList dataValues; + for (const QString& str : dataStrings) + { + bool ok; + int dataValue = str.trimmed().toInt(&ok); + if (ok) { + dataValues.append(dataValue); + } + } + + auto item = props[i]; + item.datas = dataValues; + img->SetImageProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* pth = stringManager_->addProperty(tr("path")); stringManager_->setValue(pth, im.path); item->addSubProperty(pth); + + stringSetters_[ds] = [img, entry, i](const QString& s) + { + auto props = img->GetImageProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.path = s; + img->SetImageProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + QtProperty* sfx = stringManager_->addProperty(tr("suffix")); stringManager_->setValue(sfx, im.suffix); item->addSubProperty(sfx); + + stringSetters_[ds] = [img, entry, i](const QString& s) + { + auto props = img->GetImageProperties(); + if (i >= 0 && i < props.size()) + { + auto item = props[i]; + item.suffix = s; + img->SetImageProperty(i, item); + if (auto ws = WorkSpaceManager::Get().GetCurrent()) ws->NotifyFileEntryUpdated(entry->GetType()); + } + }; + itemsGroup->addSubProperty(item); } addProperty(itemsGroup, idItems); @@ -504,20 +1174,20 @@ void PropertyBrowser::OnFileEntryChange(const QVariant& value) { } return; } - const QString title = QString("CurveEntry - %1").arg(entry->GetName()); - QtProperty* prop = curveEntryManager_->addProperty(title); - QCurveEntryAttribute attr(curve); - curveEntryManager_->setValue(prop, attr); - addProperty(prop, id); + //const QString title = QString("CurveEntry - %1").arg(entry->GetName()); + //QtProperty* prop = curveEntryManager_->addProperty(title); + //QCurveEntryAttribute attr(curve); + //curveEntryManager_->setValue(prop, attr); + //addProperty(prop, id); - // Focus the corresponding group: expand and select it - if (prop) { - QtBrowserItem* item = browser_->topLevelItem(prop); - if (item) { - browser_->setExpanded(item, true); - browser_->setCurrentItem(item); - } - } + //// Focus the corresponding group: expand and select it + //if (prop) { + // QtBrowserItem* item = browser_->topLevelItem(prop); + // if (item) { + // browser_->setExpanded(item, true); + // browser_->setCurrentItem(item); + // } + //} } void PropertyBrowser::OnGroupChange(const QVariant& value) { @@ -538,6 +1208,7 @@ void PropertyBrowser::InitUI() { } void PropertyBrowser::InitPropertyManager() { + enumManager_ = new QtEnumPropertyManager(this); intManager_ = new QtIntPropertyManager(this); boolManager_ = new QtBoolPropertyManager(this); doubleManager_ = new QtDoublePropertyManager(this); @@ -605,6 +1276,27 @@ void PropertyBrowser::InitPropertyManager() { colorSetters_[prop](color); } }); + + connect(stringManager_, &QtStringPropertyManager::valueChanged, this, + [this](QtProperty* prop, const QString& str) { + if (stringSetters_.contains(prop)) { + stringSetters_[prop](str); + } + }); + + connect(intManager_, &QtIntPropertyManager::valueChanged, this, + [this](QtProperty* prop, const int& value) { + if (intSetters_.contains(prop)) { + intSetters_[prop](value); + } + }); + + connect(doubleManager_, &QtDoublePropertyManager::valueChanged, this, + [this](QtProperty* prop, const double& value) { + if (doubleSetters_.contains(prop)) { + doubleSetters_[prop](value); + } + }); } void PropertyBrowser::OnWorkspaceFilesChanged(FileEntryType type, std::shared_ptr fileEntry) { @@ -679,4 +1371,4 @@ void PropertyBrowser::Test() { property = colorManager_->addProperty(tr("color base")); colorManager_->setValue(property, QColor(255, 12, 231, 252)); addProperty(property, QLatin1String("bda")); -} +} \ No newline at end of file diff --git a/src/ui/PropertyBrowser.h b/src/ui/PropertyBrowser.h index 889b4704..7b83e70c 100644 --- a/src/ui/PropertyBrowser.h +++ b/src/ui/PropertyBrowser.h @@ -38,6 +38,7 @@ private: private: class QtTreePropertyBrowser* browser_{ nullptr }; + class QtEnumPropertyManager* enumManager_{ nullptr }; class QtIntPropertyManager* intManager_{ nullptr }; class QtBoolPropertyManager* boolManager_{ nullptr }; class QtDoublePropertyManager* doubleManager_{ nullptr }; @@ -66,5 +67,8 @@ private: // Write-back hooks for color properties QMap> colorSetters_; + QMap> stringSetters_; + QMap> intSetters_; + QMap> doubleSetters_; }; diff --git a/src/workspace/CommandExecutor.cpp b/src/workspace/CommandExecutor.cpp index d8d34db5..d88e48aa 100644 --- a/src/workspace/CommandExecutor.cpp +++ b/src/workspace/CommandExecutor.cpp @@ -21,9 +21,9 @@ void CommandExecutor::Execute(WorkSpace* ws, WorkSpace::CommandWhen when) { } } }; - if (!cmd_.rawArgs.isEmpty()) { - pushArgs(cmd_.rawArgs); - } + //if (!cmd_.rawArgs.isEmpty()) { + // pushArgs(cmd_.rawArgs); + //} const QString programLower = cmd_.program.toLower(); if (!cmd_.path.isEmpty()) { diff --git a/src/workspace/FileEntry.cpp b/src/workspace/FileEntry.cpp index 48d8e4c2..dcae42b8 100644 --- a/src/workspace/FileEntry.cpp +++ b/src/workspace/FileEntry.cpp @@ -469,6 +469,13 @@ bool FileEntryTable::ParseFiles(const tinyxml2::XMLElement * element) return true; } +void FileEntryCurve::SetCurveProperty(int index, const CurveProperty & prop) +{ + if (index >= 0 && index < curveProperties_.size()) { + curveProperties_[index] = prop; + } +} + // FileEntryCurve SaveFiles implementation bool FileEntryCurve::SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) { if (!scene || !doc) { @@ -515,6 +522,13 @@ bool FileEntryCurve::SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocumen return true; } +void FileEntryLight::SetLightProperty(int index, const LightRowProperty & prop) +{ + if (index >= 0 && index < lightProperties_.size()) { + lightProperties_[index] = prop; + } +} + // FileEntryLight SaveFiles implementation bool FileEntryLight::SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) { if (!scene || !doc) { @@ -715,6 +729,54 @@ const FileEntryPolar::ChartProperties& FileEntryPolar::GetChartProperties() cons return chartProperties_; } +void FileEntryPolar::UpdateChartProperties(const QString & key, QVariant var) +{ + if (key == "AngularCount") + { + chartProperties_.AngularCount = var.toInt(); + } + else if (key == "RadialCount") + { + chartProperties_.RadialCount = var.toInt(); + } + else if (key == "AngularTitle") + { + chartProperties_.AngularTitle = var.toString(); + } + else if (key == "RadialTitle") + { + chartProperties_.RadialTitle = var.toString(); + } + else if (key == "AngularMin") + { + chartProperties_.AngularMin = var.toDouble(); + } + else if (key == "AngularMax") + { + chartProperties_.AngularMax = var.toDouble(); + } + else if (key == "RadialMin") + { + chartProperties_.RadialMin = var.toDouble(); + } + else if (key == "RadialMax") + { + chartProperties_.RadialMax = var.toDouble(); + } + else if (key == "AngularUnit") + { + chartProperties_.AngularUnit = var.toString(); + } + else if (key == "RadialUnit") + { + chartProperties_.RadialUnit = var.toString(); + } + else if (key == "timeParam") + { + chartProperties_.timeParam = var.toDouble(); + } +} + void FileEntryPolar::AddLineProperty(const LineProperty& line) { lineProperties_.append(line); } diff --git a/src/workspace/FileEntry.h b/src/workspace/FileEntry.h index d5cd90af..0c7d040f 100644 --- a/src/workspace/FileEntry.h +++ b/src/workspace/FileEntry.h @@ -2,6 +2,7 @@ #include #include +#include #include "xml/tinyxml2.h" enum class FileEntryType { @@ -166,6 +167,7 @@ public: void AddCurveProperty(const CurveProperty& prop) { curveProperties_.append(prop); } void RemoveCurveProperty(int index) { curveProperties_.removeAt(index); } + void SetCurveProperty(int index, const CurveProperty& prop); const CurveProperties& GetCurveProperties() const { return curveProperties_; } FileEntryCurve* AsCurve() override { return this; } @@ -297,6 +299,7 @@ public: void AddLightProperty(const LightRowProperty& prop) { lightProperties_.append(prop); } void RemoveLightProperty(int index) { lightProperties_.removeAt(index); } + void SetLightProperty(int index, const LightRowProperty& prop); const LightRowProperties& GetLightProperties() const { return lightProperties_; } FileEntryLight* AsLight() override { return this; } @@ -341,6 +344,8 @@ public: void SetChartProperties(const ChartProperties& properties); const ChartProperties& GetChartProperties() const; + void UpdateChartProperties(const QString& key, QVariant var); + // Line properties management void AddLineProperty(const LineProperty& line); void RemoveLineProperty(int index);