Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
remote_replay_list_tree_widget.h
Go to the documentation of this file.
1
8
9#ifndef REMOTEREPLAYLIST_TREEWIDGET_H
10#define REMOTEREPLAYLIST_TREEWIDGET_H
11
12#include <QDateTime>
13#include <QTreeView>
14#include <libcockatrice/protocol/pb/serverinfo_replay.pb.h>
15#include <libcockatrice/protocol/pb/serverinfo_replay_match.pb.h>
16
17class Response;
18class AbstractClient;
19class QSortFilterProxyModel;
20
21class RemoteReplayList_TreeModel : public QAbstractItemModel
22{
23 Q_OBJECT
24private:
25 class MatchNode;
26 class ReplayNode;
27 class Node
28 {
29 protected:
30 QString name;
31
32 public:
33 explicit Node(const QString &_name) : name(_name)
34 {
35 }
36 virtual ~Node() = default;
37 [[nodiscard]] QString getName() const
38 {
39 return name;
40 }
41 };
42 class MatchNode : public Node, public QList<ReplayNode *>
43 {
44 private:
45 ServerInfo_ReplayMatch matchInfo;
46
47 public:
48 explicit MatchNode(const ServerInfo_ReplayMatch &_matchInfo);
49 ~MatchNode() override;
50 void clearTree();
51 const ServerInfo_ReplayMatch &getMatchInfo()
52 {
53 return matchInfo;
54 }
55 void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo);
56 };
57 class ReplayNode : public Node
58 {
59 private:
61 ServerInfo_Replay replayInfo;
62
63 public:
64 ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
65 : Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo)
66 {
67 }
69 {
70 return parent;
71 }
72 const ServerInfo_Replay &getReplayInfo()
73 {
74 return replayInfo;
75 }
76 };
77
79 QList<MatchNode *> replayMatches;
80
82 void clearAll();
83
84 static const int numberOfColumns;
85signals:
87private slots:
88 void replayListFinished(const Response &r);
89
90public:
91 explicit RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = nullptr);
93 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
94 [[nodiscard]] int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
95 {
96 return numberOfColumns;
97 }
98 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
99 [[nodiscard]] QVariant
100 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
101 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
102 [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
103 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
104 void clearTree();
105 void refreshTree();
106 [[nodiscard]] ServerInfo_Replay const *getReplay(const QModelIndex &index) const;
107 [[nodiscard]] ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const;
108 [[nodiscard]] ServerInfo_ReplayMatch const *getEnclosingReplayMatch(const QModelIndex &index) const;
109 void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
110 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
111 void removeMatchInfo(int gameId);
112};
113
114class RemoteReplayList_TreeWidget : public QTreeView
115{
116private:
118 QSortFilterProxyModel *proxyModel;
119
120public:
121 explicit RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr);
122 [[nodiscard]] ServerInfo_Replay const *getReplay(const QModelIndex &ind) const;
123 [[nodiscard]] ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const;
124 [[nodiscard]] QList<ServerInfo_Replay const *> getSelectedReplays() const;
125 [[nodiscard]] QSet<ServerInfo_ReplayMatch const *> getSelectedReplayMatches() const;
127 {
128 treeModel->clearTree();
129 }
131 {
132 treeModel->refreshTree();
133 }
134 void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
135 {
136 treeModel->addMatchInfo(matchInfo);
137 }
138 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
139 {
140 treeModel->updateMatchInfo(gameId, matchInfo);
141 }
142 void removeMatchInfo(int gameId)
143 {
144 treeModel->removeMatchInfo(gameId);
145 }
146};
147
148#endif
Definition abstract_client.h:51
Definition remote_replay_list_tree_widget.h:43
MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
Definition remote_replay_list_tree_widget.cpp:14
~MatchNode() override
Definition remote_replay_list_tree_widget.cpp:21
void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo)
Definition remote_replay_list_tree_widget.cpp:27
const ServerInfo_ReplayMatch & getMatchInfo()
Definition remote_replay_list_tree_widget.h:51
ServerInfo_ReplayMatch matchInfo
Definition remote_replay_list_tree_widget.h:45
QString name
Definition remote_replay_list_tree_widget.h:30
Node(const QString &_name)
Definition remote_replay_list_tree_widget.h:33
QString getName() const
Definition remote_replay_list_tree_widget.h:37
Definition remote_replay_list_tree_widget.h:58
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
Definition remote_replay_list_tree_widget.h:64
const ServerInfo_Replay & getReplayInfo()
Definition remote_replay_list_tree_widget.h:72
MatchNode * parent
Definition remote_replay_list_tree_widget.h:60
ServerInfo_Replay replayInfo
Definition remote_replay_list_tree_widget.h:61
MatchNode * getParent() const
Definition remote_replay_list_tree_widget.h:68
Definition remote_replay_list_tree_widget.h:22
void removeMatchInfo(int gameId)
Definition remote_replay_list_tree_widget.cpp:287
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition remote_replay_list_tree_widget.cpp:132
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition remote_replay_list_tree_widget.cpp:196
QVariant data(const QModelIndex &index, int role) const override
Definition remote_replay_list_tree_widget.cpp:58
static const int numberOfColumns
Definition remote_replay_list_tree_widget.h:84
void clearAll()
Definition remote_replay_list_tree_widget.cpp:245
int columnCount(const QModelIndex &=QModelIndex()) const override
Definition remote_replay_list_tree_widget.h:94
~RemoteReplayList_TreeModel() override
Definition remote_replay_list_tree_widget.cpp:41
AbstractClient * client
Definition remote_replay_list_tree_widget.h:78
void refreshTree()
Definition remote_replay_list_tree_widget.cpp:252
ServerInfo_ReplayMatch const * getReplayMatch(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:215
ServerInfo_ReplayMatch const * getEnclosingReplayMatch(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:227
QIcon dirIcon
Definition remote_replay_list_tree_widget.h:81
ServerInfo_Replay const * getReplay(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:204
QModelIndex parent(const QModelIndex &index) const override
Definition remote_replay_list_tree_widget.cpp:185
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition remote_replay_list_tree_widget.cpp:46
QList< MatchNode * > replayMatches
Definition remote_replay_list_tree_widget.h:79
RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent=nullptr)
Definition remote_replay_list_tree_widget.cpp:32
QIcon fileIcon
Definition remote_replay_list_tree_widget.h:81
void clearTree()
Definition remote_replay_list_tree_widget.cpp:260
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.cpp:267
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.cpp:276
QIcon lockIcon
Definition remote_replay_list_tree_widget.h:81
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition remote_replay_list_tree_widget.cpp:168
void replayListFinished(const Response &r)
Definition remote_replay_list_tree_widget.cpp:298
QSet< ServerInfo_ReplayMatch const * > getSelectedReplayMatches() const
Definition remote_replay_list_tree_widget.cpp:372
ServerInfo_ReplayMatch const * getReplayMatch(const QModelIndex &ind) const
Definition remote_replay_list_tree_widget.cpp:343
void removeMatchInfo(int gameId)
Definition remote_replay_list_tree_widget.h:142
RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent=nullptr)
Definition remote_replay_list_tree_widget.cpp:312
QList< ServerInfo_Replay const * > getSelectedReplays() const
Definition remote_replay_list_tree_widget.cpp:355
RemoteReplayList_TreeModel * treeModel
Definition remote_replay_list_tree_widget.h:117
void refreshTree()
Definition remote_replay_list_tree_widget.h:130
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.h:138
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.h:134
void clearTree()
Definition remote_replay_list_tree_widget.h:126
QSortFilterProxyModel * proxyModel
Definition remote_replay_list_tree_widget.h:118
ServerInfo_Replay const * getReplay(const QModelIndex &ind) const
Definition remote_replay_list_tree_widget.cpp:334