Debian Codegraph @

src/librssguard/services/abstract/accountcheckmodel.h

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef ACCOUNTCHECKMODEL_H
4 #define ACCOUNTCHECKMODEL_H
5
6 #include "services/abstract/rootitem.h"
7
8 #include <QAbstractItemModel>
9 #include <QSortFilterProxyModel>
10
11 // This is common model which displays only categories/feeds
12 // and allows user to place checkmarks.
13 class RSSGUARD_DLLSPEC AccountCheckModel : public QAbstractItemModel {
14 Q_OBJECT
15
16 public:
17 explicit AccountCheckModel(QObject* parent = nullptr);
18 virtual ~AccountCheckModel() = default;
19
20 virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
21 virtual QModelIndex parent(const QModelIndex& child) const;
22 virtual int rowCount(const QModelIndex& parent) const;
23 virtual int columnCount(const QModelIndex& parent) const;
24 virtual QVariant data(const QModelIndex& index, int role) const;
25 virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
26 virtual Qt::ItemFlags flags(const QModelIndex& index) const;
27
28 QList<RootItem*> checkedItems() const;
29
30 bool isItemChecked(RootItem* item) const;
31 bool setItemChecked(RootItem* item, Qt::CheckState check);
32
33 // Returns feed/category which lies at the specified index or
34 // root item if index is invalid.
35 RootItem* itemForIndex(const QModelIndex& index) const;
36
37 // Returns source QModelIndex on which lies given item.
38 QModelIndex indexForItem(RootItem* item) const;
39
40 // Root item manipulators.
41 RootItem* rootItem() const;
42 void setRootItem(RootItem* root_item, bool delete_previous_root = true, bool with_layout_change = false);
43
44 public slots:
45 void checkAllItems();
46 void uncheckAllItems();
47
48 signals:
49 void checkStateChanged(RootItem* item, Qt::CheckState state);
50
51 protected:
52 RootItem* m_rootItem;
53
54 private:
55 QHash<RootItem*, Qt::CheckState> m_checkStates;
56 bool m_recursiveChange;
57 };
58
59 class RSSGUARD_DLLSPEC AccountCheckSortedModel : public QSortFilterProxyModel {
60 Q_OBJECT
61
62 public:
63 explicit AccountCheckSortedModel(QObject* parent = nullptr);
64 virtual ~AccountCheckSortedModel() = default;
65
66 AccountCheckModel* sourceModel() const;
67 void setRootItem(RootItem* root_item, bool delete_previous_root = true, bool with_layout_change = false);
68
69 public slots:
70 void checkAllItems();
71 void uncheckAllItems();
72
73 protected:
74 virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
75 virtual bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
76
77 private:
78 AccountCheckModel* m_sourceModel;
79 };
80
81 #endif // ACCOUNTCHECKMODEL_H