[1f4adec] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2014-2015 Adam Reichold |
---|
| 4 | |
---|
| 5 | This file is part of qpdfview. |
---|
| 6 | |
---|
| 7 | qpdfview is free software: you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU General Public License as published by |
---|
| 9 | the Free Software Foundation, either version 2 of the License, or |
---|
| 10 | (at your option) any later version. |
---|
| 11 | |
---|
| 12 | qpdfview is distributed in the hope that it will be useful, |
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | GNU General Public License for more details. |
---|
| 16 | |
---|
| 17 | You should have received a copy of the GNU General Public License |
---|
| 18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifndef BOOKMARKMODEL_H |
---|
| 23 | #define BOOKMARKMODEL_H |
---|
| 24 | |
---|
| 25 | #include <QAbstractListModel> |
---|
| 26 | |
---|
| 27 | #include <QDateTime> |
---|
| 28 | #include <QHash> |
---|
| 29 | |
---|
| 30 | namespace qpdfview |
---|
| 31 | { |
---|
| 32 | |
---|
| 33 | struct BookmarkItem |
---|
| 34 | { |
---|
| 35 | int page; |
---|
| 36 | |
---|
| 37 | QString label; |
---|
| 38 | QString comment; |
---|
| 39 | QDateTime modified; |
---|
| 40 | |
---|
| 41 | BookmarkItem(int page, const QString& label = QString(), const QString& comment = QString(), const QDateTime& modified = QDateTime::currentDateTime()) : |
---|
| 42 | page(page), |
---|
| 43 | label(label), |
---|
| 44 | comment(comment), |
---|
| 45 | modified(modified) {} |
---|
| 46 | |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | class BookmarkModel : public QAbstractListModel |
---|
| 50 | { |
---|
| 51 | Q_OBJECT |
---|
| 52 | |
---|
| 53 | public: |
---|
| 54 | static BookmarkModel* fromPath(const QString& path, bool create = false); |
---|
| 55 | |
---|
| 56 | static QList< QString > knownPaths(); |
---|
| 57 | |
---|
| 58 | static void forgetPath(const QString& path); |
---|
| 59 | static void forgetAllPaths(); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | bool isEmpty() const { return m_bookmarks.isEmpty(); } |
---|
| 63 | |
---|
| 64 | void addBookmark(const BookmarkItem& bookmark); |
---|
| 65 | void removeBookmark(const BookmarkItem& bookmark); |
---|
| 66 | |
---|
| 67 | void findBookmark(BookmarkItem& bookmark) const; |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | enum |
---|
| 71 | { |
---|
| 72 | PageRole = Qt::UserRole + 1, |
---|
| 73 | LabelRole, |
---|
| 74 | CommentRole, |
---|
| 75 | ModifiedRole |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | Qt::ItemFlags flags(const QModelIndex&) const; |
---|
| 79 | |
---|
| 80 | int columnCount(const QModelIndex& parent = QModelIndex()) const; |
---|
| 81 | int rowCount(const QModelIndex& parent = QModelIndex()) const; |
---|
| 82 | |
---|
| 83 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; |
---|
| 84 | |
---|
| 85 | private: |
---|
| 86 | Q_DISABLE_COPY(BookmarkModel) |
---|
| 87 | |
---|
| 88 | static QHash< QString, BookmarkModel* > s_instances; |
---|
| 89 | BookmarkModel(QObject* parent = 0); |
---|
| 90 | |
---|
| 91 | QList< BookmarkItem > m_bookmarks; |
---|
| 92 | |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | } // qpdfview |
---|
| 96 | |
---|
| 97 | #endif // BOOKMARKMODEL_H |
---|