mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Proper sorting of columns with enum values
This commit is contained in:
parent
3c3bd7976e
commit
a7b3248ee7
2 changed files with 21 additions and 0 deletions
|
@ -60,6 +60,20 @@ void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::
|
|||
|
||||
bool CSMWorld::IdTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
{
|
||||
Columns::ColumnId id = static_cast<Columns::ColumnId>(left.data(ColumnBase::Role_ColumnId).toInt());
|
||||
EnumColumnCache::const_iterator valuesIt = mEnumColumnCache.find(id);
|
||||
if (valuesIt == mEnumColumnCache.end())
|
||||
{
|
||||
if (Columns::hasEnums(id))
|
||||
{
|
||||
valuesIt = mEnumColumnCache.insert(std::make_pair(id, Columns::getEnums(id))).first;
|
||||
}
|
||||
}
|
||||
|
||||
if (valuesIt != mEnumColumnCache.end())
|
||||
{
|
||||
return valuesIt->second[left.data().toInt()] < valuesIt->second[right.data().toInt()];
|
||||
}
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "../filter/node.hpp"
|
||||
|
||||
#include "columns.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTableProxyModel : public QSortFilterProxyModel
|
||||
|
@ -20,6 +22,11 @@ namespace CSMWorld
|
|||
boost::shared_ptr<CSMFilter::Node> mFilter;
|
||||
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
|
||||
|
||||
// Cache of enum values for enum columns (e.g. Modified, Record Type).
|
||||
// Used to speed up comparisons during the sort by such columns.
|
||||
typedef std::map<Columns::ColumnId, std::vector<std::string> > EnumColumnCache;
|
||||
mutable EnumColumnCache mEnumColumnCache;
|
||||
|
||||
private:
|
||||
|
||||
void updateColumnMap();
|
||||
|
|
Loading…
Reference in a new issue