1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | #ifndef BOOKMARKFILTERMODEL_H |
4 | #define BOOKMARKFILTERMODEL_H |
5 | |
6 | #include <QtCore/QPersistentModelIndex> |
7 | |
8 | #include <QtCore/QAbstractProxyModel> |
9 | #include <QtCore/QSortFilterProxyModel> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class BookmarkItem; |
14 | class BookmarkModel; |
15 | |
16 | typedef QList<QPersistentModelIndex> PersistentModelIndexCache; |
17 | |
18 | class BookmarkFilterModel : public QAbstractProxyModel |
19 | { |
20 | Q_OBJECT |
21 | public: |
22 | explicit BookmarkFilterModel(QObject *parent = nullptr); |
23 | |
24 | void setSourceModel(QAbstractItemModel *sourceModel) override; |
25 | |
26 | int rowCount(const QModelIndex &index) const override; |
27 | int columnCount(const QModelIndex &index) const override; |
28 | |
29 | QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; |
30 | QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; |
31 | |
32 | QModelIndex parent(const QModelIndex &child) const override; |
33 | QModelIndex index(int row, int column, const QModelIndex &parent) const override; |
34 | |
35 | Qt::DropActions supportedDropActions () const override; |
36 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
37 | |
38 | QVariant data(const QModelIndex &index, int role) const override; |
39 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; |
40 | |
41 | void filterBookmarks(); |
42 | void filterBookmarkFolders(); |
43 | |
44 | private slots: |
45 | void changed(const QModelIndex &topLeft, const QModelIndex &bottomRight); |
46 | void rowsInserted(const QModelIndex &parent, int start, int end); |
47 | void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); |
48 | void rowsRemoved(const QModelIndex &parent, int start, int end); |
49 | void layoutAboutToBeChanged(); |
50 | void layoutChanged(); |
51 | void modelAboutToBeReset(); |
52 | void modelReset(); |
53 | |
54 | private: |
55 | void setupCache(const QModelIndex &parent); |
56 | void collectItems(const QModelIndex &parent); |
57 | |
58 | private: |
59 | BookmarkModel *sourceModel = nullptr; |
60 | PersistentModelIndexCache cache; |
61 | QPersistentModelIndex indexToRemove; |
62 | bool hideBookmarks = true; |
63 | }; |
64 | |
65 | // -- BookmarkTreeModel |
66 | |
67 | class BookmarkTreeModel : public QSortFilterProxyModel |
68 | { |
69 | Q_OBJECT |
70 | public: |
71 | BookmarkTreeModel(QObject *parent = nullptr); |
72 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
73 | |
74 | protected: |
75 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; |
76 | }; |
77 | |
78 | QT_END_NAMESPACE |
79 | |
80 | #endif // BOOKMARKFILTERMODEL_H |
81 | |