8 #include "ui_statistics_dialog.h"
9 #include <QTableWidgetItem>
13 : QDialog(parent), ui(new
Ui::statistics_dialog), _parent(parent)
17 setWindowTitle(QString(
"Statistics | %1").
arg(
_parent->windowTitle()));
18 setWindowFlag(Qt::Tool);
20 ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
22 connect(
ui->rangeComboBox, qOverload<int>(&QComboBox::currentIndexChanged),
this,
24 auto rect = _parent->currentBoundingRect();
25 update({ rect.left(), rect.right() });
36 return (
ui->rangeComboBox->currentIndex() == 0);
41 std::map<QString, Statistics> statistics;
46 const auto ts = info.curve->data();
50 for (
size_t i = 0; i < ts->size(); i++)
52 const auto p = ts->sample(i);
55 if (p.x() < range.
min)
59 if (p.x() > range.
max)
73 stat.
min = std::min(stat.
min, p.y());
74 stat.
max = std::max(stat.
max, p.y());
78 statistics[info.curve->title().text()] = stat;
81 ui->tableWidget->setRowCount(statistics.size());
83 for (
const auto& it : statistics)
85 const auto& stat = it.second;
87 std::array<QString, 5> row_values;
88 row_values[0] = it.first;
89 row_values[1] = QString::number(stat.count);
90 row_values[2] = QString::number(stat.min,
'f');
91 row_values[3] = QString::number(stat.max,
'f');
92 double mean = stat.mean_tot / double(stat.count);
93 row_values[4] = QString::number(mean,
'f');
95 for (
size_t col = 0; col < row_values.size(); col++)
97 if (
auto item =
ui->tableWidget->item(row, col))
99 item->setText(row_values[col]);
103 ui->tableWidget->setItem(row, col,
new QTableWidgetItem(row_values[col]));
116 setWindowTitle(QString(
"Statistics | %1").
arg(title));
121 QWidget::closeEvent(event);