diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-03-30 18:38:03 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-04-06 22:37:55 +0200 |
commit | 303c25e79ab12d5d48523aa890f2091e98d3b560 (patch) | |
tree | c98408c22ccb2b5312dc967131362ae7885c587e /src/pdf | |
parent | 299c67a91561a1b53646cbdbdfd4b86494d71ec8 (diff) | |
download | qtwebengine-303c25e79ab12d5d48523aa890f2091e98d3b560.tar.gz |
Expose PdfBookmarkModel to QML; use with TreeView in manual test
- TreeViewDelegate uses Qt::DisplayRole by default, so we need it to map
to the text we want to display, in the roleNames() hash. But asking
explicitly for the TitleRole is OK too (as before).
- In QML, the document property must be a QQuickPdfDocument, whereas in
C++ QPdfDocument is used directly; so we shadow the document property
for QML. Therefore QML_EXTENDED(QPdfBookmarkModel) does not work: we
need real inheritance to get real property shadowing.
- Added tests/manual/quick/pdf/bookmarks.qml with a TreeView
- Clicking the TreeViewDelegate expands the subtree if there is one; but
it also goes to the destination in the PDF, whether there is a subtree
or not. But this can be fixed in TreeViewDelegate.
- Added tests/manual/quick/pdf/bookmarks-list.qml to test the case with
structureMode: PdfBookmarkModel.ListMode (using ListView)
test.pdf is uninteresting for this purpose: there is only one bookmark;
but you can run these tests with an optional argument like this:
qml bookmarks.qml -style Material -- ~/path/to/some.pdf
qml bookmarks-list.qml -- ~/path/to/some.pdf
Change-Id: I65d12a3d9b8ef0f0fa2bc99003430324fd759dcb
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/qpdfbookmarkmodel.cpp | 3 | ||||
-rw-r--r-- | src/pdf/qpdfbookmarkmodel.h | 6 | ||||
-rw-r--r-- | src/pdf/qpdfdocument.h | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/pdf/qpdfbookmarkmodel.cpp b/src/pdf/qpdfbookmarkmodel.cpp index 04e696c9e..31c98a90b 100644 --- a/src/pdf/qpdfbookmarkmodel.cpp +++ b/src/pdf/qpdfbookmarkmodel.cpp @@ -272,7 +272,7 @@ int QPdfBookmarkModel::columnCount(const QModelIndex &parent) const QHash<int, QByteArray> QPdfBookmarkModel::roleNames() const { - QHash<int, QByteArray> names; + QHash<int, QByteArray> names = QAbstractItemModel::roleNames(); names[TitleRole] = "title"; names[LevelRole] = "level"; @@ -288,6 +288,7 @@ QVariant QPdfBookmarkModel::data(const QModelIndex &index, int role) const const BookmarkNode *node = static_cast<BookmarkNode*>(index.internalPointer()); switch (role) { + case Qt::DisplayRole: case TitleRole: return node->title(); case LevelRole: diff --git a/src/pdf/qpdfbookmarkmodel.h b/src/pdf/qpdfbookmarkmodel.h index ff1e30a4e..7db2f03da 100644 --- a/src/pdf/qpdfbookmarkmodel.h +++ b/src/pdf/qpdfbookmarkmodel.h @@ -58,15 +58,15 @@ class Q_PDF_EXPORT QPdfBookmarkModel : public QAbstractItemModel public: enum StructureMode { - TreeMode, + TreeMode = 1, ListMode }; Q_ENUM(StructureMode) enum Role { - TitleRole = Qt::DisplayRole, - LevelRole = Qt::UserRole, + TitleRole = Qt::UserRole, + LevelRole, PageNumberRole }; Q_ENUM(Role) diff --git a/src/pdf/qpdfdocument.h b/src/pdf/qpdfdocument.h index b91ca13ef..9301be868 100644 --- a/src/pdf/qpdfdocument.h +++ b/src/pdf/qpdfdocument.h @@ -128,7 +128,7 @@ Q_SIGNALS: void pageCountChanged(int pageCount); private: - friend class QPdfBookmarkModelPrivate; + friend struct QPdfBookmarkModelPrivate; friend class QPdfFile; friend class QPdfLinkModelPrivate; friend class QPdfSearchModel; |