mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
[TabDeckEditor] Create class to centralize deck state (#6459)
* create new file * use QSharedPointer in DeckListModel * [TabDeckEditor] Create class to centralize deck state * delete method * update docs
This commit is contained in:
parent
0085015ebe
commit
b2dd8eed3f
31 changed files with 933 additions and 577 deletions
|
|
@ -5,14 +5,15 @@
|
|||
DeckListModel::DeckListModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder)
|
||||
{
|
||||
// This class will leak the decklist object. We cannot safely delete it in the dtor because the deckList field is a
|
||||
// non-owning pointer and another deckList might have been assigned to it.
|
||||
// `DeckListModel::cleanList` also leaks for the same reason.
|
||||
// TODO: fix the leak
|
||||
deckList = new DeckList;
|
||||
deckList = QSharedPointer<DeckList>(new DeckList());
|
||||
root = new InnerDecklistNode;
|
||||
}
|
||||
|
||||
DeckListModel::DeckListModel(QObject *parent, const QSharedPointer<DeckList> &deckList) : DeckListModel(parent)
|
||||
{
|
||||
setDeckList(deckList);
|
||||
}
|
||||
|
||||
DeckListModel::~DeckListModel()
|
||||
{
|
||||
delete root;
|
||||
|
|
@ -586,13 +587,13 @@ void DeckListModel::setActiveFormat(const QString &_format)
|
|||
|
||||
void DeckListModel::cleanList()
|
||||
{
|
||||
setDeckList(new DeckList);
|
||||
setDeckList(QSharedPointer<DeckList>(new DeckList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _deck The deck.
|
||||
*/
|
||||
void DeckListModel::setDeckList(DeckList *_deck)
|
||||
void DeckListModel::setDeckList(const QSharedPointer<DeckList> &_deck)
|
||||
{
|
||||
if (deckList != _deck) {
|
||||
deckList = _deck;
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ signals:
|
|||
|
||||
public:
|
||||
explicit DeckListModel(QObject *parent = nullptr);
|
||||
explicit DeckListModel(QObject *parent, const QSharedPointer<DeckList> &deckList);
|
||||
~DeckListModel() override;
|
||||
|
||||
/**
|
||||
|
|
@ -314,11 +315,12 @@ public:
|
|||
* @brief Removes all cards and resets the model.
|
||||
*/
|
||||
void cleanList();
|
||||
[[nodiscard]] DeckList *getDeckList() const
|
||||
|
||||
[[nodiscard]] QSharedPointer<DeckList> getDeckList() const
|
||||
{
|
||||
return deckList;
|
||||
}
|
||||
void setDeckList(DeckList *_deck);
|
||||
void setDeckList(const QSharedPointer<DeckList> &_deck);
|
||||
|
||||
/**
|
||||
* @brief Apply a function to every card in the deck tree.
|
||||
|
|
@ -351,8 +353,8 @@ public:
|
|||
[[nodiscard]] QList<QString> getZones() const;
|
||||
|
||||
private:
|
||||
DeckList *deckList; /**< Pointer to the deck loader providing the underlying data. */
|
||||
InnerDecklistNode *root; /**< Root node of the model tree. */
|
||||
QSharedPointer<DeckList> deckList; /**< Pointer to the decklist providing the underlying data. */
|
||||
InnerDecklistNode *root; /**< Root node of the model tree. */
|
||||
DeckListModelGroupCriteria::Type activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE;
|
||||
int lastKnownColumn; /**< Last column used for sorting. */
|
||||
Qt::SortOrder lastKnownOrder; /**< Last known sort order. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue