File indexing completed on 2024-04-21 05:50:20
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005 Daniel Teske <teske@squorn.de> 0003 Copyright (C) 2010 David Faure <faure@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License as 0007 published by the Free Software Foundation; either version 2 of 0008 the License, or (at your option) version 3. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program. If not, see <http://www.gnu.org/licenses/> 0017 */ 0018 0019 #ifndef BOOKMARKMODEL_MODEL_H 0020 #define BOOKMARKMODEL_MODEL_H 0021 0022 #include "kbookmarkmodel_export.h" 0023 #include <QAbstractItemModel> 0024 0025 class CommandHistory; 0026 class KBookmarkGroup; 0027 class KBookmarkManager; 0028 class KBookmark; 0029 0030 class KBOOKMARKMODEL_EXPORT KBookmarkModel : public QAbstractItemModel 0031 { 0032 Q_OBJECT 0033 0034 enum ColumnIds { 0035 NameColumnId = 0, 0036 UrlColumnId = 1, 0037 CommentColumnId = 2, 0038 StatusColumnId = 3, 0039 LastColumnId = 3, 0040 NoOfColumnIds = LastColumnId + 1, 0041 }; 0042 0043 public: 0044 KBookmarkModel(const KBookmark &root, CommandHistory *commandHistory, QObject *parent = nullptr); 0045 void setRoot(const KBookmark &root); 0046 0047 ~KBookmarkModel() override; 0048 0049 KBookmarkManager *bookmarkManager(); 0050 CommandHistory *commandHistory(); 0051 0052 enum AdditionalRoles { 0053 // Note: use printf "0x%08X\n" $(($RANDOM*$RANDOM)) 0054 // to define additional roles. 0055 KBookmarkRole = 0x161BEC30, 0056 }; 0057 0058 // reimplemented functions 0059 QVariant data(const QModelIndex &index, int role) const override; 0060 Qt::ItemFlags flags(const QModelIndex &index) const override; 0061 QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const override; 0062 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0063 QModelIndex parent(const QModelIndex &index) const override; 0064 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0065 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0066 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0067 virtual void resetModel(); 0068 0069 QModelIndex indexForBookmark(const KBookmark &bk) const; 0070 KBookmark bookmarkForIndex(const QModelIndex &index) const; 0071 void emitDataChanged(const KBookmark &bk); 0072 0073 /// Call this before inserting items into the bookmark group 0074 void beginInsert(const KBookmarkGroup &group, int first, int last); 0075 /// Call this after item insertion is done 0076 void endInsert(); 0077 0078 /// Remove the bookmark 0079 void removeBookmark(const KBookmark &bookmark); 0080 0081 // drag and drop 0082 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0083 QStringList mimeTypes() const override; 0084 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0085 Qt::DropActions supportedDropActions() const override; 0086 0087 public Q_SLOTS: 0088 void notifyManagers(const KBookmarkGroup &grp); 0089 0090 private: 0091 class Private; 0092 Private *const d; 0093 }; 0094 0095 #endif