forked from qt-creator/qt-creator
QtSupport: Use natural sorting for Qt versions in settings widget
Change-Id: I4ef14a575c536e9f789fedf24937bd0f9e118f91 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "treemodel.h"
|
||||
|
||||
#include "qtcassert.h"
|
||||
#include "stringutils.h"
|
||||
|
||||
#include <QStack>
|
||||
#include <QSize>
|
||||
@@ -1199,4 +1200,12 @@ Qt::ItemFlags StaticTreeItem::flags(int column) const
|
||||
return Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
bool SortModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
if (m_lessThan)
|
||||
return lessThan(source_left, source_right);
|
||||
return caseFriendlyCompare(sourceModel()->data(source_left).toString(),
|
||||
sourceModel()->data(source_right).toString()) < 0;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "indexedcontainerproxyconstiterator.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -344,6 +344,20 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// By default, does natural sorting by display name. Call setLessThan() to customize.
|
||||
class QTCREATOR_UTILS_EXPORT SortModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
using QSortFilterProxyModel::QSortFilterProxyModel;
|
||||
using LessThan = std::function<bool(const QModelIndex &, const QModelIndex &)>;
|
||||
void setLessThan(const LessThan &lessThan) { m_lessThan = lessThan; }
|
||||
|
||||
private:
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
|
||||
|
||||
LessThan m_lessThan;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Q_DECLARE_METATYPE(Utils::TreeItem *)
|
||||
|
@@ -41,7 +41,6 @@
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTextBrowser>
|
||||
#include <QTreeView>
|
||||
|
||||
@@ -197,7 +196,7 @@ private:
|
||||
void updateVersionItem(QtVersionItem *item);
|
||||
|
||||
TreeModel<TreeItem, TreeItem, QtVersionItem> *m_model;
|
||||
QSortFilterProxyModel *m_filterModel;
|
||||
SortModel *m_filterModel;
|
||||
TreeItem *m_autoItem;
|
||||
TreeItem *m_manualItem;
|
||||
|
||||
@@ -314,9 +313,8 @@ QtOptionsPageWidget::QtOptionsPageWidget()
|
||||
m_model->rootItem()->appendChild(m_autoItem);
|
||||
m_model->rootItem()->appendChild(m_manualItem);
|
||||
|
||||
m_filterModel = new QSortFilterProxyModel(this);
|
||||
m_filterModel = new SortModel(this);
|
||||
m_filterModel->setSourceModel(m_model);
|
||||
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
m_qtdirList->setModel(m_filterModel);
|
||||
m_qtdirList->setSortingEnabled(true);
|
||||
|
Reference in New Issue
Block a user