Akonadi Contacts

contactsfilterproxymodel.h
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include "akonadi-contact_export.h"
12 
13 #include <QSortFilterProxyModel>
14 
15 #include <memory>
16 
17 namespace Akonadi
18 {
19 class ContactsFilterProxyModelPrivate;
20 
21 /**
22  * @short A proxy model for \a ContactsTreeModel models.
23  *
24  * This class provides a filter proxy model for a ContactsTreeModel.
25  * The list of shown contacts or contact groups can be limited by
26  * settings a filter pattern. Only contacts or contact groups that contain
27  * this pattern as part of their data will be listed.
28  *
29  * Example:
30  *
31  * @code
32  *
33  * Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( ... );
34  *
35  * Akonadi::ContactsFilterProxyModel *filter = new Akonadi::ContactsFilterProxyModel;
36  * filter->setSourceModel( model );
37  *
38  * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView;
39  * view->setModel( filter );
40  *
41  * QLineEdit *filterEdit = new QLineEdit;
42  * connect( filterEdit, SIGNAL(textChanged(QString)),
43  * filter, SLOT(setFilterString(QString)) );
44  *
45  * @endcode
46  *
47  * @author Tobias Koenig <[email protected]>
48  * @since 4.5
49  */
50 class AKONADI_CONTACT_EXPORT ContactsFilterProxyModel : public QSortFilterProxyModel
51 {
52  Q_OBJECT
53 
54 public:
55  enum MatchFilterContactFlag { All = 0, OnlyNameAndEmailsAddresses = 1 };
56  enum FilterFlag {
57  HasEmail = 0x01 /// Filters out contacts without any email address set.
58  };
59  Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
60 
61  /**
62  * Creates a new contacts filter proxy model.
63  *
64  * @param parent The parent object.
65  */
66  explicit ContactsFilterProxyModel(QObject *parent = nullptr);
67 
68  /**
69  * Destroys the contacts filter proxy model.
70  */
71  ~ContactsFilterProxyModel() override;
72 
73  /**
74  * Sets the filter @p flags. By default
75  * ContactsFilterProxyModel::FilterString is set.
76  * @param flags the filter flags to set
77  * @since 4.8
78  */
79  void setFilterFlags(ContactsFilterProxyModel::FilterFlags flags);
80 
81  /**
82  * @brief setMatchFilterContactFlag
83  * @param flag
84  * @since 5.8.0
85  *
86  */
87  void setMatchFilterContactFlag(ContactsFilterProxyModel::MatchFilterContactFlag flag);
88 
89  Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
90 
91  /**
92  * Sets whether we want virtual collections to be filtered or not.
93  * By default, virtual collections are accepted.
94  *
95  * @param exclude If true, virtual collections aren't accepted.
96  *
97  * @since 4.8
98  */
99  void setExcludeVirtualCollections(bool exclude);
100 
101 public Q_SLOTS:
102  /**
103  * Sets the @p filter that is used to filter for matching contacts
104  * and contact groups.
105  */
106  void setFilterString(const QString &filter);
107 
108 protected:
109  //@cond PRIVATE
110  bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
111  bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
112  //@endcond
113 
114 private:
115  //@cond PRIVATE
116  std::unique_ptr<ContactsFilterProxyModelPrivate> const d;
117  //@endcond
118 };
119 
120 Q_DECLARE_OPERATORS_FOR_FLAGS(ContactsFilterProxyModel::FilterFlags)
121 }
A proxy model for ContactsTreeModel models.
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.