annotate src/anime.cpp @ 6:1d82f6e04d7d

Update: add first parts to the settings dialog
author Paper <mrpapersonic@gmail.com>
date Wed, 16 Aug 2023 00:49:17 -0400
parents 190ded9438c0
children 07a9095eaeed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
1 #include <chrono>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #include <string>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #include <vector>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 #include <cmath>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 #include "window.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
6 #include "anilist.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7 #include "config.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
8 #include "anime.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #include "date.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 #include "time_utils.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 #include "information.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 #include "ui_utils.h"
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
13 #include <iostream>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap = {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 {CURRENT, "Watching"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 {PLANNING, "Planning"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 {COMPLETED, "Completed"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 {DROPPED, "Dropped"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 {PAUSED, "On hold"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 {REPEATING, "Rewatching"}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap = {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 {FINISHED, "Finished"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 {RELEASING, "Airing"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27 {NOT_YET_RELEASED, "Not aired yet"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 {CANCELLED, "Cancelled"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 {HIATUS, "On hiatus"}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap = {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 {UNKNOWN, "Unknown"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 {WINTER, "Winter"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 {SPRING, "Spring"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 {SUMMER, "Summer"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 {FALL, "Fall"}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap = {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 {TV, "TV"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 {TV_SHORT, "TV short"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43 {MOVIE, "Movie"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 {SPECIAL, "Special"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45 {OVA, "OVA"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 {ONA, "ONA"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 {MUSIC, "Music video"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48 /* these should NEVER be in the list. naybe we should
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 remove them? */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 {MANGA, "Manga"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51 {NOVEL, "Novel"},
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 {ONE_SHOT, "One-shot"}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53 };
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 Anime::Anime() {}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56 Anime::Anime(const Anime& a) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
57 status = a.status;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
58 progress = a.progress;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
59 score = a.score;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
60 started = a.started;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
61 completed = a.completed;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
62 updated = a.updated;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
63 notes = a.notes;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
64 id = a.id;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
65 title = a.title;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
66 episodes = a.episodes;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
67 airing = a.airing;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 air_date = a.air_date;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69 genres = a.genres;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
70 producers = a.producers;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
71 type = a.type;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
72 season = a.season;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
73 audience_score = a.audience_score;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
74 synopsis = a.synopsis;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
75 duration = a.duration;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
76 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
77
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
78 std::string Anime::GetUserPreferredTitle() {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
79 if (title.english.empty())
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
80 return title.romaji;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
81 return title.english;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
82 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
83
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 void AnimeList::Add(Anime& anime) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
85 if (anime_id_to_anime.contains(anime.id))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
86 return;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 anime_list.push_back(anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
88 anime_id_to_anime.emplace(anime.id, &anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
89 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
90
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
91 void AnimeList::Insert(size_t pos, Anime& anime) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 if (anime_id_to_anime.contains(anime.id))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
93 return;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
94 anime_list.insert(anime_list.begin()+pos, anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 anime_id_to_anime.emplace(anime.id, &anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
96 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
97
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
98 void AnimeList::Delete(size_t index) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
99 anime_list.erase(anime_list.begin()+index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
100 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
101
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
102 void AnimeList::Clear() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
103 anime_list.clear();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
104 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
105
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
106 size_t AnimeList::Size() const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
107 return anime_list.size();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
108 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
109
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
110 std::vector<Anime>::iterator AnimeList::begin() noexcept {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
111 return anime_list.begin();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
112 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
113
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
114 std::vector<Anime>::iterator AnimeList::end() noexcept {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
115 return anime_list.end();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
116 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
117
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
118 std::vector<Anime>::const_iterator AnimeList::cbegin() noexcept {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
119 return anime_list.cbegin();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
120 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
121
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
122 std::vector<Anime>::const_iterator AnimeList::cend() noexcept {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
123 return anime_list.cend();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
124 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
125
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
126 AnimeList::AnimeList() {}
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
127 AnimeList::AnimeList(const AnimeList& l) {
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
128 for (unsigned long long i = 0; i < l.Size(); i++) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
129 anime_list.push_back(Anime(l[i]));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
130 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
131 name = l.name;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
132 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
133
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
134 AnimeList::~AnimeList() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
135 anime_list.clear();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
136 anime_list.shrink_to_fit();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
137 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
138
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
139 Anime* AnimeList::AnimeById(int id) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
140 return anime_id_to_anime.contains(id) ? anime_id_to_anime[id] : nullptr;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
141 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
142
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
143 bool AnimeList::AnimeInList(int id) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
144 return anime_id_to_anime.contains(id);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
145 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
146
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
147 int AnimeList::GetAnimeIndex(Anime& anime) const {
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
148 for (unsigned long long i = 0; i < Size(); i++) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
149 if (&anime_list.at(i) == &anime) { // lazy
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
150 return i;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
151 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
152 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
153 return -1;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
154 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
155
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
156 Anime& AnimeList::operator[](std::size_t index) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
157 return anime_list.at(index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
158 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
159
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
160 const Anime& AnimeList::operator[](std::size_t index) const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
161 return anime_list.at(index);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
162 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
163
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
164 /* ------------------------------------------------------------------------- */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
165
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
166 AnimeListWidgetDelegate::AnimeListWidgetDelegate(QObject* parent)
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
167 : QStyledItemDelegate (parent) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
168 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
169
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
170 QWidget *AnimeListWidgetDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
171 {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
172 // LOL
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
173 return nullptr;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
174 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
175
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
176 void AnimeListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
177 {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
178 switch (index.column()) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
179 case AnimeListWidgetModel::AL_PROGRESS: {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
180 const int progress = static_cast<int>(index.data(Qt::UserRole).toReal());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
181 const int episodes = static_cast<int>(index.siblingAtColumn(AnimeListWidgetModel::AL_EPISODES).data(Qt::UserRole).toReal());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
182
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
183 QStyleOptionViewItem customOption (option);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
184 customOption.state.setFlag(QStyle::State_Enabled, true);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
185
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
186 progress_bar.paint(painter, customOption, index.data().toString(), progress, episodes);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
187 break;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
188 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
189 default:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
190 QStyledItemDelegate::paint(painter, option, index);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
191 break;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
192 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
193 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
194
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
195 AnimeListWidgetSortFilter::AnimeListWidgetSortFilter(QObject *parent)
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
196 : QSortFilterProxyModel(parent) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
197 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
198
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
199 bool AnimeListWidgetSortFilter::lessThan(const QModelIndex &l,
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
200 const QModelIndex &r) const {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
201 QVariant left = sourceModel()->data(l, sortRole());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
202 QVariant right = sourceModel()->data(r, sortRole());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
203
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
204 switch (left.userType()) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
205 case QMetaType::Int:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
206 case QMetaType::UInt:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
207 case QMetaType::LongLong:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
208 case QMetaType::ULongLong:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
209 return left.toInt() < right.toInt();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
210 case QMetaType::QDate:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
211 return left.toDate() < right.toDate();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
212 case QMetaType::QString:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
213 default:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
214 return left.toString() < right.toString();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
215 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
216 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
217
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
218 /* Thank you qBittorrent for having a great example of a
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
219 widget model. */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
220 AnimeListWidgetModel::AnimeListWidgetModel (QWidget* parent, AnimeList* alist)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
221 : QAbstractListModel(parent)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
222 , list(*alist) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
223 return;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
224 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
225
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
226 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
227 return list.Size();
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
228 (void)(parent);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
229 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
230
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
231 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
232 return NB_COLUMNS;
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
233 (void)(parent);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
234 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
235
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
236 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
237 if (role == Qt::DisplayRole) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
238 switch (section) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
239 case AL_TITLE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
240 return tr("Anime title");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
241 case AL_PROGRESS:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
242 return tr("Progress");
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
243 case AL_EPISODES:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
244 return tr("Episodes");
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
245 case AL_TYPE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
246 return tr("Type");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
247 case AL_SCORE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
248 return tr("Score");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
249 case AL_SEASON:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
250 return tr("Season");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
251 case AL_STARTED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
252 return tr("Date started");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
253 case AL_COMPLETED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
254 return tr("Date completed");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
255 case AL_NOTES:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
256 return tr("Notes");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
257 case AL_AVG_SCORE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
258 return tr("Average score");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
259 case AL_UPDATED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
260 return tr("Last updated");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
261 default:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
262 return {};
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
263 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
264 } else if (role == Qt::TextAlignmentRole) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
265 switch (section) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
266 case AL_TITLE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
267 case AL_NOTES:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
268 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
269 case AL_PROGRESS:
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
270 case AL_EPISODES:
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
271 case AL_TYPE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
272 case AL_SCORE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
273 case AL_AVG_SCORE:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
274 return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
275 case AL_SEASON:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
276 case AL_STARTED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
277 case AL_COMPLETED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
278 case AL_UPDATED:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
279 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
280 default:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
281 return QAbstractListModel::headerData(section, orientation, role);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
282 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
283 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
284 return QAbstractListModel::headerData(section, orientation, role);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
285 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
286
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
287 Anime* AnimeListWidgetModel::GetAnimeFromIndex(const QModelIndex& index) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
288 return (index.isValid()) ? &(list[index.row()]) : nullptr;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
289 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
290
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
291 QVariant AnimeListWidgetModel::data(const QModelIndex& index, int role) const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
292 if (!index.isValid())
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
293 return QVariant();
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
294 switch (role) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
295 case Qt::DisplayRole:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
296 switch (index.column()) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
297 case AL_TITLE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
298 return QString::fromUtf8(list[index.row()].GetUserPreferredTitle().c_str());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
299 case AL_PROGRESS:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
300 return QString::number(list[index.row()].progress) + "/" + QString::number(list[index.row()].episodes);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
301 case AL_EPISODES:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
302 return list[index.row()].episodes;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
303 case AL_SCORE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
304 return list[index.row()].score;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
305 case AL_TYPE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
306 return QString::fromStdString(AnimeFormatToStringMap[list[index.row()].type]);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
307 case AL_SEASON:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
308 return QString::fromStdString(AnimeSeasonToStringMap[list[index.row()].season]) + " " + QString::number(list[index.row()].air_date.GetYear());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
309 case AL_AVG_SCORE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
310 return QString::number(list[index.row()].audience_score) + "%";
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
311 case AL_STARTED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
312 return list[index.row()].started.GetAsQDate();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
313 case AL_COMPLETED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
314 return list[index.row()].completed.GetAsQDate();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
315 case AL_UPDATED: {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
316 if (list[index.row()].updated == 0)
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
317 return QString("-");
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
318 Time::Duration duration(Time::GetSystemTime() - list[index.row()].updated);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
319 return QString::fromUtf8(duration.AsRelativeString().c_str());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
320 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
321 case AL_NOTES:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
322 return QString::fromUtf8(list[index.row()].notes.c_str());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
323 default:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
324 return "";
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
325 }
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
326 break;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
327 case Qt::UserRole:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
328 switch (index.column()) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
329 case AL_PROGRESS:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
330 return list[index.row()].progress;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
331 case AL_TYPE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
332 return list[index.row()].type;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
333 case AL_SEASON:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
334 return list[index.row()].air_date.GetAsQDate();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
335 case AL_AVG_SCORE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
336 return list[index.row()].audience_score;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
337 case AL_UPDATED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
338 return list[index.row()].updated;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
339 default:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
340 return data(index, Qt::DisplayRole);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
341 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
342 break;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
343 case Qt::TextAlignmentRole:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
344 switch (index.column()) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
345 case AL_TITLE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
346 case AL_NOTES:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
347 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
348 case AL_PROGRESS:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
349 case AL_EPISODES:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
350 case AL_TYPE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
351 case AL_SCORE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
352 case AL_AVG_SCORE:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
353 return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
354 case AL_SEASON:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
355 case AL_STARTED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
356 case AL_COMPLETED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
357 case AL_UPDATED:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
358 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
359 default:
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
360 break;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
361 }
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
362 break;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
363 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
364 return QVariant();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
365 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
366
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
367 void AnimeListWidgetModel::UpdateAnime(Anime& anime) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
368 int i = list.GetAnimeIndex(anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
369 emit dataChanged(index(i), index(i));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
370 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
371
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
372 int AnimeListWidget::VisibleColumnsCount() const {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
373 int count = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
374
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
375 for (int i = 0, end = header()->count(); i < end; i++)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
376 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
377 if (!isColumnHidden(i))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
378 count++;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
379 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
380
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
381 return count;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
382 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
383
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
384 void AnimeListWidget::SetColumnDefaults() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
385 setColumnHidden(AnimeListWidgetModel::AL_SEASON, false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
386 setColumnHidden(AnimeListWidgetModel::AL_TYPE, false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
387 setColumnHidden(AnimeListWidgetModel::AL_UPDATED, false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
388 setColumnHidden(AnimeListWidgetModel::AL_PROGRESS, false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
389 setColumnHidden(AnimeListWidgetModel::AL_SCORE, false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
390 setColumnHidden(AnimeListWidgetModel::AL_TITLE, false);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
391 setColumnHidden(AnimeListWidgetModel::AL_EPISODES, true);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
392 setColumnHidden(AnimeListWidgetModel::AL_AVG_SCORE, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
393 setColumnHidden(AnimeListWidgetModel::AL_STARTED, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
394 setColumnHidden(AnimeListWidgetModel::AL_COMPLETED, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
395 setColumnHidden(AnimeListWidgetModel::AL_UPDATED, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
396 setColumnHidden(AnimeListWidgetModel::AL_NOTES, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
397 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
398
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
399 void AnimeListWidget::DisplayColumnHeaderMenu() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
400 QMenu *menu = new QMenu(this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
401 menu->setAttribute(Qt::WA_DeleteOnClose);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
402 menu->setTitle(tr("Column visibility"));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
403 menu->setToolTipsVisible(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
404
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
405 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
406 if (i == AnimeListWidgetModel::AL_TITLE)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
407 continue;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
408 const auto column_name = model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
409 QAction *action = menu->addAction(column_name, this, [this, i](const bool checked) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
410 if (!checked && (VisibleColumnsCount() <= 1))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
411 return;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
412
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
413 setColumnHidden(i, !checked);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
414
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
415 if (checked && (columnWidth(i) <= 5))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
416 resizeColumnToContents(i);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
417
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
418 // SaveSettings();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
419 });
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
420 action->setCheckable(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
421 action->setChecked(!isColumnHidden(i));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
422 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
423
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
424 menu->addSeparator();
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
425 QAction *resetAction = menu->addAction(tr("Reset to defaults"), this, [this]() {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
426 for (int i = 0, count = header()->count(); i < count; ++i)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
427 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
428 SetColumnDefaults();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
429 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
430 // SaveSettings();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
431 });
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
432 menu->popup(QCursor::pos());
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
433 (void)(resetAction);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
434 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
435
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
436 void AnimeListWidget::DisplayListMenu() {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
437 QMenu *menu = new QMenu(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
438 menu->setAttribute(Qt::WA_DeleteOnClose);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
439 menu->setTitle(tr("Column visibility"));
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
440 menu->setToolTipsVisible(true);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
441
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
442 const QItemSelection selection = sort_model->mapSelectionToSource(selectionModel()->selection());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
443 if (!selection.indexes().first().isValid()) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
444 return;
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
445 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
446
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
447 QAction* action = menu->addAction("Information", [this, selection]{
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
448 const QModelIndex index = model->index(selection.indexes().first().row());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
449 Anime* anime = model->GetAnimeFromIndex(index);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
450 if (!anime) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
451 return;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
452 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
453
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
454 InformationDialog* dialog = new InformationDialog(*anime, model, this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
455
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
456 dialog->show();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
457 dialog->raise();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
458 dialog->activateWindow();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
459 });
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
460 menu->popup(QCursor::pos());
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
461 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
462
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
463 void AnimeListWidget::ItemDoubleClicked() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
464 /* throw out any other garbage */
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
465 const QItemSelection selection = sort_model->mapSelectionToSource(selectionModel()->selection());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
466 if (!selection.indexes().first().isValid()) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
467 return;
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
468 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
469
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
470 const QModelIndex index = model->index(selection.indexes().first().row());
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
471 const QString title = index.siblingAtColumn(AnimeListWidgetModel::AL_TITLE).data(Qt::UserRole).toString();
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
472 QMessageBox box;
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
473 box.setText(QString::number(title.size()));
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
474 box.exec();
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
475 Anime* anime = model->GetAnimeFromIndex(index);
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
476 if (!anime) {
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
477 return;
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
478 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
479
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
480 InformationDialog* dialog = new InformationDialog(*anime, model, this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
481
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
482 dialog->show();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
483 dialog->raise();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
484 dialog->activateWindow();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
485 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
486
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
487 AnimeListWidget::AnimeListWidget(QWidget* parent, AnimeList* alist)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
488 : QTreeView(parent) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
489 setItemDelegate(new AnimeListWidgetDelegate(this));
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
490 model = new AnimeListWidgetModel(parent, alist);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
491 sort_model = new AnimeListWidgetSortFilter(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
492 sort_model->setSourceModel(model);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
493 sort_model->setSortRole(Qt::UserRole);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
494 setModel(sort_model);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
495 setObjectName("listwidget");
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
496 setStyleSheet("QTreeView#listwidget{border:0px;}");
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
497 setUniformRowHeights(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
498 setAllColumnsShowFocus(false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
499 setSortingEnabled(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
500 setSelectionMode(QAbstractItemView::ExtendedSelection);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
501 setItemsExpandable(false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
502 setRootIsDecorated(false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
503 setContextMenuPolicy(Qt::CustomContextMenu);
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
504 connect(this, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked);
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
505 connect(this, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
506
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
507 /* Enter & return keys */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
508 connect(new QShortcut(Qt::Key_Return, this, nullptr, nullptr, Qt::WidgetShortcut),
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
509 &QShortcut::activated, this, &AnimeListWidget::ItemDoubleClicked);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
510
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
511 connect(new QShortcut(Qt::Key_Enter, this, nullptr, nullptr, Qt::WidgetShortcut),
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
512 &QShortcut::activated, this, &AnimeListWidget::ItemDoubleClicked);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
513
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
514 header()->setStretchLastSection(false);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
515 header()->setContextMenuPolicy(Qt::CustomContextMenu);
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
516 connect(header(), &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayColumnHeaderMenu);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
517 // if(!session.config.anime_list.columns) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
518 SetColumnDefaults();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
519 // }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
520 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
521
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
522 AnimeListPage::AnimeListPage(QWidget* parent) : QTabWidget (parent) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
523 setDocumentMode(false);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
524 setObjectName("animepage");
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
525 //setStyleSheet("QTabWidget#animepage{border-bottom:0px;border-left:0px;border-right:0px;}");
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
526 SyncAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
527 for (AnimeList& list : anime_lists) {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
528 addTab(new AnimeListWidget(this, &list), QString::fromUtf8(list.name.c_str()));
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
529 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
530 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
531
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
532 void AnimeListPage::SyncAnimeList() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
533 switch (session.config.service) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
534 case ANILIST: {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
535 AniList anilist = AniList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
536 session.config.anilist.user_id = anilist.GetUserId(session.config.anilist.username);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
537 FreeAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
538 anilist.UpdateAnimeList(&anime_lists, session.config.anilist.user_id);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
539 break;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
540 }
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
541 default:
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
542 break;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
543 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
544 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
545
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
546 void AnimeListPage::FreeAnimeList() {
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
547 for (auto& list : anime_lists) {
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
548 list.Clear();
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
549 }
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
550 anime_lists.clear();
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
551 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
552
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
553 int AnimeListPage::GetTotalAnimeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
554 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
555 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
556 total += list.Size();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
557 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
558 return total;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
559 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
560
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
561 int AnimeListPage::GetTotalEpisodeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
562 /* FIXME: this also needs to take into account rewatches... */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
563 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
564 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
565 for (auto& anime : list) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
566 total += anime.progress;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
567 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
568 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
569 return total;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
570 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
571
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
572 /* Returns the total watched amount in minutes. */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
573 int AnimeListPage::GetTotalWatchedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
574 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
575 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
576 for (auto& anime : list) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
577 total += anime.duration*anime.progress;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
578 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
579 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
580 return total;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
581 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
582
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
583 /* Returns the total planned amount in minutes.
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
584 Note that we should probably limit progress to the
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
585 amount of episodes, as AniList will let you
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
586 set episode counts up to 32768. But that should
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
587 rather be handled elsewhere. */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
588 int AnimeListPage::GetTotalPlannedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
589 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
590 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
591 for (auto& anime : list) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
592 total += anime.duration*(anime.episodes-anime.progress);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
593 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
594 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
595 return total;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
596 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
597
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
598 double AnimeListPage::GetAverageScore() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
599 double avg = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
600 int amt = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
601 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
602 for (auto& anime : list) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
603 avg += anime.score;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
604 if (anime.score != 0)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
605 amt++;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
606 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
607 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
608 return avg/amt;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
609 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
610
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
611 double AnimeListPage::GetScoreDeviation() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
612 double squares_sum = 0, avg = GetAverageScore();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
613 int amt = 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
614 for (auto& list : anime_lists) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
615 for (auto& anime : list) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
616 if (anime.score != 0) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
617 squares_sum += std::pow((double)anime.score - avg, 2);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
618 amt++;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
619 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
620 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
621 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
622 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
623 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
624
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
625 #include "moc_anime.cpp"