diff --git a/src/MeasureAnalysisTreeView.cpp b/src/MeasureAnalysisTreeView.cpp index 00e4b5d..1dd0cb4 100644 --- a/src/MeasureAnalysisTreeView.cpp +++ b/src/MeasureAnalysisTreeView.cpp @@ -122,6 +122,15 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) } } } break; + case AnalysisType::ParticleInTimeView: { + MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name); + if (project_model) { + auto file_name = project_model->GetParticleEnergyDataFilename(); + if ( !file_name.isEmpty() ) { + data_files_set[QStringLiteral(u"粒子能量数据")] = file_name; + } + } + } break; default: break; } diff --git a/src/MeasureAnalysisView.cpp b/src/MeasureAnalysisView.cpp index cf72a82..64f4518 100644 --- a/src/MeasureAnalysisView.cpp +++ b/src/MeasureAnalysisView.cpp @@ -2,6 +2,7 @@ #include #include "MeasureAnalysisDataTableView.h" #include "MeasureAnalysisParticleCountPlotView.h" +#include "ParticleInjectTimeAnalysis.h" MeasureAnalysisView *MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type) { @@ -76,7 +77,7 @@ MeasureAnalysisView *MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type) // new_view->setDeleteOnClose(false); } break; case AnalysisType::ParticleInTimeView: { - new_view = new MeasureAnalysisDataTableView; + new_view = new ParticleInjectTimeAnalysis; new_view->setDeleteOnClose(false); } break; case AnalysisType::ParticleTimeDiffView: { diff --git a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp index c6c7498..dd36bb1 100644 --- a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp +++ b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp @@ -6,21 +6,22 @@ #include #include #include +#include +#include #include #include #include #include "CustomQwtPlot.h" #include +#include + ParticleInjectTimeAnalysis::ParticleInjectTimeAnalysis(QWidget *parent) : MeasureAnalysisView(parent), ui(new Ui::ParticleInjectTimeAnalysis) { ui->setupUi(this); InitUi(); - // 获取当前可执行文件的路径 - QString Path = QCoreApplication::applicationDirPath(); - m_AllData = getParticleInjectTimeData(Path + "/data.csv"); - setData(m_AllData); + } ParticleInjectTimeAnalysis::~ParticleInjectTimeAnalysis() @@ -35,7 +36,11 @@ void ParticleInjectTimeAnalysis::InitViewWorkspace(const QString &project_name) void ParticleInjectTimeAnalysis::SetAnalyzeDataFilename(const QMap &data_files_set) { - + if(!data_files_set.isEmpty()) + { + m_AllData = getParticleInjectTimeData(data_files_set.first().toString()); + setData(m_AllData); + } } void ParticleInjectTimeAnalysis::setData(QVector data) @@ -61,16 +66,16 @@ void ParticleInjectTimeAnalysis::setData(QVector data) } // 创建曲线并设置数据 - QwtPlotCurve *curve = new QwtPlotCurve("正弦曲线"); + QwtPlotCurve *curve = new QwtPlotCurve(); curve->setSamples(x, y); - // 将曲线添加到 CustomQwtPlot 中(会自动分配颜色) plot->AddCurve(curve); // 设置坐标轴范围和标题 - plot->setAxisScale(QwtPlot::xBottom, 0, x.last()); - plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue); +// plot->setAxisScale(QwtPlot::xBottom, 0, x.last()); +// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue); plot->setAxisTitle(QwtPlot::xBottom, "粒子序号"); plot->setAxisTitle(QwtPlot::yLeft, "粒子时间"); + LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName())); // 刷新绘图 plot->replot(); @@ -79,7 +84,7 @@ void ParticleInjectTimeAnalysis::setData(QVector data) QVector ParticleInjectTimeAnalysis::getParticleInjectTimeData(QString path) { - QVector records; + QVector records; QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -129,6 +134,7 @@ QVector ParticleInjectTimeAnalysis::getParticleInjectTimeDat } file.close(); + return records; } @@ -136,5 +142,29 @@ void ParticleInjectTimeAnalysis::InitUi() { plot = new CustomQwtPlot(); plot->SetXaxisDragScale(true); - ui->verticalLayout->addWidget(plot); + setupPlot(); + ui->verticalLayout_2->addWidget(plot); +} + +void ParticleInjectTimeAnalysis::setupPlot() +{ + plot->setCanvasBackground(Qt::white); + QwtPlotCanvas* canvas = qobject_cast(plot->canvas()); + canvas->setFrameStyle(QFrame::NoFrame); + + plot->setAxisTitle(QwtPlot::xBottom, QString(QStringLiteral(u"道址"))); + plot->setAxisTitle(QwtPlot::yLeft, QString(QStringLiteral(u"计数"))); + // set axis auto scale + plot->setAxisAutoScale(QwtPlot::xBottom, true); + plot->setAxisAutoScale(QwtPlot::yLeft, true); + // 启用网格线 + plot->enableAxis(QwtPlot::xBottom); + plot->enableAxis(QwtPlot::yLeft); + + // 设置QWT图例 + QwtLegend* legend = new QwtLegend(); + legend->setDefaultItemMode(QwtLegendData::ReadOnly); + plot->insertLegend(legend, QwtPlot::RightLegend); + + plot->SetXaxisDragScale(true); } diff --git a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h index c07c394..8d6d341 100644 --- a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h +++ b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h @@ -38,6 +38,7 @@ public: QVector getParticleInjectTimeData(QString path); private: void InitUi(); + void setupPlot(); private: Ui::ParticleInjectTimeAnalysis *ui; diff --git a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui index e9043a7..a37f20a 100644 --- a/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui +++ b/src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui @@ -13,10 +13,7 @@ ParticleInjectTimeAnalysis - - - 0 - + 0 @@ -124,7 +121,16 @@ - + + + 0 + 0 + + + + + + 0 @@ -138,7 +144,7 @@ 0 - + diff --git a/src/src.pro b/src/src.pro index ddf4a5b..cc96c2b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -31,11 +31,11 @@ MOC_DIR = $${BUILD_MOC}/$${TARGET}/moc UI_DIR = $${BUILD_UI}/$${TARGET}/ui INCLUDEPATH += \ - $${PWD}/MeasureAnalysisParticleCountPlotView + $${PWD}/MeasureAnalysisParticleCountPlotView \ $${PWD}/ParticleInjectTimeView DEPENDPATH += \ - $${PWD}/MeasureAnalysisParticleCountPlotView + $${PWD}/MeasureAnalysisParticleCountPlotView \ $${PWD}/ParticleInjectTimeView SOURCES += \