summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-05-30 11:34:17 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-06-04 20:55:31 +0200
commit35697c1ded0577e88e774917a8ead31d7445465a (patch)
treec1bd34898b36308e806cfe1d3beae5d90b8449e5 /tests
parentaf4f03f51fc647c48968e149799cd35ab161dc55 (diff)
Add QPdfDocument::pageLabel(int) and pageModel property
This API is available for both C++ and QML. The pageModel makes it easier to populate item-views with per-page information, such as thumbnails labeled with page labels. Fixes: QTBUG-102271 Change-Id: I70df481b378efed0327e7bb89a63c7669daecc70 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/pdf/qpdfdocument/test.pdfbin0 -> 76633 bytes
-rw-r--r--tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp11
-rw-r--r--tests/manual/quick/pdf/bookmarks-list.qml5
-rw-r--r--tests/manual/quick/pdf/bookmarks.qml4
-rw-r--r--tests/manual/quick/pdf/gridview.qml16
-rw-r--r--tests/manual/quick/pdf/listview.qml2
-rw-r--r--tests/manual/quick/pdf/pdfPageView.qml22
7 files changed, 42 insertions, 18 deletions
diff --git a/tests/auto/pdf/qpdfdocument/test.pdf b/tests/auto/pdf/qpdfdocument/test.pdf
new file mode 100644
index 000000000..0832dfbed
--- /dev/null
+++ b/tests/auto/pdf/qpdfdocument/test.pdf
Binary files differ
diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
index b44edc703..df437349e 100644
--- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
+++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
@@ -69,6 +69,7 @@ private slots:
void status();
void passwordClearedOnClose();
void metaData();
+ void pageLabels();
private:
void consistencyCheck(QPdfDocument &doc) const;
@@ -415,6 +416,16 @@ void tst_QPdfDocument::metaData()
QCOMPARE(doc.metaData(QPdfDocument::MetaDataField::ModificationDate).toDateTime(), QDateTime(QDate(2016, 8, 8), QTime(8, 3, 6), Qt::UTC));
}
+void tst_QPdfDocument::pageLabels()
+{
+ QPdfDocument doc;
+ QCOMPARE(doc.load(QFINDTESTDATA("test.pdf")), QPdfDocument::Error::None);
+ QCOMPARE(doc.pageCount(), 3);
+ QCOMPARE(doc.pageLabel(0), "Qt");
+ QCOMPARE(doc.pageLabel(1), "1");
+ QCOMPARE(doc.pageLabel(2), "i"); // i of the tiger!
+}
+
QTEST_MAIN(tst_QPdfDocument)
#include "tst_qpdfdocument.moc"
diff --git a/tests/manual/quick/pdf/bookmarks-list.qml b/tests/manual/quick/pdf/bookmarks-list.qml
index a4c030ea5..fd6c38b54 100644
--- a/tests/manual/quick/pdf/bookmarks-list.qml
+++ b/tests/manual/quick/pdf/bookmarks-list.qml
@@ -87,11 +87,10 @@ ApplicationWindow {
width: parent.width
text: model.title
background: Item { }
- onClicked: image.currentFrame = pageNumber
+ onClicked: image.currentFrame = page
}
model: PdfBookmarkModel {
document: root.doc
- structureMode: PdfBookmarkModel.ListMode
}
}
}
@@ -179,6 +178,6 @@ ApplicationWindow {
}
Text {
anchors { bottom: parent.bottom; right: parent.right; margins: 6 }
- text: "page " + (image.currentFrame + 1) + " of " + doc.pageCount
+ text: "page " + doc.pageLabel(image.currentFrame) + " of " + doc.pageCount
}
}
diff --git a/tests/manual/quick/pdf/bookmarks.qml b/tests/manual/quick/pdf/bookmarks.qml
index 0d7a84dee..230e3daf4 100644
--- a/tests/manual/quick/pdf/bookmarks.qml
+++ b/tests/manual/quick/pdf/bookmarks.qml
@@ -88,7 +88,7 @@ ApplicationWindow {
clip: true
delegate: TreeViewDelegate {
width: parent.width
- onClicked: image.currentFrame = pageNumber
+ onClicked: image.currentFrame = page
}
model: PdfBookmarkModel {
document: root.doc
@@ -189,6 +189,6 @@ ApplicationWindow {
}
Label {
anchors { bottom: parent.bottom; right: parent.right; margins: 6 }
- text: "page " + (image.currentFrame + 1) + " of " + doc.pageCount
+ text: "page " + doc.pageLabel(image.currentFrame) + " of " + doc.pageCount
}
}
diff --git a/tests/manual/quick/pdf/gridview.qml b/tests/manual/quick/pdf/gridview.qml
index 48e34732a..4ad9e4676 100644
--- a/tests/manual/quick/pdf/gridview.qml
+++ b/tests/manual/quick/pdf/gridview.qml
@@ -68,10 +68,13 @@ Window {
id: view
anchors.fill: parent
anchors.margins: 10
- model: doc.pageCount
+ model: doc.pageModel
cellWidth: cellSize
cellHeight: cellSize
delegate: Item {
+ required property int index
+ required property string label
+ required property size pointSize
width: view.cellWidth
height: view.cellHeight
Rectangle {
@@ -86,10 +89,11 @@ Window {
currentFrame: index
asynchronous: true
fillMode: Image.PreserveAspectFit
- property size naturalSize: doc.pagePointSize(index)
- property bool landscape: naturalSize.width > naturalSize.height
- width: landscape ? Math.min(view.cellWidth, naturalSize.width) : height * naturalSize.width / naturalSize.height
- height: landscape ? width * naturalSize.height / naturalSize.width : Math.min(view.cellHeight - pageNumber.height, naturalSize.height)
+ property bool landscape: pointSize.width > pointSize.height
+ width: landscape ? Math.min(view.cellWidth, pointSize.width)
+ : height * pointSize.width / pointSize.height
+ height: landscape ? width * pointSize.height / pointSize.width
+ : Math.min(view.cellHeight - pageNumber.height, pointSize.height)
sourceSize.width: width
sourceSize.height: height
}
@@ -98,7 +102,7 @@ Window {
id: pageNumber
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
- text: "Page " + (image.currentFrame + 1)
+ text: "Page " + label
}
}
}
diff --git a/tests/manual/quick/pdf/listview.qml b/tests/manual/quick/pdf/listview.qml
index 65da5d483..3201908ac 100644
--- a/tests/manual/quick/pdf/listview.qml
+++ b/tests/manual/quick/pdf/listview.qml
@@ -81,7 +81,7 @@ Window {
}
}
Text {
- text: "Page " + (image.currentFrame + 1)
+ text: "Page " + doc.pageLabel(image.currentFrame)
}
}
}
diff --git a/tests/manual/quick/pdf/pdfPageView.qml b/tests/manual/quick/pdf/pdfPageView.qml
index 393d1f774..7038e61d0 100644
--- a/tests/manual/quick/pdf/pdfPageView.qml
+++ b/tests/manual/quick/pdf/pdfPageView.qml
@@ -136,18 +136,28 @@ ApplicationWindow {
}
SpinBox {
id: currentPageSB
- from: 1
+ from: 0
to: document.pageCount
editable: true
- value: pageView.currentPage + 1
- onValueModified: pageView.goToPage(value - 1)
+ value: pageView.currentPage
+ onValueModified: pageView.goToPage(value)
+
+ textFromValue: function(value) { return document.pageLabel(value) }
+ valueFromText: function(text) {
+ for (var i = 0; i < document.pageCount; ++i) {
+ if (document.pageLabel(i).toLowerCase().indexOf(text.toLowerCase()) === 0)
+ return i
+ }
+ return spinBox.value
+ }
+
Shortcut {
sequence: StandardKey.MoveToPreviousPage
- onActivated: pageView.goToPage(currentPageSB.value - 2)
+ onActivated: pageView.goToPage(currentPageSB.value - 1)
}
Shortcut {
sequence: StandardKey.MoveToNextPage
- onActivated: pageView.goToPage(currentPageSB.value)
+ onActivated: pageView.goToPage(currentPageSB.value + 1)
}
}
ToolButton {
@@ -331,7 +341,7 @@ ApplicationWindow {
ScrollBar.vertical: ScrollBar { }
delegate: ItemDelegate {
width: parent ? parent.width : 0
- text: "page " + (page + 1) + ": " + contextBefore + pageView.searchString + contextAfter
+ text: "page " + document.pageLabel(page) + ": " + contextBefore + pageView.searchString + contextAfter
highlighted: ListView.isCurrentItem
onClicked: {
searchResultsList.currentIndex = index