3#include <QtCharts/QVXYModelMapper>
4#include <QtCore/QAbstractTableModel>
6#include <QtWidgets/QHeaderView>
7#include <QtWidgets/QTableView>
14class Table :
public QAbstractTableModel {
16 explicit Table(QObject *parent =
nullptr) : QAbstractTableModel(parent) {}
19 std::vector<std::pair<std::string, std::vector<double> > >
rows;
22 auto *tableView =
new QTableView;
23 tableView->setModel(
this);
24 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
25 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
30 std::string
str()
const {
31 std::vector<int> columnSizes(
header.size() + 1, 0);
32 for (
auto &row :
rows)
33 columnSizes[0] =
std::max((
int)row.first.length(), columnSizes[0]);
34 for (
int i = 0; i <
header.size(); ++i)
37 ss << std::setw(columnSizes[0]) <<
" ";
39 for (
auto &h :
header) ss << std::setw(columnSizes[c++]) << h;
41 for (
auto &row :
rows) {
42 ss << std::setw(columnSizes[0]) << row.first;
44 for (
auto d : row.second)
45 ss << std::setw(columnSizes[c++]) << std::setprecision(10) << std::right
53 std::vector<int> columnSizes(
header.size() + 1, 0);
54 for (
auto &row :
rows)
55 columnSizes[0] =
std::max((
int)row.first.length(), columnSizes[0]);
56 for (
int i = 0; i <
header.size(); ++i)
59 ss << std::setw(columnSizes[0]);
61 for (
auto &h :
header) ss <<
" & " << std::setw(columnSizes[c++]) << h;
62 ss <<
" \\\\\\hline" << std::endl;
63 for (
auto &row :
rows) {
64 ss << std::setw(columnSizes[0]) << row.first;
67 for (
auto d : row.second) {
68 ss <<
" & " << std::setw(columnSizes[c++]);
69 if (d == m) ss <<
"\\bfseries ";
70 ss << std::setprecision(4) << std::right << d;
72 ss <<
" \\\\" << std::endl;
77 int rowCount(
const QModelIndex &parent = QModelIndex())
const override {
78 return static_cast<int>(
rows.size() + 1);
81 int columnCount(
const QModelIndex &parent = QModelIndex())
const override {
82 return static_cast<int>(
header.size());
86 int role = Qt::DisplayRole)
const override {
88 return QString::fromStdString(
header[section %
header.size()]);
89 return QString::fromStdString(
rows[section %
rows.size()].first);
92 QVariant
data(
const QModelIndex &index,
93 int role = Qt::DisplayRole)
const override {
95 return rows[index.row()].second[index.column()];
99 Qt::ItemFlags
flags(
const QModelIndex &index)
const override {
100 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
103 void addStatsRows(std::string columnName,
const std::vector<double> &values1,
104 const std::vector<double> &values2,
105 const std::vector<double> &values3,
106 const std::vector<double> &values4,
107 const std::vector<double> &values5) {
108 rows.push_back(std::make_pair<std::string, std::vector<double> >(
111 values1.empty() ? std::nan(
"N/A") :
stat::median(values1),
112 values2.empty() ? std::nan(
"N/A") :
stat::median(values2),
113 values3.empty() ? std::nan(
"N/A") :
stat::median(values3),
114 values4.empty() ? std::nan(
"N/A") :
stat::median(values4),
115 values5.empty() ? std::nan(
"N/A") :
stat::median(values5)}));
116 rows.push_back(std::make_pair<std::string, std::vector<double> >(
119 values1.empty() ? std::nan(
"N/A") :
stat::mean(values1),
120 values2.empty() ? std::nan(
"N/A") :
stat::mean(values2),
121 values3.empty() ? std::nan(
"N/A") :
stat::mean(values3),
122 values4.empty() ? std::nan(
"N/A") :
stat::mean(values4),
123 values5.empty() ? std::nan(
"N/A") :
stat::mean(values5)}));
124 rows.push_back(std::make_pair<std::string, std::vector<double> >(
127 values1.empty() ? std::nan(
"N/A") :
stat::min(values1),
128 values2.empty() ? std::nan(
"N/A") :
stat::min(values2),
129 values3.empty() ? std::nan(
"N/A") :
stat::min(values3),
130 values4.empty() ? std::nan(
"N/A") :
stat::min(values4),
131 values5.empty() ? std::nan(
"N/A") :
stat::min(values5)}));
132 rows.push_back(std::make_pair<std::string, std::vector<double> >(
135 values1.empty() ? std::nan(
"N/A") :
stat::max(values1),
136 values2.empty() ? std::nan(
"N/A") :
stat::max(values2),
137 values3.empty() ? std::nan(
"N/A") :
stat::max(values3),
138 values4.empty() ? std::nan(
"N/A") :
stat::max(values4),
139 values5.empty() ? std::nan(
"N/A") :
stat::max(values5)}));
140 rows.push_back(std::make_pair<std::string, std::vector<double> >(
143 values1.empty() ? std::nan(
"N/A") :
stat::std(values1),
144 values2.empty() ? std::nan(
"N/A") :
stat::std(values2),
145 values3.empty() ? std::nan(
"N/A") :
stat::std(values3),
146 values4.empty() ? std::nan(
"N/A") :
stat::std(values4),
147 values5.empty() ? std::nan(
"N/A") :
stat::std(values5)}));
int orientation(const Point &p, const Point &q, const Point &r)
Definition: Primitives.cpp:100
QWidget * createWidget()
Definition: Table.hpp:21
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: Table.hpp:99
std::string str() const
Definition: Table.hpp:30
std::vector< std::pair< std::string, std::vector< double > > > rows
Definition: Table.hpp:19
void addStatsRows(std::string columnName, const std::vector< double > &values1, const std::vector< double > &values2, const std::vector< double > &values3, const std::vector< double > &values4, const std::vector< double > &values5)
Definition: Table.hpp:103
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: Table.hpp:92
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: Table.hpp:81
std::string latex() const
Definition: Table.hpp:52
Table(QObject *parent=nullptr)
Definition: Table.hpp:16
std::vector< std::string > header
Definition: Table.hpp:18
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: Table.hpp:85
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: Table.hpp:77
double max(const std::vector< double > &values)
Definition: PathStatistics.hpp:79
double std(const std::vector< double > &values)
Definition: PathStatistics.hpp:85
double min(const std::vector< double > &values)
Definition: PathStatistics.hpp:73
double median(std::vector< double > values)
Definition: PathStatistics.hpp:57
double mean(const std::vector< double > &values)
Definition: PathStatistics.hpp:67