annotate include/gui/pages/anime_list.h @ 307:8769c5d50b06

pages/anime_list: don't call GUI functions in a non-GUI thread
author Paper <paper@paper.us.eu.org>
date Sun, 19 May 2024 18:25:14 -0400
parents 9a88e1725fd2
children 1b5c04268d6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
1 #ifndef MINORI_GUI_PAGES_ANIME_LIST_H_
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
2 #define MINORI_GUI_PAGES_ANIME_LIST_H_
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
3
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 #include "core/anime.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5 #include <QAbstractListModel>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 #include <QSortFilterProxyModel>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 #include <QStyledItemDelegate>
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
8 #include <QWidget>
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
9 #include <QThread>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 #include <vector>
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
11 #include <queue>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
12
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
13 class QTreeView;
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
14 class QTabBar;
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
15 class AnimeListPage;
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
16
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
17 class AnimeListPageUpdateEntryThread final : public QThread {
307
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
18 Q_OBJECT
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
19
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
20 public:
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
21 AnimeListPageUpdateEntryThread(AnimeListPage* parent);
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
22
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
23 void AddToQueue(int id);
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
24
307
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
25 signals:
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
26 void NeedRefresh();
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
27
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
28 protected:
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
29 void run() override;
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
30
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
31 private:
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
32 AnimeListPage* page_ = nullptr;
274
f6a756c19bfb anime_list.cc: use mutexes so we don't sex the stack
Paper <paper@paper.us.eu.org>
parents: 273
diff changeset
33 std::mutex _queue_mutex;
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
34 std::queue<int> queue_;
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
35 };
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
36
95
8043152ef9d4 include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
37 class AnimeListPageSortFilter final : public QSortFilterProxyModel {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
38 Q_OBJECT
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
40 public:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
41 AnimeListPageSortFilter(QObject* parent = nullptr);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
43 protected:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
44 bool lessThan(const QModelIndex& l, const QModelIndex& r) const override;
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45 };
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
46
95
8043152ef9d4 include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
47 class AnimeListPageModel final : public QAbstractListModel {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
48 Q_OBJECT
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
50 public:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
51 enum columns {
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
52 AL_TITLE,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
53 AL_PROGRESS,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
54 AL_EPISODES,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
55 AL_SCORE,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
56 AL_AVG_SCORE,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
57 AL_TYPE,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
58 AL_SEASON,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
59 AL_STARTED,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
60 AL_COMPLETED,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
61 AL_UPDATED,
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
62 AL_NOTES,
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
64 NB_COLUMNS
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
65 };
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
66
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
67 AnimeListPageModel(QObject* parent, Anime::ListStatus _status);
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
68 ~AnimeListPageModel() override = default;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
69 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
70 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
71 QVariant data(const QModelIndex& index, int role) const override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
72 QVariant headerData(const int section, const Qt::Orientation orientation, const int role) const override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
73 void RefreshList();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
74 Anime::Anime* GetAnimeFromIndex(QModelIndex index);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
75
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
76 private:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
77 Anime::ListStatus status;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
78 std::vector<Anime::Anime> list;
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 };
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
80
95
8043152ef9d4 include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents: 85
diff changeset
81 class AnimeListPage final : public QWidget {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
82 Q_OBJECT
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
83
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
84 public:
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 274
diff changeset
85 AnimeListPage(QWidget* parent = nullptr);
307
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
86
8769c5d50b06 pages/anime_list: don't call GUI functions in a non-GUI thread
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
87 public slots:
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
88 void Refresh();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
89
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
90 protected:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
91 void paintEvent(QPaintEvent*) override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
92 void InitStyle(QStyleOptionTabWidgetFrame* option) const;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
93 void InitBasicStyle(QStyleOptionTabWidgetFrame* option) const;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
94 void SetupLayout();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
95 void showEvent(QShowEvent*) override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
96 void resizeEvent(QResizeEvent* e) override;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
97 void RefreshList();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
98 void RefreshTabs();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
99 void UpdateAnime(int id);
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
100 void RemoveAnime(int id);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
101
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
102 private slots:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
103 void DisplayColumnHeaderMenu();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
104 void DisplayListMenu();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
105 void ItemDoubleClicked();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
106 void SetColumnDefaults();
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
107 int VisibleColumnsCount() const;
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
109 private:
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
110 QTabBar* tab_bar;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
111 QTreeView* tree_view;
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
112 QRect panelRect;
273
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
113
f31305b9f60a *: various code safety changes
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
114 AnimeListPageUpdateEntryThread update_entry_thread_;
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 114
diff changeset
115 std::array<AnimeListPageSortFilter*, 5> sort_models;
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
116 };
85
c69230dc2b5d *: cleanup includes
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
117
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
118 #endif // MINORI_GUI_PAGES_ANIME_LIST_H_