Warning, file /frameworks/kpeople/src/personssortfilterproxymodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2015 Aleix Pol i Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "personssortfilterproxymodel.h" 0008 #include "backends/abstractcontact.h" 0009 #include "personsmodel.h" 0010 0011 namespace KPeople 0012 { 0013 class PersonsSortFilterProxyModelPrivate 0014 { 0015 public: 0016 QStringList m_keys; 0017 }; 0018 0019 PersonsSortFilterProxyModel::PersonsSortFilterProxyModel(QObject *parent) 0020 : QSortFilterProxyModel(parent) 0021 , d_ptr(new PersonsSortFilterProxyModelPrivate) 0022 { 0023 } 0024 0025 PersonsSortFilterProxyModel::~PersonsSortFilterProxyModel() 0026 { 0027 } 0028 0029 QStringList PersonsSortFilterProxyModel::requiredProperties() const 0030 { 0031 Q_D(const PersonsSortFilterProxyModel); 0032 return d->m_keys; 0033 } 0034 0035 void PersonsSortFilterProxyModel::setRequiredProperties(const QStringList &props) 0036 { 0037 Q_D(PersonsSortFilterProxyModel); 0038 d->m_keys = props; 0039 invalidate(); 0040 } 0041 0042 bool PersonsSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0043 { 0044 Q_D(const PersonsSortFilterProxyModel); 0045 const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); 0046 Q_ASSERT(idx.isValid()); 0047 0048 if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) { 0049 return false; 0050 } 0051 0052 const AbstractContact::Ptr contact = idx.data(KPeople::PersonsModel::PersonVCardRole).value<AbstractContact::Ptr>(); 0053 Q_ASSERT(contact); 0054 0055 // Don't filter if no keys are set 0056 if (d->m_keys.isEmpty()) { 0057 return true; 0058 } 0059 0060 for (const QString &key : std::as_const(d->m_keys)) { 0061 if (!contact->customProperty(key).isNull()) { 0062 return true; 0063 } 0064 } 0065 0066 return false; 0067 } 0068 0069 void PersonsSortFilterProxyModel::sort(int column, Qt::SortOrder order) 0070 { 0071 QSortFilterProxyModel::sort(column, order); 0072 } 0073 } 0074 0075 #include "moc_personssortfilterproxymodel.cpp"