-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournamentviewmodel.cpp
62 lines (53 loc) · 1.98 KB
/
tournamentviewmodel.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
#include "tournamentviewmodel.h"
#include "tournamentsmodel.h"
#include "tournament.h"
TournamentViewModel::TournamentViewModel(QObject *parent, bool onlySubscribed)
:QSortFilterProxyModel(parent),onlySubscribed(onlySubscribed)
{
setSortRole(static_cast<int>(Tournament::TournamentRoles::OriginalOrderRole));
setDynamicSortFilter(true);
}
QHash<int, QByteArray> TournamentViewModel::roleNames() const
{
QHash<int,QByteArray> roles;
roles[static_cast<int>(Tournament::TournamentRoles::NameRole)] = "name";
roles[static_cast<int>(Tournament::TournamentRoles::OriginalOrderRole)] = "originalOrder";
roles[static_cast<int>(Tournament::TournamentRoles::CurrentShownRoundRole)] = "currentShownRound";
return roles;
}
void TournamentViewModel::setCurrentTournament(int row)
{
if(row != m_currenTournament){
m_currenTournament = row;
emit currentTournamentChanged(row);
}
}
int TournamentViewModel::currentTournament()
{
return m_currenTournament;
}
QModelIndex TournamentViewModel::createChildIndex(int row)
{
return sourceModel()->index(row,0);
}
bool TournamentViewModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
//Only show the tournaments that are subscribed to
if(onlySubscribed){
TournamentsModel *tms = static_cast<TournamentsModel*>(sourceModel());
//If the parent item is the root item, we know that this is a tournament
if(static_cast<TournamentsItem *>(source_parent.internalPointer()) == tms->rootItem){
TournamentsItem *tm = static_cast<TournamentsItem *>(source_parent.internalPointer());
if((static_cast<Tournament*>(tm->child(source_row)))->subscribed){
return true;
}
}
return false;
}else{
return true;
}
}
bool TournamentViewModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
return source_left.data(sortRole()) < source_right.data(sortRole());
}