From 6271c941afc8f2dfc05843f1865842f5ea1ecf46 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Thu, 27 Feb 2025 00:27:53 -0800 Subject: [PATCH] deckModel now takes ownership of DeckLoader --- cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp | 4 ++++ .../widgets/deck_editor/deck_editor_deck_dock_widget.cpp | 4 ++++ cockatrice/src/deck/deck_list_model.cpp | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp b/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp index 94a5139fb..0efb0d10b 100644 --- a/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/abstract_tab_deck_editor.cpp @@ -128,6 +128,10 @@ void AbstractTabDeckEditor::actSwapCard(CardInfoPtr info, QString zoneName) deckDockWidget->deckModel->findCard(info->getName(), zoneName, providerId, collectorNumber)); } +/** + * Sets the currently active deck for this tab + * @param _deck The deck. Takes ownership of the object + */ void AbstractTabDeckEditor::setDeck(DeckLoader *_deck) { deckDockWidget->setDeck(_deck); diff --git a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp index 6f3c9e513..c975aa0f8 100644 --- a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp +++ b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp @@ -289,6 +289,10 @@ void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */) QPair(itemData["name"].toString(), itemData["uuid"].toString())); } +/** + * Sets the currently active deck for this tab + * @param _deck The deck. Takes ownership of the object + */ void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck) { deckModel->setDeckList(_deck); diff --git a/cockatrice/src/deck/deck_list_model.cpp b/cockatrice/src/deck/deck_list_model.cpp index e66633764..cd3c9bcf1 100644 --- a/cockatrice/src/deck/deck_list_model.cpp +++ b/cockatrice/src/deck/deck_list_model.cpp @@ -18,6 +18,7 @@ DeckListModel::DeckListModel(QObject *parent) : QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder) { deckList = new DeckLoader; + deckList->setParent(this); connect(deckList, &DeckLoader::deckLoaded, this, &DeckListModel::rebuildTree); connect(deckList, &DeckLoader::deckHashChanged, this, &DeckListModel::deckHashChanged); root = new InnerDecklistNode; @@ -26,7 +27,6 @@ DeckListModel::DeckListModel(QObject *parent) DeckListModel::~DeckListModel() { delete root; - delete deckList; } void DeckListModel::rebuildTree() @@ -470,10 +470,14 @@ void DeckListModel::cleanList() setDeckList(new DeckLoader); } +/** + * @param _deck The deck. Takes ownership of the object + */ void DeckListModel::setDeckList(DeckLoader *_deck) { - delete deckList; + deckList->deleteLater(); deckList = _deck; + deckList->setParent(this); connect(deckList, &DeckLoader::deckLoaded, this, &DeckListModel::rebuildTree); connect(deckList, &DeckLoader::deckHashChanged, this, &DeckListModel::deckHashChanged); rebuildTree();