-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablemodel.cpp
48 lines (41 loc) · 1.08 KB
/
tablemodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "tablemodel.h"
TableModel::TableModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
int TableModel::rowCount([[maybe_unused]] const QModelIndex &parent) const
{
return m_data.size();
}
int TableModel::columnCount([[maybe_unused]] const QModelIndex &parent) const
{
return 2;
}
QVariant TableModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole) {
auto row = index.row();
auto column = index.column();
return m_data[row][column];
}
return QVariant();
}
QVariant TableModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (section == 0) {
return "KKS";
} else {
return "Value";
}
}
return QAbstractTableModel::headerData(section, orientation, role);
}
void TableModel::appendRow(const QString &first, const QString &second)
{
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append({first, second});
endInsertRows();
}