-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbots.cpp
118 lines (116 loc) · 2.84 KB
/
bots.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "bots.h"
bots::bots(QObject *parent) :
QAbstractTableModel(parent)
{
columnNb=3;
rowNb=0;
qDebug() << "roles count" <<roleNames().size();
qDebug() << "roles " <<roleNames()[Qt::DisplayRole];
qDebug() << "roles " <<roleNames()[1];
qDebug() << "roles " <<roleNames()[2];
qDebug() << "roles " <<roleNames()[3];
qDebug() << "roles " <<roleNames()[4];
qDebug() << "roles " <<roleNames()[5];
end=(GameApp*)-1;
}
int bots::columnCount(const QModelIndex &) const
{
return columnNb;
}
int bots::rowCount(const QModelIndex &) const
{
return rowNb;
}
int bots::size() const
{
return rowNb;
}
QVariant bots::data(const QModelIndex &index, int role) const
{
qDebug() <<"Data called with col: "<<index.column()<<"row:"<<index.row() << "role :" << roleNames()[role];
if (role!=Qt::DisplayRole)
{
qDebug() << "Invalid Role";
return QVariant();
}
if (index.row()>rowNb || index.row()<0)
{
qDebug() << "Invalid Index";
return QVariant::Invalid;
}
switch (index.column())
{
case 0:
qDebug()<<"return " << botList[index.row()]->getName();
return botList[index.row()]->getName();
break;
case 1:
qDebug()<<"return kills";
qDebug()<<"return " << botList[index.row()]->getKills();
return botList[index.row()]->getKills();
break;
case 2:
qDebug()<<"return " << botList[index.row()]->getDeaths();
return botList[index.row()]->getDeaths();
}
return QVariant::Invalid;
}
QVariant bots::headerData(int section, Qt::Orientation orientation, int) const
{
if (orientation==Qt::Horizontal){
switch (section)
{
case 0:
return "Bot Name";
break;
case 1:
return "Kills";
break;
case 2:
return "Deaths";
}
}
return QVariant::Invalid;
}
GameApp* & bots::operator[](const QString & key)
{
int index=0;
for(; index<botList.size(); index++)
{
if(botList.at(index)->getName()==key)
{
return botList[index];
}
}
if (index==botList.size())
{
GameApp * newBot;
beginInsertRows(QModelIndex(),rowNb,rowNb);
botList.append(newBot);
rowNb++;
endInsertRows();
return botList[index];
}
return end;
}
int bots::find(const QString & key)
{
int index=0;
for(; index<botList.size(); index++)
{
if(botList.at(index)->getName()==key)
{
return index;
}
}
return index;
}
void bots::erase(const QString & key)
{
erase(find(key));
}
void bots::erase(int index)
{
botList.removeAt(index);
emit dataChanged(createIndex(index-1,0),createIndex(index+1,3));
}