deckModel now takes ownership of DeckLoader

This commit is contained in:
RickyRister 2025-02-27 00:27:53 -08:00
parent 97663c4fde
commit 6271c941af
3 changed files with 14 additions and 2 deletions

View file

@ -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);

View file

@ -289,6 +289,10 @@ void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */)
QPair<QString, QString>(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);

View file

@ -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();