Cockatrice 2026-10-19-Development-3.1.2-beta.2
A 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 <QAbstractItemModel>
13#include <QIcon>
14#include <QList>
15#include <QModelIndex>
16#include <QSet>
17#include <QString>
18#include <QTreeView>
19#include <libcockatrice/protocol/pb/serverinfo_replay.pb.h>
20#include <libcockatrice/protocol/pb/serverinfo_replay_match.pb.h>
21#include <qnamespace.h>
22#include <qtmetamacros.h>
23
24class Response;
25class AbstractClient;
26class QSortFilterProxyModel;
27class QObject;
28class QWidget;
29
30class RemoteReplayList_TreeModel : public QAbstractItemModel
31{
32 Q_OBJECT
33private:
34 class ReplayNode;
35
36 class Node
37 {
38 protected:
39 QString name;
40
41 public:
42 explicit Node(const QString &_name) : name(_name)
43 {
44 }
45 virtual ~Node() = default;
46 [[nodiscard]] QString getName() const
47 {
48 return name;
49 }
50 };
51 class MatchNode : public Node, public QList<ReplayNode *>
52 {
53 private:
55
56 public:
57 explicit MatchNode(const ServerInfo_ReplayMatch &_matchInfo);
58 ~MatchNode() override;
59 void clearTree();
61 {
62 return matchInfo;
63 }
64 void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo);
65 };
66 class ReplayNode : public Node
67 {
68 private:
71
72 public:
73 ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
74 : Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo)
75 {
76 }
78 {
79 return parent;
80 }
82 {
83 return replayInfo;
84 }
85 };
86
89
91 void clearAll();
92
93 static const int numberOfColumns;
94signals:
96private slots:
97 void replayListFinished(const Response &r);
98
99public:
100 explicit RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = nullptr);
102 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
103 [[nodiscard]] int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
104 {
105 return numberOfColumns;
106 }
107 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
108 [[nodiscard]] QVariant
109 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
110 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
111 [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
112 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
113 void clearTree();
114 void refreshTree();
115 [[nodiscard]] ServerInfo_Replay const *getReplay(const QModelIndex &index) const;
116 [[nodiscard]] ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const;
117 [[nodiscard]] ServerInfo_ReplayMatch const *getEnclosingReplayMatch(const QModelIndex &index) const;
118 void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
119 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
120 void removeMatchInfo(int gameId);
121};
122
123class RemoteReplayList_TreeWidget : public QTreeView
124{
125private:
127 QSortFilterProxyModel *proxyModel;
128
129public:
130 explicit RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr);
131 [[nodiscard]] ServerInfo_Replay const *getReplay(const QModelIndex &ind) const;
132 [[nodiscard]] ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const;
136 {
138 }
140 {
142 }
144 {
145 treeModel->addMatchInfo(matchInfo);
146 }
147 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
148 {
149 treeModel->updateMatchInfo(gameId, matchInfo);
150 }
151 void removeMatchInfo(int gameId)
152 {
153 treeModel->removeMatchInfo(gameId);
154 }
155};
156
157#endif
Definition abstract_client.h:73
Definition remote_connection_controller.h:20
Definition dlg_manage_sets.h:29
Definition remote_replay_list_tree_widget.h:52
MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
Definition remote_replay_list_tree_widget.cpp:27
const ServerInfo_ReplayMatch & getMatchInfo()
Definition remote_replay_list_tree_widget.h:60
ServerInfo_ReplayMatch matchInfo
Definition remote_replay_list_tree_widget.h:54
QString name
Definition remote_replay_list_tree_widget.h:39
Node(const QString &_name)
Definition remote_replay_list_tree_widget.h:42
QString getName() const
Definition remote_replay_list_tree_widget.h:46
Definition remote_replay_list_tree_widget.h:67
ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent)
Definition remote_replay_list_tree_widget.h:73
const ServerInfo_Replay & getReplayInfo()
Definition remote_replay_list_tree_widget.h:81
MatchNode * parent
Definition remote_replay_list_tree_widget.h:69
ServerInfo_Replay replayInfo
Definition remote_replay_list_tree_widget.h:70
MatchNode * getParent() const
Definition remote_replay_list_tree_widget.h:77
Definition remote_replay_list_tree_widget.h:31
void removeMatchInfo(int gameId)
Definition remote_replay_list_tree_widget.cpp:320
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition remote_replay_list_tree_widget.cpp:152
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition remote_replay_list_tree_widget.cpp:220
QVariant data(const QModelIndex &index, int role) const override
Definition remote_replay_list_tree_widget.cpp:75
static const int numberOfColumns
Definition remote_replay_list_tree_widget.h:93
void clearAll()
Definition remote_replay_list_tree_widget.cpp:276
int columnCount(const QModelIndex &=QModelIndex()) const override
Definition remote_replay_list_tree_widget.h:103
AbstractClient * client
Definition remote_replay_list_tree_widget.h:87
void refreshTree()
Definition remote_replay_list_tree_widget.cpp:284
ServerInfo_ReplayMatch const * getReplayMatch(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:242
ServerInfo_ReplayMatch const * getEnclosingReplayMatch(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:256
QIcon dirIcon
Definition remote_replay_list_tree_widget.h:90
ServerInfo_Replay const * getReplay(const QModelIndex &index) const
Definition remote_replay_list_tree_widget.cpp:229
QModelIndex parent(const QModelIndex &index) const override
Definition remote_replay_list_tree_widget.cpp:209
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition remote_replay_list_tree_widget.cpp:61
QList< MatchNode * > replayMatches
Definition remote_replay_list_tree_widget.h:88
RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent=nullptr)
Definition remote_replay_list_tree_widget.cpp:47
QIcon fileIcon
Definition remote_replay_list_tree_widget.h:90
void clearTree()
Definition remote_replay_list_tree_widget.cpp:292
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.cpp:299
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.cpp:308
QIcon lockIcon
Definition remote_replay_list_tree_widget.h:90
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition remote_replay_list_tree_widget.cpp:189
void replayListFinished(const Response &r)
Definition remote_replay_list_tree_widget.cpp:332
QSet< ServerInfo_ReplayMatch const * > getSelectedReplayMatches() const
Definition remote_replay_list_tree_widget.cpp:407
ServerInfo_ReplayMatch const * getReplayMatch(const QModelIndex &ind) const
Definition remote_replay_list_tree_widget.cpp:378
void removeMatchInfo(int gameId)
Definition remote_replay_list_tree_widget.h:151
RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent=nullptr)
Definition remote_replay_list_tree_widget.cpp:347
QList< ServerInfo_Replay const * > getSelectedReplays() const
Definition remote_replay_list_tree_widget.cpp:390
RemoteReplayList_TreeModel * treeModel
Definition remote_replay_list_tree_widget.h:126
void refreshTree()
Definition remote_replay_list_tree_widget.h:139
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.h:147
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
Definition remote_replay_list_tree_widget.h:143
void clearTree()
Definition remote_replay_list_tree_widget.h:135
QSortFilterProxyModel * proxyModel
Definition remote_replay_list_tree_widget.h:127
ServerInfo_Replay const * getReplay(const QModelIndex &ind) const
Definition remote_replay_list_tree_widget.cpp:369
Definition response.proto:11
Definition serverinfo_replay_match.proto:3
Definition serverinfo_replay.proto:2