1 #ifndef REMOTEREPLAYLIST_TREEWIDGET_H 2 #define REMOTEREPLAYLIST_TREEWIDGET_H 3 4 #include "pb/serverinfo_replay.pb.h" 5 #include "pb/serverinfo_replay_match.pb.h" 6 7 #include <QAbstractItemModel> 8 #include <QDateTime> 9 #include <QTreeView> 10 11 class Response; 12 class AbstractClient; 13 class QSortFilterProxyModel; 14 15 class RemoteReplayList_TreeModel : public QAbstractItemModel 16 { 17 Q_OBJECT 18 private: 19 class MatchNode; 20 class ReplayNode; 21 class Node 22 { 23 protected: 24 QString name; 25 26 public: Node(const QString & _name)27 Node(const QString &_name) : name(_name) 28 { 29 } ~Node()30 virtual ~Node(){}; getName()31 QString getName() const 32 { 33 return name; 34 } 35 }; 36 class MatchNode : public Node, public QList<ReplayNode *> 37 { 38 private: 39 ServerInfo_ReplayMatch matchInfo; 40 41 public: 42 MatchNode(const ServerInfo_ReplayMatch &_matchInfo); 43 ~MatchNode(); 44 void clearTree(); getMatchInfo()45 const ServerInfo_ReplayMatch &getMatchInfo() 46 { 47 return matchInfo; 48 } 49 void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo); 50 }; 51 class ReplayNode : public Node 52 { 53 private: 54 MatchNode *parent; 55 ServerInfo_Replay replayInfo; 56 57 public: ReplayNode(const ServerInfo_Replay & _replayInfo,MatchNode * _parent)58 ReplayNode(const ServerInfo_Replay &_replayInfo, MatchNode *_parent) 59 : Node(QString::fromStdString(_replayInfo.replay_name())), parent(_parent), replayInfo(_replayInfo) 60 { 61 } getParent()62 MatchNode *getParent() const 63 { 64 return parent; 65 } getReplayInfo()66 const ServerInfo_Replay &getReplayInfo() 67 { 68 return replayInfo; 69 } 70 }; 71 72 AbstractClient *client; 73 QList<MatchNode *> replayMatches; 74 75 QIcon dirIcon, fileIcon, lockIcon; 76 void clearTree(); 77 78 static const int numberOfColumns; 79 signals: 80 void treeRefreshed(); 81 private slots: 82 void replayListFinished(const Response &r); 83 84 public: 85 RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = nullptr); 86 ~RemoteReplayList_TreeModel(); 87 int rowCount(const QModelIndex &parent = QModelIndex()) const; 88 int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const 89 { 90 return numberOfColumns; 91 } 92 QVariant data(const QModelIndex &index, int role) const; 93 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 94 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 95 QModelIndex parent(const QModelIndex &index) const; 96 Qt::ItemFlags flags(const QModelIndex &index) const; 97 void refreshTree(); 98 ServerInfo_Replay const *getReplay(const QModelIndex &index) const; 99 ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const; 100 void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo); 101 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo); 102 void removeMatchInfo(int gameId); 103 }; 104 105 class RemoteReplayList_TreeWidget : public QTreeView 106 { 107 private: 108 RemoteReplayList_TreeModel *treeModel; 109 QSortFilterProxyModel *proxyModel; 110 ServerInfo_Replay const *getNode(const QModelIndex &ind) const; 111 112 public: 113 RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr); 114 ServerInfo_Replay const *getCurrentReplay() const; 115 ServerInfo_ReplayMatch const *getCurrentReplayMatch() const; 116 void refreshTree(); addMatchInfo(const ServerInfo_ReplayMatch & matchInfo)117 void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) 118 { 119 treeModel->addMatchInfo(matchInfo); 120 } updateMatchInfo(int gameId,const ServerInfo_ReplayMatch & matchInfo)121 void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo) 122 { 123 treeModel->updateMatchInfo(gameId, matchInfo); 124 } removeMatchInfo(int gameId)125 void removeMatchInfo(int gameId) 126 { 127 treeModel->removeMatchInfo(gameId); 128 } 129 }; 130 131 #endif 132