comparison src/include/anime.h @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents 1d82f6e04d7d
children
comparison
equal deleted inserted replaced
6:1d82f6e04d7d 7:07a9095eaeed
1 #ifndef __anime_h 1 #ifndef __anime_h
2 #define __anime_h 2 #define __anime_h
3 #include <vector> 3 #include <vector>
4 #include <map> 4 #include <map>
5 #include <QStyledItemDelegate>
6 #include <QProgressBar>
7 #include "date.h" 5 #include "date.h"
8 #include "window.h" 6 #include "window.h"
9 #include "progress.h" 7 #include "progress.h"
10 8
11 enum AnimeWatchingStatus { 9 enum AnimeWatchingStatus {
64 struct { 62 struct {
65 std::string romaji; 63 std::string romaji;
66 std::string english; 64 std::string english;
67 std::string native; 65 std::string native;
68 } title; 66 } title;
67 std::vector<std::string> synonyms;
69 int episodes; 68 int episodes;
70 enum AnimeAiringStatus airing; 69 enum AnimeAiringStatus airing;
71 Date air_date; 70 Date air_date;
72 std::vector<std::string> genres; 71 std::vector<std::string> genres;
73 std::vector<std::string> producers; 72 std::vector<std::string> producers;
76 int audience_score; 75 int audience_score;
77 std::string synopsis; 76 std::string synopsis;
78 int duration; 77 int duration;
79 78
80 std::string GetUserPreferredTitle(); 79 std::string GetUserPreferredTitle();
80 std::vector<std::string> GetTitleSynonyms();
81 }; 81 };
82 82
83 /* This is a simple wrapper on a vector that provides 83 /* This is a simple wrapper on a vector that provides
84 methods to make it easier to search the list. */ 84 methods to make it easier to search the list. */
85 class AnimeList { 85 class AnimeList {
86 public: 86 public:
87 AnimeList(); 87 AnimeList();
88 AnimeList(const AnimeList& l); 88 AnimeList(const AnimeList& l);
89 AnimeList& operator=(const AnimeList& l);
89 ~AnimeList(); 90 ~AnimeList();
90 void Add(Anime& anime); 91 void Add(Anime& anime);
91 void Insert(size_t pos, Anime& anime); 92 void Insert(size_t pos, Anime& anime);
92 void Delete(size_t index); 93 void Delete(size_t index);
93 void Clear(); 94 void Clear();
106 protected: 107 protected:
107 std::vector<Anime> anime_list; 108 std::vector<Anime> anime_list;
108 std::map<int, Anime*> anime_id_to_anime; 109 std::map<int, Anime*> anime_id_to_anime;
109 }; 110 };
110 111
111 class AnimeListWidgetDelegate : public QStyledItemDelegate {
112 Q_OBJECT
113
114 public:
115 explicit AnimeListWidgetDelegate(QObject *parent);
116
117 QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
118 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
119
120 protected:
121 AnimeProgressBar progress_bar;
122 };
123
124 class AnimeListWidgetSortFilter : public QSortFilterProxyModel
125 {
126 Q_OBJECT
127
128 public:
129 AnimeListWidgetSortFilter(QObject *parent = nullptr);
130
131 protected:
132 bool lessThan(const QModelIndex &l, const QModelIndex &r) const override;
133 };
134
135 class AnimeListWidgetModel : public QAbstractListModel {
136 Q_OBJECT
137 public:
138 enum columns {
139 AL_TITLE,
140 AL_PROGRESS,
141 AL_EPISODES,
142 AL_SCORE,
143 AL_AVG_SCORE,
144 AL_TYPE,
145 AL_SEASON,
146 AL_STARTED,
147 AL_COMPLETED,
148 AL_UPDATED,
149 AL_NOTES,
150
151 NB_COLUMNS
152 };
153
154 AnimeListWidgetModel(QWidget* parent, AnimeList* alist);
155 ~AnimeListWidgetModel() override = default;
156 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
157 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
158 QVariant data(const QModelIndex& index, int role) const override;
159 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
160 Anime* GetAnimeFromIndex(const QModelIndex& index);
161 void UpdateAnime(Anime& anime);
162
163 private:
164 //void AddAnime(AnimeList& list);
165 AnimeList& list;
166 };
167
168 class AnimeListWidget : public QTreeView {
169 Q_OBJECT
170 public:
171 AnimeListWidget(QWidget* parent, AnimeList* alist);
172
173 private slots:
174 void DisplayColumnHeaderMenu();
175 void DisplayListMenu();
176 void ItemDoubleClicked();
177 void SetColumnDefaults();
178 int VisibleColumnsCount() const;
179
180 private:
181 AnimeListWidgetModel* model = nullptr;
182 AnimeListWidgetSortFilter* sort_model = nullptr;
183 };
184
185 class AnimeListPage : public QTabWidget {
186 public:
187 AnimeListPage(QWidget* parent = nullptr);
188 void SyncAnimeList();
189 void FreeAnimeList();
190 int GetTotalAnimeAmount();
191 int GetTotalEpisodeAmount();
192 int GetTotalWatchedAmount();
193 int GetTotalPlannedAmount();
194 double GetAverageScore();
195 double GetScoreDeviation();
196
197 private:
198 std::vector<AnimeList> anime_lists;
199 };
200
201 extern std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap; 112 extern std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap;
202 extern std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap; 113 extern std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap;
203 extern std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap; 114 extern std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap;
204 extern std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap; 115 extern std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap;
205 #endif // __anime_h 116 #endif // __anime_h