From c97e6aa43e0cb9b26be95e14e1eaf46a577f817e Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 24 Jan 2025 20:23:57 -0800 Subject: [PATCH] add method for clearing remote replays model --- .../remote/remote_replay_list_tree_widget.cpp | 16 +++++++++++++--- .../remote/remote_replay_list_tree_widget.h | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cockatrice/src/server/remote/remote_replay_list_tree_widget.cpp b/cockatrice/src/server/remote/remote_replay_list_tree_widget.cpp index 3f58d898a..e75df12b2 100644 --- a/cockatrice/src/server/remote/remote_replay_list_tree_widget.cpp +++ b/cockatrice/src/server/remote/remote_replay_list_tree_widget.cpp @@ -43,7 +43,7 @@ RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client, RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel() { - clearTree(); + clearAll(); } int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const @@ -242,7 +242,10 @@ ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getEnclosingReplayMatc return &node->getMatchInfo(); } -void RemoteReplayList_TreeModel::clearTree() +/** + * Deletes all items in the model + */ +void RemoteReplayList_TreeModel::clearAll() { for (int i = 0; i < replayMatches.size(); ++i) delete replayMatches[i]; @@ -258,6 +261,13 @@ void RemoteReplayList_TreeModel::refreshTree() client->sendCommand(pend); } +void RemoteReplayList_TreeModel::clearTree() +{ + beginResetModel(); + clearAll(); + endResetModel(); +} + void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) { beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size()); @@ -294,7 +304,7 @@ void RemoteReplayList_TreeModel::replayListFinished(const Response &r) const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext); beginResetModel(); - clearTree(); + clearAll(); for (int i = 0; i < resp.match_list_size(); ++i) replayMatches.append(new MatchNode(resp.match_list(i))); diff --git a/cockatrice/src/server/remote/remote_replay_list_tree_widget.h b/cockatrice/src/server/remote/remote_replay_list_tree_widget.h index f64d87857..ff5a5f303 100644 --- a/cockatrice/src/server/remote/remote_replay_list_tree_widget.h +++ b/cockatrice/src/server/remote/remote_replay_list_tree_widget.h @@ -73,7 +73,7 @@ private: QList replayMatches; QIcon dirIcon, fileIcon, lockIcon; - void clearTree(); + void clearAll(); static const int numberOfColumns; signals: @@ -94,6 +94,7 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const; + void clearTree(); void refreshTree(); ServerInfo_Replay const *getReplay(const QModelIndex &index) const; ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const; @@ -115,6 +116,10 @@ public: ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const; QList getSelectedReplays() const; QSet getSelectedReplayMatches() const; + void clearTree() + { + treeModel->clearTree(); + } void refreshTree() { treeModel->refreshTree();