annotate src/anime.cpp @ 1:1ae666fdf9e2

*: initial commit
author Paper <mrpapersonic@gmail.com>
date Tue, 08 Aug 2023 19:49:15 -0400
parents
children 23d0d9319a00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include <chrono>
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include <string>
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include <vector>
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #include <cmath>
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include "window.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "anilist.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include "config.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include "anime.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 //#include "information.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap = {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 {CURRENT, "Watching"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 {PLANNING, "Planning"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 {COMPLETED, "Completed"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 {DROPPED, "Dropped"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 {PAUSED, "On hold"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 {REPEATING, "Rewatching"}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 };
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap = {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 {FINISHED, "Finished"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 {RELEASING, "Airing"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 {NOT_YET_RELEASED, "Not aired yet"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 {CANCELLED, "Cancelled"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 {HIATUS, "On hiatus"}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 };
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap = {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 {WINTER, "Winter"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 {SPRING, "Spring"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 {SUMMER, "Summer"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 {FALL, "Fall"}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 };
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap = {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 {TV, "TV"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 {TV_SHORT, "TV short"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 {MOVIE, "Movie"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 {SPECIAL, "Special"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 {OVA, "OVA"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 {ONA, "ONA"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 {MUSIC, "Music video"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 /* these should NEVER be in the list. naybe we should
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 remove them? */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 {MANGA, "Manga"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 {NOVEL, "Novel"},
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 {ONE_SHOT, "One-shot"}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 };
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 Anime::Anime() {}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 Anime::Anime(const Anime& a) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 status = a.status;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 progress = a.progress;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 score = a.score;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 started = a.started;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 completed = a.completed;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 notes = a.notes;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 id = a.id;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 title = a.title;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 episodes = a.episodes;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 airing = a.airing;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 air_date = a.air_date;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 genres = a.genres;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 producers = a.producers;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65 type = a.type;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 season = a.season;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 audience_score = a.audience_score;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 synopsis = a.synopsis;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 duration = a.duration;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 void AnimeList::Add(Anime& anime) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73 if (anime_id_to_anime.contains(anime.id))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75 anime_list.push_back(anime);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 anime_id_to_anime.emplace(anime.id, &anime);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
79 void AnimeList::Insert(size_t pos, Anime& anime) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80 if (anime_id_to_anime.contains(anime.id))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82 anime_list.insert(anime_list.begin()+pos, anime);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 anime_id_to_anime.emplace(anime.id, &anime);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 void AnimeList::Delete(size_t index) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 anime_list.erase(anime_list.begin()+index);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 void AnimeList::Clear() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 anime_list.clear();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 size_t AnimeList::Size() const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 return anime_list.size();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 std::vector<Anime>::iterator AnimeList::begin() noexcept {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99 return anime_list.begin();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 std::vector<Anime>::iterator AnimeList::end() noexcept {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 return anime_list.end();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106 std::vector<Anime>::const_iterator AnimeList::cbegin() noexcept {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 return anime_list.cbegin();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 std::vector<Anime>::const_iterator AnimeList::cend() noexcept {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111 return anime_list.cend();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 AnimeList::AnimeList() {}
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115 AnimeList::AnimeList(const AnimeList& l) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116 for (int i = 0; i < l.Size(); i++) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 anime_list.push_back(Anime(l[i]));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 name = l.name;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122 AnimeList::~AnimeList() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 anime_list.clear();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124 anime_list.shrink_to_fit();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127 Anime* AnimeList::AnimeById(int id) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128 return anime_id_to_anime.contains(id) ? anime_id_to_anime[id] : nullptr;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131 bool AnimeList::AnimeInList(int id) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 return anime_id_to_anime.contains(id);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 Anime& AnimeList::operator[](std::size_t index) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 return anime_list.at(index);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139 const Anime& AnimeList::operator[](std::size_t index) const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 return anime_list.at(index);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
141 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143 /* ------------------------------------------------------------------------- */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
145 /* Thank you qBittorrent for having a great example of a
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146 widget model. */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
147 AnimeListWidgetModel::AnimeListWidgetModel (QWidget* parent, AnimeList* alist)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
148 : QAbstractListModel(parent)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149 , list(*alist) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
150 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
151 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
152
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154 return list.Size();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
157 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
158 return NB_COLUMNS;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
159 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
160
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
161 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
162 if (role == Qt::DisplayRole) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
163 switch (section) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
164 case AL_TITLE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
165 return tr("Anime title");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
166 case AL_PROGRESS:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
167 return tr("Progress");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
168 case AL_TYPE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
169 return tr("Type");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
170 case AL_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
171 return tr("Score");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
172 case AL_SEASON:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
173 return tr("Season");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
174 case AL_STARTED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
175 return tr("Date started");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
176 case AL_COMPLETED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
177 return tr("Date completed");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
178 case AL_NOTES:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
179 return tr("Notes");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
180 case AL_AVG_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
181 return tr("Average score");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
182 case AL_UPDATED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
183 return tr("Last updated");
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
184 default:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
185 return {};
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
186 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
187 } else if (role == Qt::TextAlignmentRole) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
188 switch (section) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
189 case AL_TITLE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
190 case AL_NOTES:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
191 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
192 case AL_PROGRESS:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
193 case AL_TYPE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
194 case AL_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
195 case AL_AVG_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
196 return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
197 case AL_SEASON:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
198 case AL_STARTED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
199 case AL_COMPLETED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
200 case AL_UPDATED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
201 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
202 default:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
203 return QAbstractListModel::headerData(section, orientation, role);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
204 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
205 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
206 return QAbstractListModel::headerData(section, orientation, role);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
207 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
208
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
209 Anime* AnimeListWidgetModel::GetAnimeFromIndex(const QModelIndex& index) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
210 return (!index.isValid()) ? &(list[index.row()]) : nullptr;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
211 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
212
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
213 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
214 if (!index.isValid())
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
215 return QVariant();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
216 if (role == Qt::DisplayRole) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
217 switch (index.column()) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
218 case AL_TITLE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
219 return QString::fromWCharArray(list[index.row()].title.c_str());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
220 case AL_PROGRESS:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
221 return list[index.row()].progress;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
222 case AL_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
223 return list[index.row()].score;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
224 case AL_TYPE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
225 return QString::fromStdString(AnimeFormatToStringMap[list[index.row()].type]);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
226 case AL_SEASON:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
227 return QString::fromStdString(AnimeSeasonToStringMap[list[index.row()].season]) + " " + QString::number((int)list[index.row()].air_date.year());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
228 case AL_AVG_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
229 return list[index.row()].audience_score;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
230 case AL_STARTED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
231 /* why c++20 chrono is stinky: the game */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
232 return QDate(int(list[index.row()].started.year()), static_cast<int>((unsigned int)list[index.row()].started.month()), static_cast<int>((unsigned int)list[index.row()].started.day()));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
233 case AL_COMPLETED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
234 return QDate(int(list[index.row()].completed.year()), static_cast<int>((unsigned int)list[index.row()].completed.month()), static_cast<int>((unsigned int)list[index.row()].completed.day()));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
235 case AL_NOTES:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
236 return QString::fromWCharArray(list[index.row()].notes.c_str());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
237 default:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
238 return "";
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
239 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
240 } else if (role == Qt::TextAlignmentRole) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
241 switch (index.column()) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
242 case AL_TITLE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
243 case AL_NOTES:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
244 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
245 case AL_PROGRESS:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
246 case AL_TYPE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
247 case AL_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
248 case AL_AVG_SCORE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
249 return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
250 case AL_SEASON:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
251 case AL_STARTED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
252 case AL_COMPLETED:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
253 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
254 default:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
255 break;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
256 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
257 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
258 return QVariant();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
259 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
260
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
261 /* this should ALWAYS be called if the list is edited */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
262 void AnimeListWidgetModel::Update() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
263
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
264 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
265
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
266 /* Most of this stuff is const and/or should be edited in the Information dialog
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
267
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
268 bool AnimeListWidgetModel::setData(const QModelIndex &index, const QVariant &value, int role) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
269 if (!index.isValid() || role != Qt::DisplayRole)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
270 return false;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
271
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
272 Anime* const anime = &list[index.row()];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
273
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
274 switch (index.column()) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
275 case AL_TITLE:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
276 break;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
277 case AL_CATEGORY:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
278 break;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
279 default:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
280 return false;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
281 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
282
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
283 return true;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
284 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
285 */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
286
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
287 int AnimeListWidget::VisibleColumnsCount() const {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
288 int count = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
289
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
290 for (int i = 0, end = header()->count(); i < end; i++)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
291 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
292 if (!isColumnHidden(i))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
293 count++;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
294 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
295
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
296 return count;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
297 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
298
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
299 void AnimeListWidget::SetColumnDefaults() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
300 setColumnHidden(AnimeListWidgetModel::AL_SEASON, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
301 setColumnHidden(AnimeListWidgetModel::AL_TYPE, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
302 setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
303 setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
304 setColumnHidden(AnimeListWidgetModel::AL_SCORE, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
305 setColumnHidden(AnimeListWidgetModel::AL_TITLE, false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
306 setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
307 setColumnHidden(AnimeListWidgetModel::AL_STARTED, true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
308 setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
309 setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
310 setColumnHidden(AnimeListWidgetModel::AL_NOTES, true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
311 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
312
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
313 void AnimeListWidget::DisplayColumnHeaderMenu() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
314 QMenu *menu = new QMenu(this);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
315 menu->setAttribute(Qt::WA_DeleteOnClose);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
316 menu->setTitle(tr("Column visibility"));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
317 menu->setToolTipsVisible(true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
318
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
319 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
320 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
321 if (i == AnimeListWidgetModel::AL_TITLE)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
322 continue;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
323 const auto column_name = model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
324 QAction *action = menu->addAction(column_name, this, [this, i](const bool checked) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
325 if (!checked && (VisibleColumnsCount() <= 1))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
326 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
327
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
328 setColumnHidden(i, !checked);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
329
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
330 if (checked && (columnWidth(i) <= 5))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
331 resizeColumnToContents(i);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
332
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
333 // SaveSettings();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
334 });
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
335 action->setCheckable(true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
336 action->setChecked(!isColumnHidden(i));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
337 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
338
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
339 menu->addSeparator();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
340 QAction *resetAction = menu->addAction(tr("Reset to defaults"), this, [this]()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
341 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
342 for (int i = 0, count = header()->count(); i < count; ++i)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
343 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
344 SetColumnDefaults();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
345 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
346 // SaveSettings();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
347 });
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
348
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
349 menu->popup(QCursor::pos());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
350 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
351
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
352 void AnimeListWidget::DisplayListMenu() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
353 /* throw out any other garbage */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
354 const QModelIndexList selected_items = selectionModel()->selectedRows();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
355 if (selected_items.size() != 1 || !selected_items.first().isValid())
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
356 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
357
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
358 const QModelIndex index = model->index(selected_items.first().row());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
359 Anime* anime = model->GetAnimeFromIndex(index);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
360 if (!anime)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
361 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
362
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
363 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
364
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
365 void AnimeListWidget::ItemDoubleClicked() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
366 /* throw out any other garbage */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
367 const QModelIndexList selected_items = selectionModel()->selectedRows();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
368 if (selected_items.size() != 1 || !selected_items.first().isValid())
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
369 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
370
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
371 /* TODO: after we implement our sort model, we have to use mapToSource here... */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
372 const QModelIndex index = model->index(selected_items.first().row());
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
373 Anime* anime = model->GetAnimeFromIndex(index);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
374 if (!anime)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
375 return;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
376
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
377 /* todo: open information dialog... */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
378 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
379
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
380 AnimeListWidget::AnimeListWidget(QWidget* parent, AnimeList* alist)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
381 : QTreeView(parent) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
382 model = new AnimeListWidgetModel(parent, alist);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
383 this->setModel(model);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
384 setUniformRowHeights(true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
385 setAllColumnsShowFocus(false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
386 setSortingEnabled(true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
387 setSelectionMode(QAbstractItemView::ExtendedSelection);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
388 setItemsExpandable(false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
389 setRootIsDecorated(false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
390 setContextMenuPolicy(Qt::CustomContextMenu);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
391 connect(this, &QAbstractItemView::doubleClicked, this, &ItemDoubleClicked);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
392 connect(this, &QWidget::customContextMenuRequested, this, &DisplayListMenu);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
393
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
394 /* Enter & return keys */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
395 connect(new QShortcut(Qt::Key_Return, this, nullptr, nullptr, Qt::WidgetShortcut),
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
396 &QShortcut::activated, this, &ItemDoubleClicked);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
397
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
398 connect(new QShortcut(Qt::Key_Enter, this, nullptr, nullptr, Qt::WidgetShortcut),
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
399 &QShortcut::activated, this, &ItemDoubleClicked);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
400
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
401 header()->setStretchLastSection(false);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
402 header()->setContextMenuPolicy(Qt::CustomContextMenu);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
403 connect(header(), &QWidget::customContextMenuRequested, this, &DisplayColumnHeaderMenu);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
404 // if(!session.config.anime_list.columns) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
405 SetColumnDefaults();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
406 // }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
407 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
408
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
409 AnimeListPage::AnimeListPage(QWidget* parent) : QTabWidget (parent) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
410 setDocumentMode(true);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
411 SyncAnimeList();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
412 for (AnimeList& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
413 addTab(new AnimeListWidget(this, &list), QString::fromWCharArray(list.name.c_str()));
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
414 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
415 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
416
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
417 void AnimeListPage::SyncAnimeList() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
418 switch (session.config.service) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
419 case ANILIST: {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
420 AniList anilist = AniList();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
421 anilist.Authorize();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
422 session.config.anilist.user_id = anilist.GetUserId(session.config.anilist.username);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
423 FreeAnimeList();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
424 anilist.UpdateAnimeList(&anime_lists, session.config.anilist.user_id);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
425 break;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
426 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
427 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
428 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
429
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
430 void AnimeListPage::FreeAnimeList() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
431 if (anime_lists.size() > 0) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
432 /* FIXME: we may not need this, but to prevent memleaks
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
433 we should keep it until we're sure we don't */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
434 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
435 list.Clear();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
436 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
437 anime_lists.clear();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
438 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
439 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
440
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
441 int AnimeListPage::GetTotalAnimeAmount() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
442 int total = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
443 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
444 total += list.Size();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
445 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
446 return total;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
447 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
448
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
449 int AnimeListPage::GetTotalEpisodeAmount() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
450 /* FIXME: this also needs to take into account rewatches... */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
451 int total = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
452 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
453 for (auto& anime : list) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
454 total += anime.progress;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
455 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
456 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
457 return total;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
458 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
459
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
460 /* Returns the total watched amount in minutes. */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
461 int AnimeListPage::GetTotalWatchedAmount() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
462 int total = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
463 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
464 for (auto& anime : list) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
465 total += anime.duration*anime.progress;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
466 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
467 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
468 return total;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
469 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
470
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
471 /* Returns the total planned amount in minutes.
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
472 Note that we should probably limit progress to the
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
473 amount of episodes, as AniList will let you
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
474 set episode counts up to 32768. But that should
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
475 rather be handled elsewhere. */
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
476 int AnimeListPage::GetTotalPlannedAmount() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
477 int total = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
478 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
479 for (auto& anime : list) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
480 total += anime.duration*(anime.episodes-anime.progress);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
481 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
482 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
483 return total;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
484 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
485
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
486 double AnimeListPage::GetAverageScore() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
487 double avg = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
488 int amt = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
489 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
490 for (auto& anime : list) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
491 avg += anime.score;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
492 if (anime.score != 0)
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
493 amt++;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
494 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
495 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
496 return avg/amt;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
497 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
498
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
499 double AnimeListPage::GetScoreDeviation() {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
500 double squares_sum = 0, avg = GetAverageScore();
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
501 int amt = 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
502 for (auto& list : anime_lists) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
503 for (auto& anime : list) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
504 if (anime.score != 0) {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
505 squares_sum += std::pow((double)anime.score - avg, 2);
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
506 amt++;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
507 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
508 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
509 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
510 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
511 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
512
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
513 #include "moc_anime.cpp"