File indexing completed on 2024-12-08 07:33:46
0001 // SPDX-FileCopyrightText: 2022 Snehit Sah <hi@snehit.dev> 0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 0004 #include "sortfilterspacelistmodel.h" 0005 0006 #include "roomlistmodel.h" 0007 0008 SortFilterSpaceListModel::SortFilterSpaceListModel(QObject *parent) 0009 : QSortFilterProxyModel{parent} 0010 { 0011 setSortRole(RoomListModel::RoomIdRole); 0012 sort(0); 0013 invalidateFilter(); 0014 connect(this, &QAbstractProxyModel::sourceModelChanged, this, [this]() { 0015 connect(sourceModel(), &QAbstractListModel::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, QList<int> roles) { 0016 if (roles.contains(RoomListModel::IsChildSpaceRole)) { 0017 invalidate(); 0018 } 0019 countChanged(); 0020 }); 0021 invalidate(); 0022 Q_EMIT countChanged(); 0023 }); 0024 } 0025 0026 bool SortFilterSpaceListModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0027 { 0028 Q_UNUSED(source_parent); 0029 return sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() 0030 && sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != QStringLiteral("upgraded") 0031 && !sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsChildSpaceRole).toBool(); 0032 } 0033 0034 bool SortFilterSpaceListModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const 0035 { 0036 const auto idLeft = sourceModel()->data(source_left, RoomListModel::RoomIdRole).toString(); 0037 const auto idRight = sourceModel()->data(source_right, RoomListModel::RoomIdRole).toString(); 0038 return idLeft < idRight; 0039 } 0040 0041 #include "moc_sortfilterspacelistmodel.cpp"