-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtournament.cpp
95 lines (82 loc) · 2.36 KB
/
tournament.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
#include "tournament.h"
Tournament::Tournament(TournamentsItem *parent,QString name,int originalOrder):
TournamentsItem(parent,ItemType::Tournament),name(name), originalOrder(originalOrder)
{
}
int Tournament::columnCount() const
{
return 1;
}
QVariant Tournament::data(int role) const
{
return data(static_cast<TournamentRoles>(role));
}
QVariant Tournament::data(Tournament::TournamentRoles role) const
{
switch(role){
case TournamentRoles::NameRole:
return this->name;
case TournamentRoles::OriginalOrderRole:
return this->originalOrder;
case TournamentRoles::EventTypeRole:
return this->eventType;
case TournamentRoles::StatusRole:
return this->status;
case TournamentRoles::CurrentShownRoundRole:
return this->currentShownRound;
}
}
TournamentsItem *Tournament::child(int position) const
{
return rounds.at(position);
}
int Tournament::childCount() const
{
return rounds.size();
}
bool Tournament::addChild(TournamentsItem *item)
{
if(item->tourType != TournamentsItem::ItemType::Round){return false;}
rounds.append(static_cast<Round*>(item));
return true;
}
int Tournament::position(TournamentsItem *item)
{
Round *r = static_cast<Round*>(item);
return rounds.indexOf(r);
}
int Tournament::position(int id){
for(int i=0;i<rounds.size();++i){
if(rounds.at(i)->number == id){
return i;
}
}
return -1;
}
bool Tournament::setData(int role, const QVariant &value)
{
switch(static_cast<TournamentRoles>(role)){
case TournamentRoles::NameRole:
if(name == value.toString()){return false;}
name = value.toString();
return true;
case TournamentRoles::OriginalOrderRole:
if(originalOrder == value.toInt()){return false;}
originalOrder = value.toInt();
return true;
case TournamentRoles::EventTypeRole:
if(eventType == value.toString()){return false;}
eventType = value.toString();
return true;
case TournamentRoles::StatusRole:
if(status == value.toString()){return false;}
status = value.toString();
return true;
case TournamentRoles::CurrentShownRoundRole:
if(currentShownRound == value.toInt()){return false;}
currentShownRound = value.toInt();
return true;
default:
return false;
}
}