summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-04-20 09:02:50 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-06-04 20:55:31 +0200
commit0de16e9a20366b02b544e2279461612c69cdf11b (patch)
tree4ea1fca411803d5a2dea540154b21ece219af5dd /examples
parent33f6047ef17421fd07d0350fedcfbd049e31fe28 (diff)
Redefine PdfSearchModel.currentResult as document-based; use PdfLink
PdfSearchModel.currentResult is now the index within the whole list of search results, rather than starting over from 0 on each page. This simplifies some code. The way that PdfMultiPageView uses PdfSearchModel, the currentPage property is read-only: it tells the page of currentResult (which we need in the view, because each page has the ability to show a current-search-result highlight shape, but only one page actually needs to show it). The controls in a viewer to iterate search results (up and down arrows in the footer) simply increment and derement currentResult; the currentPage property gets updated to tell the view which page currently holds currentResult; and the ListView highlight follows along in the sidebar too, because ListView.currentIndex is now bound to searchModel.currentResult. But in PdfScrollablePageView, we still need to bind the currentPage property, to get the currentPageBoundingPolygons property updated when we switch pages. Since that viewer only sees one page at a time, it's much more declarative to do it that way, rather than calling the invokable boundingPolygonsOnPage(int) function. Bindings get updated on their own; whereas in PdfMultiPageView it's a bit inelegant that we need to call boundingPolygonsOnPage() repeatedly, at the right times so that the highlights are never shown in the wrong places at the wrong time. It could be avoided if we had a separate per-page model object to filter the results from the main PdfSearchModel; but that would add significant API complexity, and perhaps be too confusing for anyone who tries to re-implement a QML-based viewer component. The current search result highlight now stays on the page where the user left it: scrolling manually to another page will no longer choose a current result on the new page, as it did before. This is more consistent with typical applications. A currentResultLink property is added, to make it easy to call PdfPageNavigator.jump(link), thus passing along the QPdfLink.rectangles. The same link object gets re-emitted in the PdfPageNavigator.jumped signal to tell the view to scroll in such a way as to get those rectangles visible in the viewport, via TableView.positionViewAtCell(). There are a couple of drive-by fixes: QQuickPdfSearchModel::documentChanged() doesn't need to be declared, because we are using the signal inherited from QPdfSearchModel. And const-correctness is improved in the implementation of boundingPolygonsOnPage(). [ChangeLog][QtPDF] PdfSearchModel.currentResult is now the result index within the whole set of search results rather than on currentPage; and changing currentPage no longer makes currentResult change. In the views, this means the current highlighted search result stays on the same page even when the user views a different page. Change-Id: I96957f50e703f62101b3d3c708ff5f27b162cd8d Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/pdf/multipage/viewer.qml9
-rw-r--r--examples/pdf/pdfviewer/viewer.qml18
2 files changed, 12 insertions, 15 deletions
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml
index 0e9855459..ecf7d5e20 100644
--- a/examples/pdf/multipage/viewer.qml
+++ b/examples/pdf/multipage/viewer.qml
@@ -308,13 +308,12 @@ ApplicationWindow {
id: searchResultsList
implicitHeight: parent.height
model: view.searchModel
+ currentIndex: view.searchModel.currentResult
ScrollBar.vertical: ScrollBar { }
delegate: ItemDelegate {
id: resultDelegate
required property int index
required property int page
- required property int indexOnPage
- required property point location
required property string contextBefore
required property string contextAfter
width: parent ? parent.width : 0
@@ -344,11 +343,7 @@ ApplicationWindow {
}
}
highlighted: ListView.isCurrentItem
- onClicked: {
- searchResultsList.currentIndex = resultDelegate.index
- view.goToLocation(resultDelegate.page, resultDelegate.location)
- view.searchModel.currentResult = resultDelegate.indexOnPage
- }
+ onClicked: view.searchModel.currentResult = resultDelegate.index
}
}
TreeView {
diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml
index 1a9a4fbe4..5ba2dc444 100644
--- a/examples/pdf/pdfviewer/viewer.qml
+++ b/examples/pdf/pdfviewer/viewer.qml
@@ -254,17 +254,23 @@ ApplicationWindow {
anchors.fill: parent
anchors.margins: 2
model: view.searchModel
+ currentIndex: view.searchModel.currentResult
ScrollBar.vertical: ScrollBar { }
delegate: ItemDelegate {
+ id: resultDelegate
+ required property int index
+ required property int page
+ required property string contextBefore
+ required property string contextAfter
width: parent ? parent.width : 0
RowLayout {
anchors.fill: parent
spacing: 0
Label {
- text: "Page " + (page + 1) + ": "
+ text: "Page " + (resultDelegate.page + 1) + ": "
}
Label {
- text: contextBefore
+ text: resultDelegate.contextBefore
elide: Text.ElideLeft
horizontalAlignment: Text.AlignRight
Layout.fillWidth: true
@@ -276,18 +282,14 @@ ApplicationWindow {
width: implicitWidth
}
Label {
- text: contextAfter
+ text: resultDelegate.contextAfter
elide: Text.ElideRight
Layout.fillWidth: true
Layout.preferredWidth: parent.width / 2
}
}
highlighted: ListView.isCurrentItem
- onClicked: {
- searchResultsList.currentIndex = index
- view.goToLocation(page, location, 0)
- view.searchModel.currentResult = indexOnPage
- }
+ onClicked: view.searchModel.currentResult = resultDelegate.index
}
}
}