Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2022-08-14 00:19:05 +0300
committerJonathan White <support@dmapps.us>2022-09-11 15:31:04 +0300
commit4bc805d59a54cbf688e48e36ae04e26a391f162d (patch)
tree27d7352306449a300b35a37706a1fa0bcadf5a76
parentfa75833b013384a931e7a11f324eef4120c72f3f (diff)
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.
-rw-r--r--src/gui/SortFilterHideProxyModel.cpp14
-rw-r--r--src/gui/SortFilterHideProxyModel.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/SortFilterHideProxyModel.cpp b/src/gui/SortFilterHideProxyModel.cpp
index 0193d9594..20a1dfacc 100644
--- a/src/gui/SortFilterHideProxyModel.cpp
+++ b/src/gui/SortFilterHideProxyModel.cpp
@@ -16,6 +16,7 @@
*/
#include "SortFilterHideProxyModel.h"
+#include <QCollator>
SortFilterHideProxyModel::SortFilterHideProxyModel(QObject* parent)
: QSortFilterProxyModel(parent)
@@ -41,3 +42,16 @@ bool SortFilterHideProxyModel::filterAcceptsColumn(int sourceColumn, const QMode
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);
+}
diff --git a/src/gui/SortFilterHideProxyModel.h b/src/gui/SortFilterHideProxyModel.h
index 58d9ff703..746ccbd96 100644
--- a/src/gui/SortFilterHideProxyModel.h
+++ b/src/gui/SortFilterHideProxyModel.h
@@ -32,6 +32,7 @@ public:
protected:
bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override;
+ bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
private:
QBitArray m_hiddenColumns;