1 /* This file is part of the KDE project 2 Copyright (C) 2005 Daniel Teske <teske@squorn.de> 3 Copyright (C) 2010 David Faure <faure@kde.org> 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2 of 8 the License, or (at your option) version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/> 17 */ 18 19 #ifndef BOOKMARKMODEL_MODEL_H 20 #define BOOKMARKMODEL_MODEL_H 21 22 #include "kbookmarkmodel_export.h" 23 #include <QAbstractItemModel> 24 25 class CommandHistory; 26 class KBookmarkGroup; 27 class KBookmarkManager; 28 class KBookmark; 29 30 class KBOOKMARKMODEL_EXPORT KBookmarkModel : public QAbstractItemModel 31 { 32 Q_OBJECT 33 34 enum ColumnIds { 35 NameColumnId = 0, 36 UrlColumnId = 1, 37 CommentColumnId = 2, 38 StatusColumnId = 3, 39 LastColumnId = 3, 40 NoOfColumnIds = LastColumnId + 1, 41 }; 42 43 public: 44 KBookmarkModel(const KBookmark &root, CommandHistory *commandHistory, QObject *parent = nullptr); 45 void setRoot(const KBookmark &root); 46 47 ~KBookmarkModel() override; 48 49 KBookmarkManager *bookmarkManager(); 50 CommandHistory *commandHistory(); 51 52 enum AdditionalRoles { 53 // Note: use printf "0x%08X\n" $(($RANDOM*$RANDOM)) 54 // to define additional roles. 55 KBookmarkRole = 0x161BEC30, 56 }; 57 58 // reimplemented functions 59 QVariant data(const QModelIndex &index, int role) const override; 60 Qt::ItemFlags flags(const QModelIndex &index) const override; 61 QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const override; 62 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 63 QModelIndex parent(const QModelIndex &index) const override; 64 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 65 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 66 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 67 virtual void resetModel(); 68 69 QModelIndex indexForBookmark(const KBookmark &bk) const; 70 KBookmark bookmarkForIndex(const QModelIndex &index) const; 71 void emitDataChanged(const KBookmark &bk); 72 73 /// Call this before inserting items into the bookmark group 74 void beginInsert(const KBookmarkGroup &group, int first, int last); 75 /// Call this after item insertion is done 76 void endInsert(); 77 78 /// Remove the bookmark 79 void removeBookmark(const KBookmark &bookmark); 80 81 // drag and drop 82 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 83 QStringList mimeTypes() const override; 84 QMimeData *mimeData(const QModelIndexList &indexes) const override; 85 Qt::DropActions supportedDropActions() const override; 86 87 public Q_SLOTS: 88 void notifyManagers(const KBookmarkGroup &grp); 89 90 private: 91 class Private; 92 Private *const d; 93 }; 94 95 #endif 96