Debian Codegraph @

src/librssguard/core/feedsproxymodel.h

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef FEEDSPROXYMODEL_H
4 #define FEEDSPROXYMODEL_H
5
6 #include "services/abstract/rootitem.h"
7
8 #include <QSortFilterProxyModel>
9
10 class FeedsModel;
11 class FeedsView;
12
13 class FeedsProxyModel : public QSortFilterProxyModel {
14 Q_OBJECT
15
16 public:
17 // Enum which describes basic filtering schemes
18 // for feeds.
19 enum class FeedListFilter {
20 NoFiltering = 1,
21 ShowUnread = 2,
22 ShowEmpty = 4,
23 ShowNonEmpty = 8,
24 ShowWithNewArticles = 16,
25 ShowWithError = 32,
26 ShowSwitchedOff = 64,
27 ShowQuiet = 128,
28 ShowWithArticleFilters = 256
29 };
30
31 explicit FeedsProxyModel(FeedsModel* source_model, QObject* parent = nullptr);
32 virtual ~FeedsProxyModel();
33
34 void setFeedListFilter(FeedListFilter filter);
35
36 virtual bool canDropMimeData(const QMimeData* data,
37 Qt::DropAction action,
38 int row,
39 int column,
40 const QModelIndex& parent) const;
41 virtual bool dropMimeData(const QMimeData* data,
42 Qt::DropAction action,
43 int row,
44 int column,
45 const QModelIndex& parent);
46
47 virtual void sort(int column, Qt::SortOrder order = Qt::SortOrder::AscendingOrder);
48
49 // Returns index list of items which "match" given value.
50 // Used for finding items according to entered title text.
51 virtual QModelIndexList match(const QModelIndex& start,
52 int role,
53 const QVariant& value,
54 int hits,
55 Qt::MatchFlags flags) const;
56
57 // Maps list of indexes.
58 QModelIndexList mapListToSource(const QModelIndexList& indexes) const;
59
60 const RootItem* selectedItem() const;
61 void setSelectedItem(const RootItem* selected_item);
62
63 void setView(FeedsView* newView);
64
65 bool sortAlphabetically() const;
66 void setSortAlphabetically(bool sort_alphabetically);
67
68 signals:
69 void indexNotFilteredOutAnymore(QModelIndex source_idx) const;
70
71 // There was some drag/drop operation, notify view about this.
72 void requireItemValidationAfterDragDrop(const QModelIndex& source_index);
73
74 protected:
75 virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
76 virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
77
78 private:
79 void initializeFilters();
80
81 bool filterAcceptsRowInternal(int source_row, const QModelIndex& source_parent) const;
82
83 // Source model pointer.
84 FeedsModel* m_sourceModel;
85 FeedsView* m_view;
86 const RootItem* m_selectedItem;
87 bool m_sortAlphabetically;
88 bool m_showNodeUnread;
89 bool m_showNodeProbes;
90 bool m_showNodeLabels;
91 bool m_showNodeImportant;
92 QList<RootItem::Kind> m_priorities;
93 QList<QPair<int, QModelIndex>> m_hiddenIndices;
94
95 FeedListFilter m_filter;
96
97 // NOTE: The parameter type can be Category, Feed or Label only.
98 QMap<FeedListFilter, std::function<bool(const RootItem*)>> m_filters;
99 QList<FeedListFilter> m_filterKeys;
100 };
101
102 Q_DECLARE_METATYPE(FeedsProxyModel::FeedListFilter)
103
104 #endif // FEEDSPROXYMODEL_H