sort edit sets better (#2648)
This commit is contained in:
parent
160d66d890
commit
3c54499a40
2 changed files with 16 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue