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 BOOKMARKMODEL_H 42 #define BOOKMARKMODEL_H 43 44 #include <QtCore/QAbstractItemModel> 45 46 #include <QtGui/QIcon> 47 48 QT_BEGIN_NAMESPACE 49 50 class BookmarkItem; 51 class QMimeData; 52 class QTreeView; 53 54 typedef QMap<BookmarkItem*, QPersistentModelIndex> ItemModelIndexCache; 55 56 class BookmarkModel : public QAbstractItemModel 57 { 58 Q_OBJECT 59 public: 60 BookmarkModel(); 61 ~BookmarkModel(); 62 63 QByteArray bookmarks() const; 64 void setBookmarks(const QByteArray &bookmarks); 65 66 void setItemsEditable(bool editable); 67 void expandFoldersIfNeeeded(QTreeView *treeView); 68 69 QModelIndex addItem(const QModelIndex &parent, bool isFolder = false); 70 bool removeItem(const QModelIndex &index); 71 72 int rowCount(const QModelIndex &index = QModelIndex()) const; 73 int columnCount(const QModelIndex &index = QModelIndex()) const; 74 75 QModelIndex parent(const QModelIndex &index) const; 76 QModelIndex index(int row, int column, const QModelIndex &index) const; 77 78 Qt::DropActions supportedDropActions () const; 79 Qt::ItemFlags flags(const QModelIndex &index) const; 80 81 QVariant data(const QModelIndex &index, int role) const; 82 void setData(const QModelIndex &index, const QVector<QVariant> &data); 83 bool setData(const QModelIndex &index, const QVariant &value, int role); 84 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 85 86 QModelIndex indexFromItem(BookmarkItem *item) const; 87 BookmarkItem *itemFromIndex(const QModelIndex &index) const; 88 QList<QPersistentModelIndex> indexListFor(const QString &label) const; 89 90 bool insertRows(int position, int rows, const QModelIndex &parent); 91 bool removeRows(int position, int rows, const QModelIndex &parent); 92 93 QStringList mimeTypes() const; 94 QMimeData* mimeData(const QModelIndexList &indexes) const; 95 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, 96 int column, const QModelIndex &parent); 97 98 private: 99 void setupCache(const QModelIndex &parent); 100 QModelIndexList collectItems(const QModelIndex &parent) const; 101 void collectItems(const QModelIndex &parent, qint32 depth, 102 QDataStream *stream) const; 103 104 private: 105 int columns; 106 bool m_folder; 107 bool m_editable; 108 QIcon folderIcon; 109 QIcon bookmarkIcon; 110 QTreeView *treeView; 111 BookmarkItem *rootItem; 112 ItemModelIndexCache cache; 113 }; 114 115 QT_END_NAMESPACE 116 117 #endif // BOOKMARKMODEL_H 118