diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-01-23 13:21:08 -0700 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-01-28 12:15:10 -0700 |
commit | 7b65afccc97194da47736141560a6fb6e38bba96 (patch) | |
tree | 9e299d45801e9d69c3e9390f7595480980c5ec7a | |
parent | e3af0e8ae86151214a1e285c7f3bd7d24efbdd35 (diff) |
Delay PdfMultiPageView.goTo[Page|Location] if called too early
PdfMultiPageView does not expose a property alias to TableView.rows;
we could call it pageCount, but we don't want to mislead users into
thinking that the view is the "source of truth" for how many pages
it's going to show. The document's pageCount is populated earlier,
and that's a problem only in such a case when it's too early to ask
the view to go to a particular page. So we work around it in the
view by treating these goTo functions as requests to be satisfied
as soon as it becomes possible.
Fixes: QTBUG-119416
Pick-to: 6.5
Change-Id: Ie2377fe6f2983b72e871b1be2afe4d0878f60841
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit e9a5b6e514996c059d52a857a5aef624afb80a0e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit d63c4dacd2b4ffa2608965ed7e49303b75c722ad)
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/pdfquick/PdfMultiPageView.qml | 22 | ||||
-rw-r--r-- | tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml | 18 | ||||
-rw-r--r-- | tests/auto/pdfquick/multipageview/tst_multipageview.cpp | 12 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/pdfquick/PdfMultiPageView.qml b/src/pdfquick/PdfMultiPageView.qml index 84c3e3181..cfc19c28b 100644 --- a/src/pdfquick/PdfMultiPageView.qml +++ b/src/pdfquick/PdfMultiPageView.qml @@ -159,6 +159,13 @@ Item { \sa PdfPageNavigator::jump(), currentPage */ function goToLocation(page, location, zoom) { + if (tableView.rows === 0) { + // save this request for later + tableView.pendingRow = page + tableView.pendingLocation = location + tableView.pendingZoom = zoom + return + } if (zoom > 0) { pageNavigator.jumping = true // don't call pageNavigator.update() because we will jump() instead root.renderScale = zoom @@ -309,6 +316,21 @@ Item { property real pageHolderWidth: Math.max(root.width, ((rot90 ? document?.maxPageHeight : document?.maxPageWidth) ?? 0) * root.renderScale) columnWidthProvider: function(col) { return document ? pageHolderWidth + vscroll.width + 2 : 0 } rowHeightProvider: function(row) { return (rot90 ? document.pagePointSize(row).width : document.pagePointSize(row).height) * root.renderScale } + + // delayed-jump feature in case the user called goToPage() or goToLocation() too early + property int pendingRow: -1 + property point pendingLocation + property real pendingZoom: -1 + onRowsChanged: { + if (rows > 0 && tableView.pendingRow >= 0) { + console.log(lcMPV, "initiating delayed jump to page", tableView.pendingRow, "loc", tableView.pendingLocation, "zoom", tableView.pendingZoom) + root.goToLocation(tableView.pendingRow, tableView.pendingLocation, tableView.pendingZoom) + tableView.pendingRow = -1 + tableView.pendingLocation = Qt.point(-1, -1) + tableView.pendingZoom = -1 + } + } + delegate: Rectangle { id: pageHolder color: tableView.debug ? "beige" : "transparent" diff --git a/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml b/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml new file mode 100644 index 000000000..ce74f5ed8 --- /dev/null +++ b/tests/auto/pdfquick/multipageview/data/jumpOnDocumentReady.qml @@ -0,0 +1,18 @@ +import QtQuick +import QtQuick.Pdf + +PdfMultiPageView { + id: view + width: 480 + height: 480 + + document: PdfDocument { + id: document + onStatusChanged: { + if(status === PdfDocument.Ready) + view.goToPage(2) + } + } + + Component.onCompleted: document.source = "bookmarksAndLinks.pdf" +} diff --git a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp index 9067fdbe3..b64cd47b1 100644 --- a/tests/auto/pdfquick/multipageview/tst_multipageview.cpp +++ b/tests/auto/pdfquick/multipageview/tst_multipageview.cpp @@ -30,6 +30,7 @@ private Q_SLOTS: void selectionAndClipboard(); void search(); void pinchDragPinch(); + void jumpOnDocumentReady(); public: enum NavigationAction { @@ -430,5 +431,16 @@ void tst_MultiPageView::pinchDragPinch() QTRY_COMPARE(image->status(), QQuickPdfPageImage::Ready); } +void tst_MultiPageView::jumpOnDocumentReady() // QTBUG-119416 +{ + QQuickView window; + QVERIFY(showView(window, testFileUrl("jumpOnDocumentReady.qml"))); + QQuickItem *pdfView = window.rootObject(); + QVERIFY(pdfView); + + // QML calls view.goToPage(2): verify that it eventually happens + QTRY_COMPARE(pdfView->property("currentPage").toInt(), 2); +} + QTEST_MAIN(tst_MultiPageView) #include "tst_multipageview.moc" |