-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamemodel.cpp
More file actions
66 lines (50 loc) · 1.2 KB
/
Copy pathgamemodel.cpp
File metadata and controls
66 lines (50 loc) · 1.2 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
#include "gamemodel.h"
GameModel::GameModel(QObject *parent) :
QAbstractListModel(parent)
{
int x, y, z;
int randItem [2];
QModelIndex ind;
QMap<int,QVariant> obj_roles;
x = 0;
y = 0;
for (z = 0; z < rowCount; z++)
{
obj_roles[ValueRole] = 0;
obj_roles[XRole] = x;
obj_roles[YRole] = y;
setItemData(index(z),obj_roles);
if (x == 3)
x = 0;
else
x++;
if (y == 3)
y = 0;
else
y++;
}
randItem[0] = rand() % 16;
randItem[1] = rand() % 16;
while (randItem[1] == randItem[0])
randItem[1] = rand() % 16;
for (z = 0; z < 2; z++)
{
ind = index(randItem[z]);
setData(ind,2*(rand() % 2 + 1),ValueRole);
}
}
QHash<int,QByteArray> GameModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[ValueRole] = "value";
roles[XRole] = "xpos";
roles[YRole] = "ypos";
return roles;
}
QVariant GameModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
GameTile* tile = static_cast<GameTile*>(index.internalPointer());
return tile->data(role);
}