File indexing completed on 2024-05-12 16:25:48

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "emoticonfilterproxymodel.h"
0008 #include "emoticonmodel.h"
0009 
0010 EmoticonFilterProxyModel::EmoticonFilterProxyModel(QObject *parent)
0011     : QSortFilterProxyModel(parent)
0012 {
0013     setFilterCaseSensitivity(Qt::CaseInsensitive);
0014     setFilterRole(EmoticonModel::IdentifierRole);
0015     sort(0);
0016 }
0017 
0018 EmoticonFilterProxyModel::~EmoticonFilterProxyModel() = default;
0019 
0020 bool EmoticonFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0021 {
0022     if (!sourceModel()) {
0023         return false;
0024     }
0025     if (left.isValid() && right.isValid()) {
0026         const QString leftString = sourceModel()->data(left, EmoticonModel::IdentifierRole).toString();
0027         const QString rightString = sourceModel()->data(right, EmoticonModel::IdentifierRole).toString();
0028         return QString::localeAwareCompare(leftString, rightString) < 0;
0029     } else {
0030         return false;
0031     }
0032 }
0033 
0034 #include "moc_emoticonfilterproxymodel.cpp"