1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Assistant of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef BOOKMARKFILTERMODEL_H
42 #define BOOKMARKFILTERMODEL_H
43 
44 #include <QtCore/QPersistentModelIndex>
45 
46 #include <QtGui/QAbstractProxyModel>
47 #include <QtGui/QSortFilterProxyModel>
48 
49 QT_BEGIN_NAMESPACE
50 
51 class BookmarkItem;
52 class BookmarkModel;
53 
54 typedef QList<QPersistentModelIndex> PersistentModelIndexCache;
55 
56 class BookmarkFilterModel : public QAbstractProxyModel
57 {
58     Q_OBJECT
59 public:
60     explicit BookmarkFilterModel(QObject *parent = 0);
61 
62     void setSourceModel(QAbstractItemModel *sourceModel);
63 
64     int rowCount(const QModelIndex &index) const;
65     int columnCount(const QModelIndex &index) const;
66 
67     QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
68     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
69 
70     QModelIndex parent(const QModelIndex &child) const;
71     QModelIndex index(int row, int column, const QModelIndex &parent) const;
72 
73     Qt::DropActions supportedDropActions () const;
74     Qt::ItemFlags flags(const QModelIndex &index) const;
75 
76     QVariant data(const QModelIndex &index, int role) const;
77     bool setData(const QModelIndex &index, const QVariant &value, int role);
78 
79     void filterBookmarks();
80     void filterBookmarkFolders();
81 
82 private slots:
83     void changed(const QModelIndex &topLeft, const QModelIndex &bottomRight);
84     void rowsInserted(const QModelIndex &parent, int start, int end);
85     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
86     void rowsRemoved(const QModelIndex &parent, int start, int end);
87     void layoutAboutToBeChanged();
88     void layoutChanged();
89     void modelAboutToBeReset();
90     void modelReset();
91 
92 private:
93     void setupCache(const QModelIndex &parent);
94     void collectItems(const QModelIndex &parent);
95 
96 private:
97     bool hideBookmarks;
98     BookmarkModel *sourceModel;
99     PersistentModelIndexCache cache;
100     QPersistentModelIndex indexToRemove;
101 };
102 
103 // -- BookmarkTreeModel
104 
105 class BookmarkTreeModel : public QSortFilterProxyModel
106 {
107     Q_OBJECT
108 public:
109     BookmarkTreeModel(QObject *parent = 0);
110     int columnCount(const QModelIndex &parent = QModelIndex()) const;
111 
112 protected:
113     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
114 };
115 
116 QT_END_NAMESPACE
117 
118 #endif // BOOKMARKFILTERMODEL_H
119