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:
Fabio Bas 2014-11-19 18:09:37 +01:00
parent cb37073828
commit 8542d875d3
4 changed files with 45 additions and 10 deletions

View file

@ -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);
}