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

KDE's Doxygen guidelines are available online.