GH-3490 sort instances by name is now aware of numbers

This commit is contained in:
Petr Mrázek 2021-10-25 21:43:00 +02:00
parent 040af58070
commit 85ecbad467
2 changed files with 8 additions and 1 deletions

View File

@ -5,6 +5,10 @@
InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent) InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent)
{ {
m_naturalSort.setNumericMode(true);
m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes
m_naturalSort.setLocale(QLocale::system());
} }
QVariant InstanceProxyModel::data(const QModelIndex & index, int role) const QVariant InstanceProxyModel::data(const QModelIndex & index, int role) const
@ -29,6 +33,6 @@ bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
} }
else else
{ {
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; return m_naturalSort.compare(pdataLeft->name(), pdataRight->name()) < 0;
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "groupview/GroupedProxyModel.h" #include "groupview/GroupedProxyModel.h"
#include <QCollator>
/** /**
* A proxy model that is responsible for sorting instances into groups * A proxy model that is responsible for sorting instances into groups
@ -13,4 +14,6 @@ public:
protected: protected:
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override; virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
QCollator m_naturalSort;
}; };