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 BOOKMARKMODEL_H
4#define BOOKMARKMODEL_H
5
6#include <QtCore/QAbstractItemModel>
7#include <QtCore/QMap>
8
9#include <QtGui/QIcon>
10
11QT_BEGIN_NAMESPACE
12
13class BookmarkItem;
14class QMimeData;
15class QTreeView;
16
17typedef QMap<BookmarkItem*, QPersistentModelIndex> ItemModelIndexCache;
18
19class BookmarkModel : public QAbstractItemModel
20{
21 Q_OBJECT
22public:
23 BookmarkModel();
24 ~BookmarkModel() override;
25
26 QByteArray bookmarks() const;
27 void setBookmarks(const QByteArray &bookmarks);
28
29 void setItemsEditable(bool editable);
30 void expandFoldersIfNeeeded(QTreeView *treeView);
31
32 QModelIndex addItem(const QModelIndex &parent, bool isFolder = false);
33 bool removeItem(const QModelIndex &index);
34
35 int rowCount(const QModelIndex &index = QModelIndex()) const override;
36 int columnCount(const QModelIndex &index = QModelIndex()) const override;
37
38 QModelIndex parent(const QModelIndex &index) const override;
39 QModelIndex index(int row, int column, const QModelIndex &index) const override;
40
41 Qt::DropActions supportedDropActions () const override;
42 Qt::ItemFlags flags(const QModelIndex &index) const override;
43
44 QVariant data(const QModelIndex &index, int role) const override;
45 void setData(const QModelIndex &index, const QList<QVariant> &data);
46 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
47 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
48
49 QModelIndex indexFromItem(BookmarkItem *item) const;
50 BookmarkItem *itemFromIndex(const QModelIndex &index) const;
51 QList<QPersistentModelIndex> indexListFor(const QString &label) const;
52
53 bool insertRows(int position, int rows, const QModelIndex &parent) override;
54 bool removeRows(int position, int rows, const QModelIndex &parent) override;
55
56 QStringList mimeTypes() const override;
57 QMimeData* mimeData(const QModelIndexList &indexes) const override;
58 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
59 int column, const QModelIndex &parent) override;
60
61private:
62 void setupCache(const QModelIndex &parent);
63 QModelIndexList collectItems(const QModelIndex &parent) const;
64 void collectItems(const QModelIndex &parent, qint32 depth,
65 QDataStream *stream) const;
66
67private:
68 int columns;
69 bool m_folder;
70 bool m_editable;
71 QIcon folderIcon;
72 QIcon bookmarkIcon;
73 QTreeView *treeView;
74 BookmarkItem *rootItem;
75 ItemModelIndexCache cache;
76};
77
78QT_END_NAMESPACE
79
80#endif // BOOKMARKMODEL_H
81

source code of qttools/src/assistant/assistant/bookmarkmodel.h