mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-10 04:16:43 -07:00
use QSharedPointer in DeckListModel
This commit is contained in:
parent
d4bbb6f881
commit
8cc7a61000
2 changed files with 14 additions and 11 deletions
|
|
@ -5,14 +5,15 @@
|
||||||
DeckListModel::DeckListModel(QObject *parent)
|
DeckListModel::DeckListModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder)
|
: 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
|
deckList = QSharedPointer<DeckList>(new DeckList());
|
||||||
// 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;
|
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeckListModel::DeckListModel(QObject *parent, const QSharedPointer<DeckList> &deckList) : DeckListModel(parent)
|
||||||
|
{
|
||||||
|
setDeckList(deckList);
|
||||||
|
}
|
||||||
|
|
||||||
DeckListModel::~DeckListModel()
|
DeckListModel::~DeckListModel()
|
||||||
{
|
{
|
||||||
delete root;
|
delete root;
|
||||||
|
|
@ -580,13 +581,13 @@ void DeckListModel::setActiveFormat(const QString &_format)
|
||||||
|
|
||||||
void DeckListModel::cleanList()
|
void DeckListModel::cleanList()
|
||||||
{
|
{
|
||||||
setDeckList(new DeckList);
|
setDeckList(QSharedPointer<DeckList>(new DeckList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param _deck The deck.
|
* @param _deck The deck.
|
||||||
*/
|
*/
|
||||||
void DeckListModel::setDeckList(DeckList *_deck)
|
void DeckListModel::setDeckList(const QSharedPointer<DeckList> &_deck)
|
||||||
{
|
{
|
||||||
if (deckList != _deck) {
|
if (deckList != _deck) {
|
||||||
deckList = _deck;
|
deckList = _deck;
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ signals:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeckListModel(QObject *parent = nullptr);
|
explicit DeckListModel(QObject *parent = nullptr);
|
||||||
|
explicit DeckListModel(QObject *parent, const QSharedPointer<DeckList> &deckList);
|
||||||
~DeckListModel() override;
|
~DeckListModel() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -323,11 +324,12 @@ public:
|
||||||
* @brief Removes all cards and resets the model.
|
* @brief Removes all cards and resets the model.
|
||||||
*/
|
*/
|
||||||
void cleanList();
|
void cleanList();
|
||||||
[[nodiscard]] DeckList *getDeckList() const
|
|
||||||
|
[[nodiscard]] QSharedPointer<DeckList> getDeckList() const
|
||||||
{
|
{
|
||||||
return deckList;
|
return deckList;
|
||||||
}
|
}
|
||||||
void setDeckList(DeckList *_deck);
|
void setDeckList(const QSharedPointer<DeckList> &_deck);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Apply a function to every card in the deck tree.
|
* @brief Apply a function to every card in the deck tree.
|
||||||
|
|
@ -370,8 +372,8 @@ public:
|
||||||
void setActiveGroupCriteria(DeckListModelGroupCriteria::Type newCriteria);
|
void setActiveGroupCriteria(DeckListModelGroupCriteria::Type newCriteria);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeckList *deckList; /**< Pointer to the deck loader providing the underlying data. */
|
QSharedPointer<DeckList> deckList; /**< Pointer to the decklist providing the underlying data. */
|
||||||
InnerDecklistNode *root; /**< Root node of the model tree. */
|
InnerDecklistNode *root; /**< Root node of the model tree. */
|
||||||
DeckListModelGroupCriteria::Type activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE;
|
DeckListModelGroupCriteria::Type activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE;
|
||||||
int lastKnownColumn; /**< Last column used for sorting. */
|
int lastKnownColumn; /**< Last column used for sorting. */
|
||||||
Qt::SortOrder lastKnownOrder; /**< Last known sort order. */
|
Qt::SortOrder lastKnownOrder; /**< Last known sort order. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue