File indexing completed on 2024-02-25 16:44:35

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 "channelcompleterfilterproxymodel.h"
0008 #include "inputcompletermodel.h"
0009 
0010 ChannelCompleterFilterProxyModel::ChannelCompleterFilterProxyModel(QObject *parent)
0011     : QSortFilterProxyModel(parent)
0012 {
0013     setFilterCaseSensitivity(Qt::CaseInsensitive);
0014     setFilterRole(InputCompleterModel::CompleterName);
0015     sort(0);
0016 }
0017 
0018 ChannelCompleterFilterProxyModel::~ChannelCompleterFilterProxyModel() = default;
0019 
0020 void ChannelCompleterFilterProxyModel::clear()
0021 {
0022     static_cast<InputCompleterModel *>(sourceModel())->clear();
0023 }
0024 
0025 bool ChannelCompleterFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0026 {
0027     if (!sourceModel()) {
0028         return false;
0029     }
0030     if (left.isValid() && right.isValid()) {
0031         const QString leftString = sourceModel()->data(left, InputCompleterModel::CompleterName).toString();
0032         const QString rightString = sourceModel()->data(right, InputCompleterModel::CompleterName).toString();
0033         return QString::localeAwareCompare(leftString, rightString) < 0;
0034     } else {
0035         return false;
0036     }
0037 }
0038 
0039 #include "moc_channelcompleterfilterproxymodel.cpp"