mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
Support numeric aware sorting on Windows and macOS
* Fix #8356 - Qt does not enable numeric aware sorting when using locale sort. Extracted both Windows and macOS locale aware sorting code and added the appropriate numeric aware flag. Note: There is no std library way to do this so Linux is out of luck for now.
This commit is contained in:
parent
b0a68ea0de
commit
4c1e5ec74c
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SortFilterHideProxyModel.h"
|
#include "SortFilterHideProxyModel.h"
|
||||||
|
#include <QCollator>
|
||||||
|
|
||||||
SortFilterHideProxyModel::SortFilterHideProxyModel(QObject* parent)
|
SortFilterHideProxyModel::SortFilterHideProxyModel(QObject* parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
@ -41,3 +42,16 @@ bool SortFilterHideProxyModel::filterAcceptsColumn(int sourceColumn, const QMode
|
|||||||
|
|
||||||
return sourceColumn >= m_hiddenColumns.size() || !m_hiddenColumns.at(sourceColumn);
|
return sourceColumn >= m_hiddenColumns.size() || !m_hiddenColumns.at(sourceColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SortFilterHideProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||||
|
{
|
||||||
|
auto leftData = sourceModel()->data(left, sortRole());
|
||||||
|
auto rightData = sourceModel()->data(right, sortRole());
|
||||||
|
if (leftData.type() == QVariant::String) {
|
||||||
|
QCollator sorter;
|
||||||
|
sorter.setNumericMode(true);
|
||||||
|
return sorter.compare(leftData.toString(), rightData.toString()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QSortFilterProxyModel::lessThan(left, right);
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override;
|
bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override;
|
||||||
|
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QBitArray m_hiddenColumns;
|
QBitArray m_hiddenColumns;
|
||||||
|
Loading…
Reference in New Issue
Block a user