#include "MeasureAnalysisParticleCountPlotView.h" #include "qcustomplot.h" #include "csv.h" #include MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidget* parent) : MeasureAnalysisView { parent } { this->setAnalyzeViewType(ViewType::CountSpectrum); _custom_plot = new QCustomPlot(this); _custom_plot->setGeometry(0, 0, this->width(), this->height()); } void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap& data_files_set) { for (auto it = data_files_set.begin(); it != data_files_set.end(); ++it) { loadDataFromFile(it.value()); } } 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 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(); }