File indexing completed on 2025-03-02 05:11:58

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Fredrik Höglund <fredrik@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
0005 */
0006 
0007 #include "sortproxymodel.h"
0008 #include "cursortheme.h"
0009 #include <QString>
0010 
0011 QHash<int, QByteArray> SortProxyModel::roleNames() const
0012 {
0013     QHash<int, QByteArray> roleNames = QSortFilterProxyModel::roleNames();
0014     roleNames[CursorTheme::DisplayDetailRole] = "description";
0015 
0016     return roleNames;
0017 }
0018 
0019 int SortProxyModel::compare(const QModelIndex &left, const QModelIndex &right, int role) const
0020 {
0021     const QAbstractItemModel *model = sourceModel();
0022 
0023     QString first = model->data(left, role).toString();
0024     QString second = model->data(right, role).toString();
0025 
0026     if (filterCaseSensitivity() == Qt::CaseInsensitive) {
0027         first = first.toLower();
0028         second = second.toLower();
0029     }
0030 
0031     return QString::localeAwareCompare(first, second);
0032 }
0033 
0034 bool SortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0035 {
0036     const int result = compare(left, right, Qt::DisplayRole);
0037 
0038     if (result != 0)
0039         return (result < 0);
0040     else
0041         return compare(left, right, CursorTheme::DisplayDetailRole) < 0;
0042 }