mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-05 20:39:59 -08:00
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/**
|
|
* @file card_database_model.h
|
|
* @ingroup CardDatabaseModels
|
|
* @brief The CardDatabaseModel maps the cardList contained in the CardDatabase as a QAbstractListModel.
|
|
*/
|
|
|
|
#ifndef CARDDATABASEMODEL_H
|
|
#define CARDDATABASEMODEL_H
|
|
|
|
#include <QAbstractListModel>
|
|
#include <QList>
|
|
#include <QSet>
|
|
#include <libcockatrice/card/database/card_database.h>
|
|
|
|
class CardDatabaseModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
enum Columns
|
|
{
|
|
NameColumn,
|
|
SetListColumn,
|
|
ManaCostColumn,
|
|
PTColumn,
|
|
CardTypeColumn,
|
|
ColorColumn
|
|
};
|
|
enum Role
|
|
{
|
|
SortRole = Qt::UserRole
|
|
};
|
|
CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromEnabledSets, QObject *parent = nullptr);
|
|
~CardDatabaseModel() override;
|
|
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
[[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
|
|
[[nodiscard]] QVariant
|
|
headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
[[nodiscard]] CardDatabase *getDatabase() const
|
|
{
|
|
return db;
|
|
}
|
|
[[nodiscard]] CardInfoPtr getCard(int index) const
|
|
{
|
|
return cardList[index];
|
|
}
|
|
|
|
private:
|
|
QList<CardInfoPtr> cardList;
|
|
QSet<CardInfoPtr> cardListSet; // Supports faster lookups in cardDatabaseEnabledSetsChanged()
|
|
CardDatabase *db;
|
|
bool showOnlyCardsFromEnabledSets;
|
|
|
|
inline bool checkCardHasAtLeastOneEnabledSet(CardInfoPtr card);
|
|
private slots:
|
|
void cardAdded(CardInfoPtr card);
|
|
void cardRemoved(CardInfoPtr card);
|
|
void cardInfoChanged(CardInfoPtr card);
|
|
void cardDatabaseEnabledSetsChanged();
|
|
};
|
|
|
|
#endif
|