-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBlackHolesTableModel.cpp
64 lines (56 loc) · 1.76 KB
/
BlackHolesTableModel.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "BlackHolesTableModel.h"
BlackHolesTableModel::BlackHolesTableModel(const Galaxy *galaxy, QObject *parent):
QAbstractTableModel(parent),_galaxy(galaxy)
{
}
int BlackHolesTableModel::rowCount(const QModelIndex &parent) const
{
return _galaxy->blackHoleCount();
}
int BlackHolesTableModel::columnCount(const QModelIndex &parent) const
{
return 6;
}
QVariant BlackHolesTableModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
int col=index.column();
int row=index.row();
switch (col)
{
case 0:
return _galaxy->blackHoleStar1(row);
case 1:
return std::round(_galaxy->blackHoleStar1Distance(row)*10.0)*0.1;
case 2:
return _galaxy->blackHoleStar2(row);
case 3:
return std::round(_galaxy->blackHoleStar2Distance(row)*10.0)*0.1;
case 4:
return _galaxy->blackHoleTurnsToClose(row);
case 5:
return _galaxy->blackHoleNextLootChange(row);
default:
return QVariant();
}
return index.row()+index.column();
}
return QVariant();
}
QVariant BlackHolesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
static const QVector<QString> header={tr("Star 1"),tr("Dist."),tr("Star 2"),
tr("Dist."), tr("Days left"),tr("Next loot change")};
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Vertical)
{
return _galaxy->blackHoleId(section);
}
else if (orientation == Qt::Horizontal) {
return header.at(section);
}
}
return QVariant();
}