2026-03-03 18:15:34 +08:00
|
|
|
#include "MeasureAnalysisParticleCountPlotView.h"
|
|
|
|
|
#include "qcustomplot.h"
|
|
|
|
|
#include "csv.h"
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
|
|
MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidget* parent)
|
|
|
|
|
: MeasureAnalysisView { parent }
|
|
|
|
|
{
|
|
|
|
|
this->setAnalyzeViewType(ViewType::CountSpectrum);
|
|
|
|
|
|
|
|
|
|
_custom_plot = new QCustomPlot(this);
|
|
|
|
|
_custom_plot->setGeometry(0, 0, this->width(), this->height());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 16:17:04 +08:00
|
|
|
void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
2026-03-03 18:15:34 +08:00
|
|
|
{
|
|
|
|
|
for (auto it = data_files_set.begin(); it != data_files_set.end(); ++it) {
|
2026-03-04 16:17:04 +08:00
|
|
|
loadDataFromFile(it.value().toString());
|
2026-03-03 18:15:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeasureAnalysisParticleCountPlotView::setupCustomPlot()
|
|
|
|
|
{
|
|
|
|
|
_custom_plot->xAxis->setLabel(QString(QStringLiteral(u"道址")));
|
|
|
|
|
_custom_plot->yAxis->setLabel(QString(QStringLiteral(u"计数")));
|
|
|
|
|
_custom_plot->legend->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MeasureAnalysisParticleCountPlotView::loadDataFromFile(const QString& filename)
|
|
|
|
|
{
|
|
|
|
|
std::string address_str = QString(QStringLiteral(u"道址")).toStdString();
|
|
|
|
|
std::string count_str = QString(QStringLiteral(u"计数")).toStdString();
|
|
|
|
|
|
|
|
|
|
io::CSVReader<
|
|
|
|
|
2,
|
|
|
|
|
io::trim_chars<' ', '\t'>,
|
|
|
|
|
io::double_quote_escape<',', '"'>,
|
|
|
|
|
io::throw_on_overflow,
|
|
|
|
|
io::empty_line_comment
|
|
|
|
|
> reader(filename.toUtf8().toStdString());
|
|
|
|
|
reader.read_header(io::ignore_extra_column, address_str, count_str);
|
|
|
|
|
|
|
|
|
|
int address;
|
|
|
|
|
int particle_count;
|
|
|
|
|
QVector<double> x, y;
|
|
|
|
|
while (reader.read_row(address, particle_count)) {
|
|
|
|
|
x.push_back(address);
|
|
|
|
|
y.push_back(particle_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto graph = _custom_plot->addGraph();
|
|
|
|
|
// graph->setPen(QPen(Qt::red));
|
|
|
|
|
// graph->setBrush(QBrush(Qt::red));
|
|
|
|
|
graph->setData(x, y, true);
|
|
|
|
|
|
|
|
|
|
_custom_plot->replot();
|
|
|
|
|
}
|