File indexing completed on 2024-10-06 04:34:07
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 "statusmodelfilterproxymodel.h" 0008 #include "statusmodel.h" 0009 0010 StatusModelFilterProxyModel::StatusModelFilterProxyModel(QObject *parent) 0011 : QSortFilterProxyModel(parent) 0012 { 0013 setFilterCaseSensitivity(Qt::CaseInsensitive); 0014 } 0015 0016 StatusModelFilterProxyModel::~StatusModelFilterProxyModel() = default; 0017 0018 bool StatusModelFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 0019 { 0020 if (!sourceModel()) { 0021 return false; 0022 } 0023 if (left.isValid() && right.isValid()) { 0024 const int leftString = sourceModel()->data(left, StatusModel::Order).toInt(); 0025 const int rightString = sourceModel()->data(right, StatusModel::Order).toInt(); 0026 return rightString < leftString; 0027 } else { 0028 return false; 0029 } 0030 return true; 0031 } 0032 0033 bool StatusModelFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0034 { 0035 const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent); 0036 if (mUseOnlyStandardStatus) { 0037 const int order = sourceIndex.data(StatusModel::Order).toInt(); 0038 return order > 10; // Standard entry has order > 10 0039 } 0040 if (!mAllowOfflineSupport) { 0041 const User::PresenceStatus status = sourceIndex.data(StatusModel::Status).value<User::PresenceStatus>(); 0042 if (status == User::PresenceStatus::PresenceOffline) { 0043 return false; 0044 } 0045 } 0046 return true; 0047 } 0048 0049 bool StatusModelFilterProxyModel::allowOfflineSupport() const 0050 { 0051 return mAllowOfflineSupport; 0052 } 0053 0054 void StatusModelFilterProxyModel::setAllowOfflineSupport(bool newAllowOfflineSupport) 0055 { 0056 if (mAllowOfflineSupport != newAllowOfflineSupport) { 0057 mAllowOfflineSupport = newAllowOfflineSupport; 0058 invalidateFilter(); 0059 } 0060 } 0061 0062 bool StatusModelFilterProxyModel::useOnlyStandardStatus() const 0063 { 0064 return mUseOnlyStandardStatus; 0065 } 0066 0067 void StatusModelFilterProxyModel::setUseOnlyStandardStatus(bool useOnlyStandardStatus) 0068 { 0069 mUseOnlyStandardStatus = useOnlyStandardStatus; 0070 } 0071 0072 #include "moc_statusmodelfilterproxymodel.cpp"