-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableModel.cpp
More file actions
70 lines (57 loc) · 1.92 KB
/
Copy pathTableModel.cpp
File metadata and controls
70 lines (57 loc) · 1.92 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "TableModel.h"
void TableModel::setDataModel(DataModel *dataModel)
{
if (!dataModel)
{
GUI_DEBUG("Null pointer dataModel* here.");
return;
}
_dataModel = dataModel;
connect(_dataModel, &DataModel::update, this, &TableModel::onUpdate, Qt::QueuedConnection);
}
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return TableHeaders.value(section, "none");
}
int TableModel::rowCount(const QModelIndex &) const
{
return _dataModel->getDataSize();
}
int TableModel::columnCount(const QModelIndex &) const
{
return TableHeaders.size();
}
QVariant TableModel::data(const QModelIndex &index, int role) const
{
auto getData = [this](const QModelIndex &index)->QVariant{
auto tableData = _dataModel->getData(index.row());
if (!tableData.isValid) return QVariant();
switch(index.column())
{
case 0: return QVariant::fromValue(tableData.fileName.fileName());
case 1: return QVariant::fromValue(tableData.colorPrediction == ColorPrediction::Red? QString("Red") : QString("Blue"));
case 2: return QVariant::fromValue(QString::number(tableData.LLR, 'f', 2));
case 3: return QVariant::fromValue(QString::number(tableData.reliability, 'f', 3));
case 4: return QVariant::fromValue(tableData.path.absolutePath());
case 5: return QVariant::fromValue(double(tableData.LLR));
}
return QVariant();
};
switch (role) {
case Qt::DisplayRole:
return getData(index);
default:
break;
}
return QVariant();
}
QHash<int, QByteArray> TableModel::roleNames() const
{
return { {Qt::DisplayRole, "display"} };
}
void TableModel::onUpdate() {
GUI_DEBUG("onNewData");
beginInsertRows(QModelIndex(), rowCount(), rowCount());
endInsertRows();
emit dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, columnCount() - 1));
}