Sets dialog: new columns and sorting
Added "order key", "set type" and "release date" columns Use a proxy model to sort the table made the dialog wider accordingly
This commit is contained in:
parent
cb37073828
commit
8542d875d3
4 changed files with 45 additions and 10 deletions
|
@ -20,13 +20,16 @@ int SetsModel::rowCount(const QModelIndex &parent) const
|
|||
|
||||
QVariant SetsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || (index.column() >= 2) || (index.row() >= rowCount()) || (role != Qt::DisplayRole))
|
||||
if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount()) || (role != Qt::DisplayRole))
|
||||
return QVariant();
|
||||
|
||||
CardSet *set = sets[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0: return set->getShortName();
|
||||
case 1: return set->getLongName();
|
||||
case SortKeyCol: return set->getSortKey();
|
||||
case SetTypeCol: return set->getSetType();
|
||||
case ShortNameCol: return set->getShortName();
|
||||
case LongNameCol: return set->getLongName();
|
||||
case ReleaseDateCol: return set->getReleaseDate();
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +39,11 @@ QVariant SetsModel::headerData(int section, Qt::Orientation orientation, int rol
|
|||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0: return tr("Short name");
|
||||
case 1: return tr("Long name");
|
||||
case SortKeyCol: return tr("Key");
|
||||
case SetTypeCol: return tr("Set type");
|
||||
case ShortNameCol: return tr("Short name");
|
||||
case LongNameCol: return tr("Long name");
|
||||
case ReleaseDateCol: return tr("Release date");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
@ -91,3 +97,10 @@ QStringList SetsModel::mimeTypes() const
|
|||
{
|
||||
return QStringList() << "application/x-cockatricecardset";
|
||||
}
|
||||
|
||||
SetsProxyModel::SetsProxyModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define SETSMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QMimeData>
|
||||
#include "carddatabase.h"
|
||||
|
||||
|
@ -17,11 +18,16 @@ public:
|
|||
|
||||
class SetsModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
private:
|
||||
static const int NUM_COLS = 5;
|
||||
SetList sets;
|
||||
public:
|
||||
enum SetsColumns { SortKeyCol, SetTypeCol, ShortNameCol, LongNameCol, ReleaseDateCol };
|
||||
|
||||
SetsModel(CardDatabase *_db, QObject *parent = 0);
|
||||
~SetsModel();
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &/*parent*/) const { return 2; }
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const { return NUM_COLS; }
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
@ -30,8 +36,11 @@ public:
|
|||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
QStringList mimeTypes() const;
|
||||
private:
|
||||
SetList sets;
|
||||
};
|
||||
|
||||
class SetsProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SetsProxyModel(QObject *parent = 0);
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -3,21 +3,32 @@
|
|||
#include "main.h"
|
||||
#include <QTreeView>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
|
||||
WndSets::WndSets(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
model = new SetsModel(db, this);
|
||||
proxyModel = new SetsProxyModel(this);
|
||||
proxyModel->setSourceModel(model);
|
||||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
view = new QTreeView;
|
||||
view->setModel(model);
|
||||
view->setModel(proxyModel);
|
||||
view->setAlternatingRowColors(true);
|
||||
view->setUniformRowHeights(true);
|
||||
view->setAllColumnsShowFocus(true);
|
||||
view->setSortingEnabled(true);
|
||||
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||
|
||||
view->setDragEnabled(true);
|
||||
view->setAcceptDrops(true);
|
||||
view->setDropIndicatorShown(true);
|
||||
view->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
#if QT_VERSION < 0x050000
|
||||
view->header()->setResizeMode(SetsModel::LongNameCol, QHeaderView::ResizeToContents);
|
||||
#else
|
||||
view->header()->setSectionResizeMode(SetsModel::LongNameCol, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(view);
|
||||
|
@ -27,7 +38,7 @@ WndSets::WndSets(QWidget *parent)
|
|||
setCentralWidget(centralWidget);
|
||||
|
||||
setWindowTitle(tr("Edit sets"));
|
||||
resize(400, 400);
|
||||
resize(700, 400);
|
||||
}
|
||||
|
||||
WndSets::~WndSets()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QMainWindow>
|
||||
|
||||
class SetsModel;
|
||||
class SetsProxyModel;
|
||||
class QTreeView;
|
||||
class CardDatabase;
|
||||
|
||||
|
@ -11,6 +12,7 @@ class WndSets : public QMainWindow {
|
|||
Q_OBJECT
|
||||
private:
|
||||
SetsModel *model;
|
||||
SetsProxyModel *proxyModel;
|
||||
QTreeView *view;
|
||||
public:
|
||||
WndSets(QWidget *parent = 0);
|
||||
|
|
Loading…
Reference in a new issue