Branch data Line data Source code
1 : : #include "MailFilterProxyModel.h"
2 : :
3 : : #include "MailListModel.h"
4 : : #include "data/Models.h"
5 : :
6 : 65 : MailFilterProxyModel::MailFilterProxyModel(QObject *parent)
7 : 65 : : QSortFilterProxyModel(parent) {}
8 : :
9 : 43 : void MailFilterProxyModel::setFilterText(const QString &text) {
10 [ + + ]: 43 : if (m_filterText == text) return;
11 : 19 : m_filterText = text;
12 : 19 : invalidateFilter();
13 : : }
14 : :
15 : 5 : void MailFilterProxyModel::setShowUnreadOnly(bool on) {
16 [ - + ]: 5 : if (m_showUnread == on) return;
17 : 5 : m_showUnread = on;
18 : 5 : invalidateFilter();
19 : : }
20 : :
21 : 5 : void MailFilterProxyModel::setShowStarredOnly(bool on) {
22 [ - + ]: 5 : if (m_showStarred == on) return;
23 : 5 : m_showStarred = on;
24 : 5 : invalidateFilter();
25 : : }
26 : :
27 : 2 : void MailFilterProxyModel::setShowWithAttachments(bool on) {
28 [ + + ]: 2 : if (m_showAttachments == on) return;
29 : 1 : m_showAttachments = on;
30 : 1 : invalidateFilter();
31 : : }
32 : :
33 : 955 : bool MailFilterProxyModel::filterAcceptsRow(
34 : : int sourceRow, const QModelIndex &sourceParent) const {
35 [ + - + - ]: 955 : auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
36 : :
37 : : // Unread filter: check Seen flag
38 [ + + ]: 955 : if (m_showUnread) {
39 [ + - + - ]: 10 : quint32 flags = idx.data(MailListModel::FlagsRole).toUInt();
40 [ + + ]: 10 : if (flags & MailFlag::Seen)
41 : 2 : return false; // mail is read → hide
42 : : }
43 : :
44 : : // Starred filter: check Flagged flag
45 [ + + ]: 953 : if (m_showStarred) {
46 [ + - + - ]: 10 : quint32 flags = idx.data(MailListModel::FlagsRole).toUInt();
47 [ + + ]: 10 : if (!(flags & MailFlag::Flagged))
48 : 8 : return false; // mail is not starred → hide
49 : : }
50 : :
51 : : // Attachments filter
52 [ + + ]: 945 : if (m_showAttachments) {
53 [ + - + - ]: 2 : bool hasAtt = idx.data(MailListModel::HasAttachmentsRole).toBool();
54 [ + + ]: 2 : if (!hasAtt)
55 : 1 : return false;
56 : : }
57 : :
58 : : // Text filter: match against Subject and From columns
59 [ + + ]: 944 : if (!m_filterText.isEmpty()) {
60 : : auto subjectIdx =
61 [ + - + - ]: 117 : sourceModel()->index(sourceRow, MailListModel::Subject, sourceParent);
62 : : auto fromIdx =
63 [ + - + - ]: 117 : sourceModel()->index(sourceRow, MailListModel::From, sourceParent);
64 : :
65 [ + - + - ]: 117 : QString subject = subjectIdx.data(Qt::DisplayRole).toString();
66 [ + - + - ]: 117 : QString from = fromIdx.data(Qt::DisplayRole).toString();
67 : :
68 [ + - + + : 199 : if (!subject.contains(m_filterText, Qt::CaseInsensitive) &&
+ + ]
69 [ + - + + ]: 82 : !from.contains(m_filterText, Qt::CaseInsensitive)) {
70 : 66 : return false;
71 : : }
72 [ + + + + ]: 183 : }
73 : :
74 : 878 : return true;
75 : : }
|