Support downloading replay folders (#5325)

* rename old get replay match method to get enclosing

* creat raw getReplayMatch method

* implement thing
This commit is contained in:
RickyRister 2024-12-25 04:33:36 -08:00 committed by GitHub
parent 9d7fd66546
commit ed907d7c6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 18 deletions

View file

@ -216,6 +216,18 @@ ServerInfo_Replay const *RemoteReplayList_TreeModel::getReplay(const QModelIndex
}
ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getReplayMatch(const QModelIndex &index) const
{
if (!index.isValid())
return nullptr;
auto *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
if (!node)
return nullptr;
return &node->getMatchInfo();
}
ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getEnclosingReplayMatch(const QModelIndex &index) const
{
if (!index.isValid())
return nullptr;
@ -318,6 +330,15 @@ ServerInfo_Replay const *RemoteReplayList_TreeWidget::getReplay(const QModelInde
return treeModel->getReplay(proxyModel->mapToSource(ind));
}
/**
* Gets the replay match at the given index
* @return The replay match. Returns nullptr if there is no replay match at the index.
*/
ServerInfo_ReplayMatch const *RemoteReplayList_TreeWidget::getReplayMatch(const QModelIndex &ind) const
{
return treeModel->getReplayMatch(proxyModel->mapToSource(ind));
}
/**
* Gets all currently selected replays.
* Any selection that isn't a replay file (e.g. a folder) will appear as a nullptr in the list.
@ -338,6 +359,7 @@ QList<ServerInfo_Replay const *> RemoteReplayList_TreeWidget::getSelectedReplays
/**
* Gets all currently selected replayMatches.
* If a non-folder node is selected, it will return the parent folder of that node.
*
* @return A Set of pointers to the selected replayMatches.
*/
@ -346,7 +368,7 @@ QSet<ServerInfo_ReplayMatch const *> RemoteReplayList_TreeWidget::getSelectedRep
const auto selection = selectionModel()->selectedRows();
auto replayMatches = QSet<ServerInfo_ReplayMatch const *>();
for (const auto &row : selection) {
if (const auto replayMatch = treeModel->getReplayMatch(proxyModel->mapToSource(row))) {
if (const auto replayMatch = treeModel->getEnclosingReplayMatch(proxyModel->mapToSource(row))) {
replayMatches << replayMatch;
}
}

View file

@ -97,6 +97,7 @@ public:
void refreshTree();
ServerInfo_Replay const *getReplay(const QModelIndex &index) const;
ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const;
ServerInfo_ReplayMatch const *getEnclosingReplayMatch(const QModelIndex &index) const;
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
void removeMatchInfo(int gameId);
@ -111,6 +112,7 @@ private:
public:
RemoteReplayList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr);
ServerInfo_Replay const *getReplay(const QModelIndex &ind) const;
ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const;
QList<ServerInfo_Replay const *> getSelectedReplays() const;
QSet<ServerInfo_ReplayMatch const *> getSelectedReplayMatches() const;
void refreshTree();