diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-04-20 09:02:50 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-06-04 20:55:31 +0200 |
commit | 0de16e9a20366b02b544e2279461612c69cdf11b (patch) | |
tree | 4ea1fca411803d5a2dea540154b21ece219af5dd /src/pdf | |
parent | 33f6047ef17421fd07d0350fedcfbd049e31fe28 (diff) | |
download | qtwebengine-0de16e9a20366b02b544e2279461612c69cdf11b.tar.gz |
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 'src/pdf')
-rw-r--r-- | src/pdf/qpdfsearchmodel.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/pdf/qpdfsearchmodel.cpp b/src/pdf/qpdfsearchmodel.cpp index d13ab6c75..d1fc0d190 100644 --- a/src/pdf/qpdfsearchmodel.cpp +++ b/src/pdf/qpdfsearchmodel.cpp @@ -360,6 +360,8 @@ bool QPdfSearchModelPrivate::doSearch(int page) QPdfSearchModelPrivate::PageAndIndex QPdfSearchModelPrivate::pageAndIndexForResult(int resultIndex) { + if (pagesSearched.isEmpty()) + return {-1, -1}; const int pageCount = document->pageCount(); int totalSoFar = 0; int previousTotalSoFar = 0; |