Akonadi Contacts

contactsfilterproxymodel.h
1/*
2 This file is part of Akonadi Contact.
3
4 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#pragma once
10
11#include "akonadi-contact-core_export.h"
12
13#include <QSortFilterProxyModel>
14
15#include <memory>
16
17namespace Akonadi
18{
19class 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 <tokoe@kde.org>
48 * @since 4.5
49 */
50class AKONADI_CONTACT_CORE_EXPORT ContactsFilterProxyModel : public QSortFilterProxyModel
51{
52 Q_OBJECT
53
54public:
55 enum MatchFilterContactFlag {
56 All = 0,
57 OnlyNameAndEmailsAddresses = 1
58 };
59 enum FilterFlag {
60 HasEmail = 0x01 /// Filters out contacts without any email address set.
61 };
62 Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
63
64 /**
65 * Creates a new contacts filter proxy model.
66 *
67 * @param parent The parent object.
68 */
69 explicit ContactsFilterProxyModel(QObject *parent = nullptr);
70
71 /**
72 * Destroys the contacts filter proxy model.
73 */
75
76 /**
77 * Sets the filter @p flags. By default
78 * ContactsFilterProxyModel::FilterString is set.
79 * @param flags the filter flags to set
80 * @since 4.8
81 */
82 void setFilterFlags(ContactsFilterProxyModel::FilterFlags flags);
83
84 /**
85 * @brief setMatchFilterContactFlag
86 * @param flag
87 * @since 5.8.0
88 *
89 */
90 void setMatchFilterContactFlag(ContactsFilterProxyModel::MatchFilterContactFlag flag);
91
92 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
93
94 /**
95 * Sets whether we want virtual collections to be filtered or not.
96 * By default, virtual collections are accepted.
97 *
98 * @param exclude If true, virtual collections aren't accepted.
99 *
100 * @since 4.8
101 */
102 void setExcludeVirtualCollections(bool exclude);
103
104public Q_SLOTS:
105 /**
106 * Sets the @p filter that is used to filter for matching contacts
107 * and contact groups.
108 */
109 void setFilterString(const QString &filter);
110
111protected:
112 //@cond PRIVATE
113 bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
114 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
115 //@endcond
116
117private:
118 //@cond PRIVATE
119 std::unique_ptr<ContactsFilterProxyModelPrivate> const d;
120 //@endcond
121};
122
123Q_DECLARE_OPERATORS_FOR_FLAGS(ContactsFilterProxyModel::FilterFlags)
124}
A proxy model for ContactsTreeModel models.
~ContactsFilterProxyModel() override
Destroys the contacts filter proxy model.
A widget for editing the display name of a contact.
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.