-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraktseasonsmodel.cpp
65 lines (54 loc) · 1.65 KB
/
traktseasonsmodel.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
#include "traktseasonsmodel.h"
#include "traktshow.h"
TraktSeasonsModel::TraktSeasonsModel(TraktShow *show, QObject *parent) :
TraktModel(buildRequest(show), parent),
m_show(show)
{
}
TraktRequest *TraktSeasonsModel::buildRequest(TraktShow *show) const
{
TraktRequest *request = new TraktRequest();
request->setPath(QString("/shows/%1/seasons").arg(show->ids()->trakt()));
request->addQueryItem("extended", "full,images");
return request;
}
QVariant TraktSeasonsModel::data(const QModelIndex &index, int role) const
{
TraktSeason *season = at(index.row());
if (!season) {
return QVariant();
}
switch (role) {
case RoleNumber:
return season->number();
case RoleRating:
return season->rating();
case RoleVotes:
return season->votes();
case RoleEpisodeCount:
return season->episodeCount();
case RoleAiredEpisodes:
return season->airedEpisodes();
}
return TraktModel<TraktSeason*>::data(index, role);
}
QHash<int, QByteArray> TraktSeasonsModel::roleNames() const
{
QHash<int, QByteArray> roleNames = TraktModel<TraktSeason*>::roleNames();
roleNames.insert(RoleNumber, "number");
roleNames.insert(RoleRating, "rating");
roleNames.insert(RoleVotes, "votes");
roleNames.insert(RoleEpisodeCount, "episodeCount");
roleNames.insert(RoleAiredEpisodes, "airedEpisodes");
return roleNames;
}
TraktSeason *TraktSeasonsModel::convertItem(const QVariantMap &item)
{
TraktSeason *season = new TraktSeason(item, m_show);
season->parse(item);
return season;
}
TraktSeason *TraktSeasonsModel::at(int i) const
{
return TraktModel::at(i);
}