Fix some lexical sorting of names with numbers

This commit is contained in:
GriffinR
2025-01-30 11:53:00 -05:00
parent 09694891f3
commit 9bdf396679
7 changed files with 54 additions and 25 deletions

View File

@@ -3,15 +3,28 @@
#include <QSortFilterProxyModel>
class FilterChildrenProxyModel : public QSortFilterProxyModel
class NumericSortProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit FilterChildrenProxyModel(QObject *parent = nullptr);
void setHideEmpty(bool hidden) { this->hideEmpty = hidden; }
explicit NumericSortProxyModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) {};
protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
};
class FilterChildrenProxyModel : public NumericSortProxyModel
{
Q_OBJECT
public:
explicit FilterChildrenProxyModel(QObject *parent = nullptr) : NumericSortProxyModel(parent) {};
void setHideEmpty(bool hidden) { this->hideEmpty = hidden; }
protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
private:
bool hideEmpty = false;
};

View File

@@ -79,7 +79,6 @@ protected:
QString activeItemName;
QString folderTypeName;
bool sortingEnabled = false;
bool editable = false;
QIcon mapGrayIcon;

View File

@@ -2,9 +2,24 @@
#define WILDMONSEARCH_H
#include <QDialog>
#include <QTableWidgetItem>
#include <QCollator>
class Project;
class NumericSortTableItem : public QTableWidgetItem
{
public:
explicit NumericSortTableItem(const QString &text) : QTableWidgetItem(text) {};
protected:
virtual bool operator<(const QTableWidgetItem &other) const override {
QCollator collator;
collator.setNumericMode(true);
return collator.compare(text(), other.text()) < 0;
}
};
namespace Ui {
class WildMonSearch;
}