annotate src/include/anime_list.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
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #ifndef __anime_list_h
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #define __anime_list_h
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include <vector>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #include <QStyledItemDelegate>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <QSortFilterProxyModel>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <QAbstractListModel>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include <QTreeView>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <QWidget>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include "anime.h"
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include "progress.h"
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 class AnimeListWidgetDelegate : public QStyledItemDelegate {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 public:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 explicit AnimeListWidgetDelegate(QObject *parent);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 protected:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 AnimeProgressBar progress_bar;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 };
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 class AnimeListWidgetSortFilter : public QSortFilterProxyModel
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 public:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 AnimeListWidgetSortFilter(QObject *parent = nullptr);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 protected:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 bool lessThan(const QModelIndex &l, const QModelIndex &r) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 };
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 class AnimeListWidgetModel : public QAbstractListModel {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 public:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 enum columns {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 AL_TITLE,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 AL_PROGRESS,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 AL_EPISODES,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 AL_SCORE,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 AL_AVG_SCORE,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 AL_TYPE,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 AL_SEASON,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 AL_STARTED,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 AL_COMPLETED,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 AL_UPDATED,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 AL_NOTES,
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 NB_COLUMNS
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 };
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 AnimeListWidgetModel(QWidget* parent, AnimeList* alist);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 ~AnimeListWidgetModel() override = default;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 QVariant data(const QModelIndex& index, int role) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 Anime* GetAnimeFromIndex(const QModelIndex& index);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 void UpdateAnime(Anime& anime);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 void Update(const AnimeList& new_list);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 private:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 //void AddAnime(AnimeList& list);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 AnimeList& list;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 };
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 /* todo: rename these to "page" or something more
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 sensible than "widget" */
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73 class AnimeListWidget : public QWidget {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 Q_OBJECT
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 public:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 AnimeListWidget(QWidget* parent);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 void SyncAnimeList();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
79 void FreeAnimeList();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80 int GetTotalAnimeAmount();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 int GetTotalEpisodeAmount();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82 int GetTotalWatchedAmount();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 int GetTotalPlannedAmount();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 double GetAverageScore();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85 double GetScoreDeviation();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 protected:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 void paintEvent(QPaintEvent*) override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 void InitStyle(QStyleOptionTabWidgetFrame *option) const;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 void InitBasicStyle(QStyleOptionTabWidgetFrame *option) const;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 void SetupLayout();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 void showEvent(QShowEvent*) override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 void resizeEvent(QResizeEvent* e) override;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 private slots:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 void DisplayColumnHeaderMenu();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 void DisplayListMenu();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 void ItemDoubleClicked();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99 void SetColumnDefaults();
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 int VisibleColumnsCount() const;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 private:
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 QTabBar* tab_bar;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 QTreeView* tree_view;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 QRect panelRect;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106 std::vector<AnimeListWidgetSortFilter*> sort_models;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 std::vector<AnimeList> anime_lists;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 };
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109 #endif // __anime_list_h