KPeople

personssortfilterproxymodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Aleix Pol i Gonzalez <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "personssortfilterproxymodel.h"
8 #include "backends/abstractcontact.h"
9 #include "personsmodel.h"
10 
11 namespace KPeople
12 {
13 class PersonsSortFilterProxyModelPrivate
14 {
15 public:
16  QStringList m_keys;
17 };
18 
19 PersonsSortFilterProxyModel::PersonsSortFilterProxyModel(QObject *parent)
20  : QSortFilterProxyModel(parent)
21  , d_ptr(new PersonsSortFilterProxyModelPrivate)
22 {
23 }
24 
25 PersonsSortFilterProxyModel::~PersonsSortFilterProxyModel()
26 {
27 }
28 
30 {
31  Q_D(const PersonsSortFilterProxyModel);
32  return d->m_keys;
33 }
34 
35 void PersonsSortFilterProxyModel::setRequiredProperties(const QStringList &props)
36 {
37  Q_D(PersonsSortFilterProxyModel);
38  d->m_keys = props;
39  invalidate();
40 }
41 
42 bool PersonsSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
43 {
44  Q_D(const PersonsSortFilterProxyModel);
45  const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
46  Q_ASSERT(idx.isValid());
47 
48  if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) {
49  return false;
50  }
51 
52  const AbstractContact::Ptr contact = idx.data(KPeople::PersonsModel::PersonVCardRole).value<AbstractContact::Ptr>();
53  Q_ASSERT(contact);
54 
55  // Don't filter if no keys are set
56  if (d->m_keys.isEmpty()) {
57  return true;
58  }
59 
60  for (const QString &key : std::as_const(d->m_keys)) {
61  if (!contact->customProperty(key).isNull()) {
62  return true;
63  }
64  }
65 
66  return false;
67 }
68 
69 void PersonsSortFilterProxyModel::sort(int column, Qt::SortOrder order)
70 {
71  QSortFilterProxyModel::sort(column, order);
72 }
73 }
T value() const const
SortOrder
QStringList requiredProperties
Specifies the properties that should be provided by the contact for the contact to be shown.
virtual void sort(int column, Qt::SortOrder order) override
QVariant data(int role) const const
bool isValid() const const
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Aug 14 2022 04:09:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.