1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Assistant of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | #ifndef BOOKMARKMODEL_H |
29 | #define BOOKMARKMODEL_H |
30 | |
31 | #include <QtCore/QAbstractItemModel> |
32 | |
33 | #include <QtGui/QIcon> |
34 | |
35 | QT_BEGIN_NAMESPACE |
36 | |
37 | class BookmarkItem; |
38 | class QMimeData; |
39 | class QTreeView; |
40 | |
41 | typedef QMap<BookmarkItem*, QPersistentModelIndex> ItemModelIndexCache; |
42 | |
43 | class BookmarkModel : public QAbstractItemModel |
44 | { |
45 | Q_OBJECT |
46 | public: |
47 | BookmarkModel(); |
48 | ~BookmarkModel() override; |
49 | |
50 | QByteArray bookmarks() const; |
51 | void setBookmarks(const QByteArray &bookmarks); |
52 | |
53 | void setItemsEditable(bool editable); |
54 | void expandFoldersIfNeeeded(QTreeView *treeView); |
55 | |
56 | QModelIndex addItem(const QModelIndex &parent, bool isFolder = false); |
57 | bool removeItem(const QModelIndex &index); |
58 | |
59 | int rowCount(const QModelIndex &index = QModelIndex()) const override; |
60 | int columnCount(const QModelIndex &index = QModelIndex()) const override; |
61 | |
62 | QModelIndex parent(const QModelIndex &index) const override; |
63 | QModelIndex index(int row, int column, const QModelIndex &index) const override; |
64 | |
65 | Qt::DropActions supportedDropActions () const override; |
66 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
67 | |
68 | QVariant data(const QModelIndex &index, int role) const override; |
69 | void setData(const QModelIndex &index, const QVector<QVariant> &data); |
70 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; |
71 | QVariant (int section, Qt::Orientation orientation, int role) const override; |
72 | |
73 | QModelIndex indexFromItem(BookmarkItem *item) const; |
74 | BookmarkItem *itemFromIndex(const QModelIndex &index) const; |
75 | QList<QPersistentModelIndex> indexListFor(const QString &label) const; |
76 | |
77 | bool insertRows(int position, int rows, const QModelIndex &parent) override; |
78 | bool removeRows(int position, int rows, const QModelIndex &parent) override; |
79 | |
80 | QStringList mimeTypes() const override; |
81 | QMimeData* mimeData(const QModelIndexList &indexes) const override; |
82 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, |
83 | int column, const QModelIndex &parent) override; |
84 | |
85 | private: |
86 | void setupCache(const QModelIndex &parent); |
87 | QModelIndexList collectItems(const QModelIndex &parent) const; |
88 | void collectItems(const QModelIndex &parent, qint32 depth, |
89 | QDataStream *stream) const; |
90 | |
91 | private: |
92 | int columns; |
93 | bool m_folder; |
94 | bool m_editable; |
95 | QIcon folderIcon; |
96 | QIcon bookmarkIcon; |
97 | QTreeView *treeView; |
98 | BookmarkItem *rootItem; |
99 | ItemModelIndexCache cache; |
100 | }; |
101 | |
102 | QT_END_NAMESPACE |
103 | |
104 | #endif // BOOKMARKMODEL_H |
105 | |