sort edit sets better (#2648)

This commit is contained in:
ctrlaltca 2017-04-25 17:40:47 +02:00 committed by Zach H
parent 160d66d890
commit 3c54499a40
2 changed files with 16 additions and 4 deletions

View file

@ -30,10 +30,21 @@ QVariant SetsModel::data(const QModelIndex &index, int role) const
CardSet *set = sets[index.row()];
if ( role == Qt::CheckStateRole && index.column() == EnabledCol )
return static_cast< int >( enabledSets.contains(set) ? Qt::Checked : Qt::Unchecked );
if (index.column() == EnabledCol)
{
switch(role)
{
case SortRole:
return enabledSets.contains(set) ? "1" : "0";
case Qt::CheckStateRole:
return static_cast< int >( enabledSets.contains(set) ? Qt::Checked : Qt::Unchecked );
case Qt::DisplayRole:
default:
return QVariant();
}
}
if (role != Qt::DisplayRole)
if (role != Qt::DisplayRole && role != SortRole)
return QVariant();
switch (index.column()) {
@ -178,7 +189,7 @@ void SetsModel::sort(int column, Qt::SortOrder order)
int row;
for(row = 0; row < numRows; ++row)
setMap.insertMulti(index(row, column).data().toString(), sets.at(row));
setMap.insertMulti(index(row, column).data(SetsModel::SortRole).toString(), sets.at(row));
QList<CardSet *> tmp = setMap.values();
sets.clear();

View file

@ -27,6 +27,7 @@ private:
QSet<CardSet *> enabledSets;
public:
enum SetsColumns { SortKeyCol, IsKnownCol, EnabledCol, LongNameCol, ShortNameCol, SetTypeCol, ReleaseDateCol };
enum Role { SortRole=Qt::UserRole };
SetsModel(CardDatabase *_db, QObject *parent = 0);
~SetsModel();