1 #ifndef SETSMODEL_H 2 #define SETSMODEL_H 3 4 #include "carddatabase.h" 5 6 #include <QAbstractTableModel> 7 #include <QMimeData> 8 #include <QSet> 9 #include <QSortFilterProxyModel> 10 11 class SetsProxyModel; 12 13 class SetsMimeData : public QMimeData 14 { 15 Q_OBJECT 16 private: 17 int oldRow; 18 19 public: SetsMimeData(int _oldRow)20 SetsMimeData(int _oldRow) : oldRow(_oldRow) 21 { 22 } getOldRow()23 int getOldRow() const 24 { 25 return oldRow; 26 } formats()27 QStringList formats() const 28 { 29 return QStringList() << "application/x-cockatricecardset"; 30 } 31 }; 32 33 class SetsModel : public QAbstractTableModel 34 { 35 Q_OBJECT 36 friend class SetsProxyModel; 37 38 private: 39 static const int NUM_COLS = 7; 40 SetList sets; 41 QSet<CardSetPtr> enabledSets; 42 43 public: 44 enum SetsColumns 45 { 46 SortKeyCol, 47 IsKnownCol, 48 EnabledCol, 49 LongNameCol, 50 ShortNameCol, 51 SetTypeCol, 52 ReleaseDateCol 53 }; 54 enum Role 55 { 56 SortRole = Qt::UserRole 57 }; 58 59 SetsModel(CardDatabase *_db, QObject *parent = nullptr); 60 ~SetsModel(); 61 int rowCount(const QModelIndex &parent = QModelIndex()) const; 62 int columnCount(const QModelIndex &parent = QModelIndex()) const 63 { 64 Q_UNUSED(parent); 65 return NUM_COLS; 66 } 67 QVariant data(const QModelIndex &index, int role) const; 68 bool setData(const QModelIndex &index, const QVariant &value, int role); 69 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 70 Qt::ItemFlags flags(const QModelIndex &index) const; 71 Qt::DropActions supportedDropActions() const; 72 73 QMimeData *mimeData(const QModelIndexList &indexes) const; 74 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); 75 QStringList mimeTypes() const; 76 void swapRows(int oldRow, int newRow); 77 void toggleRow(int row, bool enable); 78 void toggleRow(int row); 79 void toggleAll(bool); 80 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); 81 void save(CardDatabase *db); 82 void restore(CardDatabase *db); 83 }; 84 85 class SetsDisplayModel : public QSortFilterProxyModel 86 { 87 Q_OBJECT 88 public: 89 SetsDisplayModel(QObject *parent = NULL); 90 91 protected: 92 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 93 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 94 void fetchMore(const QModelIndex &index) override; 95 }; 96 97 #endif 98