summaryrefslogtreecommitdiffstats
path: root/src/pdf
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2023-07-04 21:04:15 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2023-08-02 20:07:43 +0200
commitc439786616ade9436a599806e67199ffa93f9c91 (patch)
treed0d7a7fd1a354f932543007b0114599a285716af /src/pdf
parente9eadbb2772d22bec863ee331521f51e78541801 (diff)
Fix PDF page label search: don't trim in QPdfDocument::pageIndexForLabel()
In the 6.6 header review it was suggested that the caller should do the trimming if necessary; avoiding it here is more efficient. So far the only caller is QPdfPageSelector (although we may need to implement the same feature in the Quick PDF examples at some point). Typing page labels into QPdfPageSelector didn't work because QPdfPageSelector::validate() was not overridden. Now we reuse pageIndexForLabel() for that too: if the label is found, it's valid; if the label is not found, we just assume the user is not done typing yet. There's no QPdfDocument function to do a substring search for page labels, or to return the whole list of them either. It seems they can only be gotten one-at-a-time via the FPDF_GetPageLabel function. Now it actually works in the widget-based example qtwebengine/examples/pdfwidgets/pdfviewer/pdfviewer: if you load a document that has some Roman-numeral-numbered preface pages and type e.g. " iii" into the spinbox, it jumps to page iii. Fixes: QTBUG-115476 Pick-to: 6.6 Change-Id: I070338effee1bbf916581c5ba964367424b786b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/qpdfdocument.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index 695b30c59..e2309be9c 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -831,9 +831,8 @@ QString QPdfDocument::pageLabel(int page)
*/
int QPdfDocument::pageIndexForLabel(const QString &label)
{
- const auto trimmed = label.trimmed();
for (int i = 0; i < d->pageCount; ++i) {
- if (pageLabel(i) == trimmed)
+ if (pageLabel(i) == label)
return i;
}
return -1;