From 212a78fe75f59d4d0d580e0064991c7043785f3e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Sun, 14 Dec 2014 12:51:38 +0100 Subject: Re-organize the build system to turn this into a full-fledged module --- tests/auto/pdf/cmake/cmake.pro | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/auto/pdf/cmake/cmake.pro (limited to 'tests') diff --git a/tests/auto/pdf/cmake/cmake.pro b/tests/auto/pdf/cmake/cmake.pro new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From ec484f4756c8814a11420ad48c0bcc1e04b92910 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 12:50:13 +0100 Subject: Implement basic document loading from a file --- tests/auto/pdf/pdf.pro | 2 ++ tests/auto/pdf/qpdfdocument/qpdfdocument.pro | 6 ++++ tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 46 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/auto/pdf/pdf.pro create mode 100644 tests/auto/pdf/qpdfdocument/qpdfdocument.pro create mode 100644 tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp (limited to 'tests') diff --git a/tests/auto/pdf/pdf.pro b/tests/auto/pdf/pdf.pro new file mode 100644 index 000000000..41c081c3e --- /dev/null +++ b/tests/auto/pdf/pdf.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = qpdfdocument diff --git a/tests/auto/pdf/qpdfdocument/qpdfdocument.pro b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro new file mode 100644 index 000000000..28e56e0bd --- /dev/null +++ b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qpdfdocument +QT += pdf printsupport testlib +macx:CONFIG -= app_bundle +SOURCES += tst_qpdfdocument.cpp + diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp new file mode 100644 index 000000000..080f8085b --- /dev/null +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -0,0 +1,46 @@ + +#include + +#include +#include +#include +#include + +class tst_QPdfDocument: public QObject +{ + Q_OBJECT +public: + +private slots: + void pageCount(); +}; + + +void tst_QPdfDocument::pageCount() +{ + QTemporaryFile tempPdf; + tempPdf.setAutoRemove(true); + QVERIFY(tempPdf.open()); + { + QPrinter printer; + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(tempPdf.fileName()); + + { + QPainter painter(&printer); + painter.drawText(0, 0, QStringLiteral("Hello Page 1")); + printer.newPage(); + painter.drawText(0, 0, QStringLiteral("Hello Page 2")); + } + } + + QPdfDocument doc; + QCOMPARE(doc.pageCount(), 0); + QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 2); +} + +QTEST_MAIN(tst_QPdfDocument) + +#include "tst_qpdfdocument.moc" + -- cgit v1.2.3 From c03b6371db5c82cb19a5122a3159e46fab2d3a38 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 13:34:00 +0100 Subject: Added basic rendering and page size getter --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 080f8085b..f91b407bb 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -21,16 +21,20 @@ void tst_QPdfDocument::pageCount() QTemporaryFile tempPdf; tempPdf.setAutoRemove(true); QVERIFY(tempPdf.open()); + + QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); + { QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(tempPdf.fileName()); + printer.setPageLayout(layout); { QPainter painter(&printer); - painter.drawText(0, 0, QStringLiteral("Hello Page 1")); + painter.drawText(100, 100, QStringLiteral("Hello Page 1")); printer.newPage(); - painter.drawText(0, 0, QStringLiteral("Hello Page 2")); + painter.drawText(100, 100, QStringLiteral("Hello Page 2")); } } @@ -38,6 +42,8 @@ void tst_QPdfDocument::pageCount() QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); + + QCOMPARE(doc.pageSize(0).toSize(), layout.fullRectPoints().size()); } QTEST_MAIN(tst_QPdfDocument) -- cgit v1.2.3 From edcffeb3e4c1a81ab86d997b8721dbb67a2ae9c4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 16:13:52 +0100 Subject: Allow loading documents synchronously from a QIODevice --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 49 ++++++++++++++++-------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index f91b407bb..a51c17296 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -13,37 +13,52 @@ public: private slots: void pageCount(); + void loadFromIODevice(); }; +struct TemporaryPdf: public QTemporaryFile +{ + TemporaryPdf(); + QPageLayout pageLayout; +}; -void tst_QPdfDocument::pageCount() + +TemporaryPdf::TemporaryPdf() { - QTemporaryFile tempPdf; - tempPdf.setAutoRemove(true); - QVERIFY(tempPdf.open()); + open(); + pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); - QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); + QPrinter printer; + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName()); + printer.setPageLayout(pageLayout); { - QPrinter printer; - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(tempPdf.fileName()); - printer.setPageLayout(layout); - - { - QPainter painter(&printer); - painter.drawText(100, 100, QStringLiteral("Hello Page 1")); - printer.newPage(); - painter.drawText(100, 100, QStringLiteral("Hello Page 2")); - } + QPainter painter(&printer); + painter.drawText(100, 100, QStringLiteral("Hello Page 1")); + printer.newPage(); + painter.drawText(100, 100, QStringLiteral("Hello Page 2")); } +} + +void tst_QPdfDocument::pageCount() +{ + TemporaryPdf tempPdf; QPdfDocument doc; QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); - QCOMPARE(doc.pageSize(0).toSize(), layout.fullRectPoints().size()); + QCOMPARE(doc.pageSize(0).toSize(), tempPdf.pageLayout.fullRectPoints().size()); +} + +void tst_QPdfDocument::loadFromIODevice() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + QCOMPARE(doc.load(&tempPdf), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 2); } QTEST_MAIN(tst_QPdfDocument) -- cgit v1.2.3 From 09ad4d74cea40dd3d88c0a39b1dcbc8db5347c6e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 17:40:41 +0100 Subject: Provide async loading through QNetworkReply --- tests/auto/pdf/qpdfdocument/qpdfdocument.pro | 2 +- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 44 +++++++++++++++++++----- 2 files changed, 36 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/qpdfdocument.pro b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro index 28e56e0bd..8382a25e3 100644 --- a/tests/auto/pdf/qpdfdocument/qpdfdocument.pro +++ b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qpdfdocument -QT += pdf printsupport testlib +QT += pdf printsupport testlib network macx:CONFIG -= app_bundle SOURCES += tst_qpdfdocument.cpp diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index a51c17296..c0fe93cef 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include class tst_QPdfDocument: public QObject { @@ -14,6 +17,7 @@ public: private slots: void pageCount(); void loadFromIODevice(); + void loadAsync(); }; struct TemporaryPdf: public QTemporaryFile @@ -28,17 +32,21 @@ TemporaryPdf::TemporaryPdf() open(); pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); - QPrinter printer; - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(fileName()); - printer.setPageLayout(pageLayout); - { - QPainter painter(&printer); - painter.drawText(100, 100, QStringLiteral("Hello Page 1")); - printer.newPage(); - painter.drawText(100, 100, QStringLiteral("Hello Page 2")); + QPrinter printer; + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName()); + printer.setPageLayout(pageLayout); + + { + QPainter painter(&printer); + painter.drawText(100, 100, QStringLiteral("Hello Page 1")); + printer.newPage(); + painter.drawText(100, 100, QStringLiteral("Hello Page 2")); + } } + + seek(0); } void tst_QPdfDocument::pageCount() @@ -61,6 +69,24 @@ void tst_QPdfDocument::loadFromIODevice() QCOMPARE(doc.pageCount(), 2); } +void tst_QPdfDocument::loadAsync() +{ + TemporaryPdf tempPdf; + + QNetworkAccessManager nam; + + QUrl url = QUrl::fromLocalFile(tempPdf.fileName()); + QScopedPointer reply(nam.get(QNetworkRequest(url))); + + QPdfDocument doc; + QSignalSpy readySpy(&doc, SIGNAL(documentReady())); + + doc.loadAsynchronously(reply.data()); + + QCOMPARE(readySpy.count(), 1); + QCOMPARE(doc.pageCount(), 2); +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" -- cgit v1.2.3 From 5406099863d5dfcf91a9ae23b217441d9058687f Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 23:44:27 +0100 Subject: Keep reading until all pages are available --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index c0fe93cef..306591208 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -79,11 +79,13 @@ void tst_QPdfDocument::loadAsync() QScopedPointer reply(nam.get(QNetworkRequest(url))); QPdfDocument doc; - QSignalSpy readySpy(&doc, SIGNAL(documentReady())); + QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); + QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); doc.loadAsynchronously(reply.data()); - QCOMPARE(readySpy.count(), 1); + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); QCOMPARE(doc.pageCount(), 2); } -- cgit v1.2.3 From 55b863f2dd2773290c63259c3835b19dcb277098 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 15 Dec 2014 23:54:10 +0100 Subject: Provide unit test for password protected PDFs --- tests/auto/pdf/qpdfdocument/pdf-sample.protected.pdf | Bin 0 -> 9138 bytes tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/auto/pdf/qpdfdocument/pdf-sample.protected.pdf (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/pdf-sample.protected.pdf b/tests/auto/pdf/qpdfdocument/pdf-sample.protected.pdf new file mode 100644 index 000000000..d76fdd1a6 Binary files /dev/null and b/tests/auto/pdf/qpdfdocument/pdf-sample.protected.pdf differ diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 306591208..6ebd1979f 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -18,6 +18,7 @@ private slots: void pageCount(); void loadFromIODevice(); void loadAsync(); + void password(); }; struct TemporaryPdf: public QTemporaryFile @@ -89,6 +90,16 @@ void tst_QPdfDocument::loadAsync() QCOMPARE(doc.pageCount(), 2); } +void tst_QPdfDocument::password() +{ + QPdfDocument doc; + QCOMPARE(doc.pageCount(), 0); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf"), QStringLiteral("WrongPassword")), QPdfDocument::IncorrectPasswordError); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf"), QStringLiteral("Qt")), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 1); +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" -- cgit v1.2.3 From 8d1e0d331b91cafa4e5f5b189e7dfee7ddb9b276 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 16 Dec 2014 00:51:08 +0100 Subject: Clean up the loading Unify the load API and implementation to always go through FPDFAvail. --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 6ebd1979f..336c6e8d9 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -66,7 +66,12 @@ void tst_QPdfDocument::loadFromIODevice() { TemporaryPdf tempPdf; QPdfDocument doc; - QCOMPARE(doc.load(&tempPdf), QPdfDocument::NoError); + QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); + QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); + doc.load(&tempPdf); + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(doc.error(), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); } @@ -83,7 +88,7 @@ void tst_QPdfDocument::loadAsync() QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); - doc.loadAsynchronously(reply.data()); + doc.load(reply.data()); QCOMPARE(startedSpy.count(), 1); QCOMPARE(finishedSpy.count(), 1); @@ -95,8 +100,10 @@ void tst_QPdfDocument::password() QPdfDocument doc; QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); - QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf"), QStringLiteral("WrongPassword")), QPdfDocument::IncorrectPasswordError); - QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf"), QStringLiteral("Qt")), QPdfDocument::NoError); + doc.setPassword(QStringLiteral("WrongPassword")); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); + doc.setPassword(QStringLiteral("Qt")); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 1); } -- cgit v1.2.3 From d76e133bd1389f83b26e3de5091b68b9dd0a90dc Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 25 Jul 2016 11:44:44 +0200 Subject: Skip build of auto-test when print support is disabled in the Qt build Change-Id: I86bd5779ae4fee7dfba0b7a2121128120dbe3a5b Reviewed-by: Tobias Koenig --- tests/auto/pdf/pdf.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/pdf/pdf.pro b/tests/auto/pdf/pdf.pro index 41c081c3e..bb4d02075 100644 --- a/tests/auto/pdf/pdf.pro +++ b/tests/auto/pdf/pdf.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qpdfdocument +qtHaveModule(printsupport): SUBDIRS = qpdfdocument -- cgit v1.2.3 From 40dc7d593ed95988130eaa8abde33e20fbfc50a3 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Sat, 6 Aug 2016 20:30:22 +0200 Subject: Add close() method to QPdfDocument The close() method will close an open document and emit the aboutToBeClosed() signal, so that other component, which keep a pointer to QPdfDocument, can react to it. Change-Id: I93200eb0b4bf96479fc114b43c9f6f2af4d15ffa Reviewed-by: Simon Hausmann --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 336c6e8d9..ef00bdbeb 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -19,6 +19,9 @@ private slots: void loadFromIODevice(); void loadAsync(); void password(); + void close(); + void loadAfterClose(); + void closeOnDestroy(); }; struct TemporaryPdf: public QTemporaryFile @@ -107,6 +110,71 @@ void tst_QPdfDocument::password() QCOMPARE(doc.pageCount(), 1); } +void tst_QPdfDocument::close() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + + QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + + doc.load(&tempPdf); + QCOMPARE(aboutToBeClosedSpy.count(), 0); + doc.close(); + QCOMPARE(aboutToBeClosedSpy.count(), 1); + QCOMPARE(doc.pageCount(), 0); +} + +void tst_QPdfDocument::loadAfterClose() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + + QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + + doc.load(&tempPdf); + QCOMPARE(aboutToBeClosedSpy.count(), 0); + doc.close(); + QCOMPARE(aboutToBeClosedSpy.count(), 1); + + QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); + QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); + doc.load(&tempPdf); + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(doc.error(), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 2); +} + +void tst_QPdfDocument::closeOnDestroy() +{ + TemporaryPdf tempPdf; + + // deleting an open document should automatically close it + { + QPdfDocument *doc = new QPdfDocument; + + QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); + doc->load(&tempPdf); + + delete doc; + + QCOMPARE(aboutToBeClosedSpy.count(), 1); + } + + // deleting a closed document should not emit any signal + { + QPdfDocument *doc = new QPdfDocument; + doc->load(&tempPdf); + doc->close(); + + QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); + + delete doc; + + QCOMPARE(aboutToBeClosedSpy.count(), 0); + } +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" -- cgit v1.2.3 From 728414509b8f370c2e94baef06c85934d902ee3d Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Sat, 6 Aug 2016 20:38:59 +0200 Subject: Add passwordChanged() signal to QPdfDocument The passwordChanged() signal is emitted whenever the password on the document is changed. Change-Id: I8c35274dba7160b81555eac5bbda37d47cb8c9b7 Reviewed-by: Simon Hausmann --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index ef00bdbeb..41b34ff17 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -22,6 +22,7 @@ private slots: void close(); void loadAfterClose(); void closeOnDestroy(); + void passwordClearedOnClose(); }; struct TemporaryPdf: public QTemporaryFile @@ -101,11 +102,16 @@ void tst_QPdfDocument::loadAsync() void tst_QPdfDocument::password() { QPdfDocument doc; + QSignalSpy passwordChangedSpy(&doc, SIGNAL(passwordChanged())); + QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); + QCOMPARE(passwordChangedSpy.count(), 0); doc.setPassword(QStringLiteral("WrongPassword")); + QCOMPARE(passwordChangedSpy.count(), 1); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); doc.setPassword(QStringLiteral("Qt")); + QCOMPARE(passwordChangedSpy.count(), 2); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 1); } @@ -175,6 +181,27 @@ void tst_QPdfDocument::closeOnDestroy() } } +void tst_QPdfDocument::passwordClearedOnClose() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + + QSignalSpy passwordChangedSpy(&doc, SIGNAL(passwordChanged())); + + doc.setPassword(QStringLiteral("Qt")); + QCOMPARE(passwordChangedSpy.count(), 1); + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::NoError); + passwordChangedSpy.clear(); + + doc.close(); // password is cleared on close + QCOMPARE(passwordChangedSpy.count(), 1); + passwordChangedSpy.clear(); + + doc.load(&tempPdf); + doc.close(); // signal is not emitted if password didn't change + QCOMPARE(passwordChangedSpy.count(), 0); +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" -- cgit v1.2.3 From 7fe31a05db2f807e61c2878a6d5f429f3212b0b7 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 1 Dec 2015 13:12:14 +0100 Subject: Add metaData() accessor method to QPdfDocument Change-Id: Ib25ae8940ff8a35627093031a82c1f25c7c940fc Reviewed-by: Simon Hausmann --- .../auto/pdf/qpdfdocument/pdf-sample.metadata.pdf | Bin 0 -> 9298 bytes tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 28 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/auto/pdf/qpdfdocument/pdf-sample.metadata.pdf (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/pdf-sample.metadata.pdf b/tests/auto/pdf/qpdfdocument/pdf-sample.metadata.pdf new file mode 100644 index 000000000..c3350ba5f Binary files /dev/null and b/tests/auto/pdf/qpdfdocument/pdf-sample.metadata.pdf differ diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 41b34ff17..b4e989801 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -23,6 +23,7 @@ private slots: void loadAfterClose(); void closeOnDestroy(); void passwordClearedOnClose(); + void metaData(); }; struct TemporaryPdf: public QTemporaryFile @@ -202,6 +203,33 @@ void tst_QPdfDocument::passwordClearedOnClose() QCOMPARE(passwordChangedSpy.count(), 0); } +void tst_QPdfDocument::metaData() +{ + QPdfDocument doc; + + // a closed document does not return any meta data + QCOMPARE(doc.metaData(QPdfDocument::Title).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::Subject).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::Author).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::Keywords).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::Producer).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::Creator).toString(), QString()); + QCOMPARE(doc.metaData(QPdfDocument::CreationDate).toDateTime(), QDateTime()); + QCOMPARE(doc.metaData(QPdfDocument::ModificationDate).toDateTime(), QDateTime()); + + QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.metadata.pdf")), QPdfDocument::NoError); + + // check for proper meta data from sample document + QCOMPARE(doc.metaData(QPdfDocument::Title).toString(), QString::fromLatin1("Qt PDF Unit Test Document")); + QCOMPARE(doc.metaData(QPdfDocument::Subject).toString(), QString::fromLatin1("A test for meta data access")); + QCOMPARE(doc.metaData(QPdfDocument::Author).toString(), QString::fromLatin1("John Doe")); + QCOMPARE(doc.metaData(QPdfDocument::Keywords).toString(), QString::fromLatin1("meta data keywords")); + QCOMPARE(doc.metaData(QPdfDocument::Producer).toString(), QString::fromLatin1("LibreOffice 5.1")); + QCOMPARE(doc.metaData(QPdfDocument::Creator).toString(), QString::fromLatin1("Writer")); + QCOMPARE(doc.metaData(QPdfDocument::CreationDate).toDateTime(), QDateTime(QDate(2016, 8, 7), QTime(7, 3, 6), Qt::UTC)); + QCOMPARE(doc.metaData(QPdfDocument::ModificationDate).toDateTime(), QDateTime(QDate(2016, 8, 8), QTime(8, 3, 6), Qt::UTC)); +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" -- cgit v1.2.3 From 4c75307a97d25ee01a41f80ec116d7ef328fdf3d Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Tue, 9 Aug 2016 19:25:47 +0200 Subject: Refactor the state handling of QPdfDocument Introduce a status property, which describes the current status of the QPdfDocument during loading/closing workflow. Change-Id: I2c095c41cfaacb4cd325682def71f80ffe6ab6d9 Reviewed-by: Shawn Rutledge --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 128 +++++++++++++++++++---- 1 file changed, 106 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index b4e989801..96619e5e0 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -12,7 +12,12 @@ class tst_QPdfDocument: public QObject { Q_OBJECT + public: + tst_QPdfDocument() + { + qRegisterMetaType(); + } private slots: void pageCount(); @@ -22,6 +27,7 @@ private slots: void close(); void loadAfterClose(); void closeOnDestroy(); + void status(); void passwordClearedOnClose(); void metaData(); }; @@ -71,11 +77,11 @@ void tst_QPdfDocument::loadFromIODevice() { TemporaryPdf tempPdf; QPdfDocument doc; - QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); - QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); + QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); doc.load(&tempPdf); - QCOMPARE(startedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.error(), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); } @@ -90,13 +96,13 @@ void tst_QPdfDocument::loadAsync() QScopedPointer reply(nam.get(QNetworkRequest(url))); QPdfDocument doc; - QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); - QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); + QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); doc.load(reply.data()); - QCOMPARE(startedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.pageCount(), 2); } @@ -111,6 +117,7 @@ void tst_QPdfDocument::password() doc.setPassword(QStringLiteral("WrongPassword")); QCOMPARE(passwordChangedSpy.count(), 1); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::IncorrectPasswordError); + QCOMPARE(doc.status(), QPdfDocument::Error); doc.setPassword(QStringLiteral("Qt")); QCOMPARE(passwordChangedSpy.count(), 2); QCOMPARE(doc.load(QFINDTESTDATA("pdf-sample.protected.pdf")), QPdfDocument::NoError); @@ -122,12 +129,19 @@ void tst_QPdfDocument::close() TemporaryPdf tempPdf; QPdfDocument doc; - QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); doc.load(&tempPdf); - QCOMPARE(aboutToBeClosedSpy.count(), 0); + + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); + statusChangedSpy.clear(); + doc.close(); - QCOMPARE(aboutToBeClosedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); QCOMPARE(doc.pageCount(), 0); } @@ -136,18 +150,24 @@ void tst_QPdfDocument::loadAfterClose() TemporaryPdf tempPdf; QPdfDocument doc; - QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); doc.load(&tempPdf); - QCOMPARE(aboutToBeClosedSpy.count(), 0); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); + statusChangedSpy.clear(); + doc.close(); - QCOMPARE(aboutToBeClosedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); + statusChangedSpy.clear(); - QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); - QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); doc.load(&tempPdf); - QCOMPARE(startedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.error(), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); } @@ -160,12 +180,15 @@ void tst_QPdfDocument::closeOnDestroy() { QPdfDocument *doc = new QPdfDocument; - QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); doc->load(&tempPdf); + QSignalSpy statusChangedSpy(doc, SIGNAL(statusChanged(QPdfDocument::Status))); + delete doc; - QCOMPARE(aboutToBeClosedSpy.count(), 1); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); } // deleting a closed document should not emit any signal @@ -174,12 +197,73 @@ void tst_QPdfDocument::closeOnDestroy() doc->load(&tempPdf); doc->close(); - QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); + QSignalSpy statusChangedSpy(doc, SIGNAL(statusChanged(QPdfDocument::Status))); delete doc; - QCOMPARE(aboutToBeClosedSpy.count(), 0); + QCOMPARE(statusChangedSpy.count(), 0); + } +} + +void tst_QPdfDocument::status() +{ + TemporaryPdf tempPdf; + + QPdfDocument doc; + QCOMPARE(doc.status(), QPdfDocument::Null); + + QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); + + // open existing document + doc.load(&tempPdf); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); + statusChangedSpy.clear(); + + QCOMPARE(doc.status(), QPdfDocument::Ready); + + // close document + doc.close(); + + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); + statusChangedSpy.clear(); + + QCOMPARE(doc.status(), QPdfDocument::Null); + + // try to open non-existing document + doc.load(QFINDTESTDATA("does-not-exist.pdf")); + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Error); + QCOMPARE(doc.status(), QPdfDocument::Error); + statusChangedSpy.clear(); + + // try to open non-existing document asynchronously + QNetworkAccessManager accessManager; + + const QUrl url("http://doesnotexist.qt.io"); + QScopedPointer reply(accessManager.get(QNetworkRequest(url))); + + doc.load(reply.data()); + + QTime stopWatch; + stopWatch.start(); + forever { + QCoreApplication::instance()->processEvents(); + if (statusChangedSpy.count() == 2) + break; + + if (stopWatch.elapsed() >= 30000) + break; } + + QCOMPARE(statusChangedSpy.count(), 2); + QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); + QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Error); + statusChangedSpy.clear(); } void tst_QPdfDocument::passwordClearedOnClose() -- cgit v1.2.3 From 398880564621b06a79a4ba245baf350022ad438a Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Mon, 22 Aug 2016 14:28:40 +0200 Subject: Add QPdfBookmarkModel class Change-Id: I000a398d2347870916bd93b290a1ddf5023fb0ce Reviewed-by: Simon Hausmann --- tests/auto/pdf/pdf.pro | 4 +- .../pdf/qpdfbookmarkmodel/pdf-sample.bookmarks.pdf | Bin 0 -> 8925 bytes .../pdf/qpdfbookmarkmodel/qpdfbookmarkmodel.pro | 5 + .../qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp | 246 +++++++++++++++++++++ 4 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks.pdf create mode 100644 tests/auto/pdf/qpdfbookmarkmodel/qpdfbookmarkmodel.pro create mode 100644 tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp (limited to 'tests') diff --git a/tests/auto/pdf/pdf.pro b/tests/auto/pdf/pdf.pro index bb4d02075..04e36b3dc 100644 --- a/tests/auto/pdf/pdf.pro +++ b/tests/auto/pdf/pdf.pro @@ -1,2 +1,4 @@ TEMPLATE = subdirs -qtHaveModule(printsupport): SUBDIRS = qpdfdocument + +SUBDIRS = qpdfbookmarkmodel +qtHaveModule(printsupport): SUBDIRS += qpdfdocument diff --git a/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks.pdf b/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks.pdf new file mode 100644 index 000000000..bd27c18b6 Binary files /dev/null and b/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks.pdf differ diff --git a/tests/auto/pdf/qpdfbookmarkmodel/qpdfbookmarkmodel.pro b/tests/auto/pdf/qpdfbookmarkmodel/qpdfbookmarkmodel.pro new file mode 100644 index 000000000..11a010637 --- /dev/null +++ b/tests/auto/pdf/qpdfbookmarkmodel/qpdfbookmarkmodel.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qpdfbookmarkmodel +QT += pdf testlib network +macos:CONFIG -= app_bundle +SOURCES += tst_qpdfbookmarkmodel.cpp diff --git a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp new file mode 100644 index 000000000..afaaf4d6f --- /dev/null +++ b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp @@ -0,0 +1,246 @@ +/****************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt PDF Module. +** +** $QT_BEGIN_LICENSE:COMM$ +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** $QT_END_LICENSE$ +** +******************************************************************************/ + +#include + +#include +#include + +class tst_QPdfBookmarkModel: public QObject +{ + Q_OBJECT + +public: + tst_QPdfBookmarkModel() + { + qRegisterMetaType(); + } + +private slots: + void emptyModel(); + void setEmptyDocument(); + void setEmptyDocumentAndLoad(); + void setLoadedDocument(); + void unloadDocument(); + void testTreeStructure(); + void testListStructure(); +}; + +void tst_QPdfBookmarkModel::emptyModel() +{ + QPdfBookmarkModel model; + + QVERIFY(!model.document()); + QCOMPARE(model.structureMode(), QPdfBookmarkModel::TreeMode); + QCOMPARE(model.rowCount(), 0); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.index(0, 0).isValid(), false); +} + +void tst_QPdfBookmarkModel::setEmptyDocument() +{ + QPdfDocument document; + QPdfBookmarkModel model; + + model.setDocument(&document); + + QCOMPARE(model.document(), &document); + QCOMPARE(model.structureMode(), QPdfBookmarkModel::TreeMode); + QCOMPARE(model.rowCount(), 0); + QCOMPARE(model.columnCount(), 1); + QCOMPARE(model.index(0, 0).isValid(), false); +} + +void tst_QPdfBookmarkModel::setEmptyDocumentAndLoad() +{ + QPdfDocument document; + QPdfBookmarkModel model; + + model.setDocument(&document); + + QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); + QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); + + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + + QCOMPARE(modelAboutToBeResetSpy.count(), 1); + QCOMPARE(modelResetSpy.count(), 1); + + QCOMPARE(model.rowCount(), 3); +} + +void tst_QPdfBookmarkModel::setLoadedDocument() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + + QPdfBookmarkModel model; + + QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); + QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); + + model.setDocument(&document); + + QCOMPARE(modelAboutToBeResetSpy.count(), 1); + QCOMPARE(modelResetSpy.count(), 1); + + QCOMPARE(model.rowCount(), 3); +} + +void tst_QPdfBookmarkModel::unloadDocument() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + + QPdfBookmarkModel model; + model.setDocument(&document); + + QCOMPARE(model.rowCount(), 3); + + QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); + QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); + + document.close(); + + QCOMPARE(modelAboutToBeResetSpy.count(), 1); + QCOMPARE(modelResetSpy.count(), 1); + + QCOMPARE(model.rowCount(), 0); +} + +void tst_QPdfBookmarkModel::testTreeStructure() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + + QPdfBookmarkModel model; + model.setDocument(&document); + + QCOMPARE(model.rowCount(), 3); + + const QModelIndex index1 = model.index(0, 0); + QCOMPARE(index1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1")); + QCOMPARE(index1.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index1), 2); + + const QModelIndex index1_1 = model.index(0, 0, index1); + QCOMPARE(index1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.1")); + QCOMPARE(index1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index1_1), 0); + + const QModelIndex index1_2 = model.index(1, 0, index1); + QCOMPARE(index1_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.2")); + QCOMPARE(index1_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index1_2), 0); + + const QModelIndex index2 = model.index(1, 0); + QCOMPARE(index2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2")); + QCOMPARE(index2.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index2), 2); + + const QModelIndex index2_1 = model.index(0, 0, index2); + QCOMPARE(index2_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1")); + QCOMPARE(index2_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index2_1), 1); + + const QModelIndex index2_1_1 = model.index(0, 0, index2_1); + QCOMPARE(index2_1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1.1")); + QCOMPARE(index2_1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 2); + QCOMPARE(model.rowCount(index2_1_1), 0); + + const QModelIndex index2_2 = model.index(1, 0, index2); + QCOMPARE(index2_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.2")); + QCOMPARE(index2_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index2_2), 0); + + const QModelIndex index3 = model.index(2, 0); + QCOMPARE(index3.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 3")); + QCOMPARE(index3.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index3), 0); + + const QModelIndex index4 = model.index(3, 0); + QCOMPARE(index4, QModelIndex()); +} + +void tst_QPdfBookmarkModel::testListStructure() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + + QPdfBookmarkModel model; + model.setDocument(&document); + + QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); + QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); + + model.setStructureMode(QPdfBookmarkModel::ListMode); + + QCOMPARE(modelAboutToBeResetSpy.count(), 1); + QCOMPARE(modelResetSpy.count(), 1); + + QCOMPARE(model.rowCount(), 8); + + const QModelIndex index1 = model.index(0, 0); + QCOMPARE(index1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1")); + QCOMPARE(index1.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index1), 0); + + const QModelIndex index1_1 = model.index(1, 0); + QCOMPARE(index1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.1")); + QCOMPARE(index1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index1_1), 0); + + const QModelIndex index1_2 = model.index(2, 0); + QCOMPARE(index1_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.2")); + QCOMPARE(index1_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index1_2), 0); + + const QModelIndex index2 = model.index(3, 0); + QCOMPARE(index2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2")); + QCOMPARE(index2.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index2), 0); + + const QModelIndex index2_1 = model.index(4, 0); + QCOMPARE(index2_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1")); + QCOMPARE(index2_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index2_1), 0); + + const QModelIndex index2_1_1 = model.index(5, 0); + QCOMPARE(index2_1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1.1")); + QCOMPARE(index2_1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 2); + QCOMPARE(model.rowCount(index2_1_1), 0); + + const QModelIndex index2_2 = model.index(6, 0); + QCOMPARE(index2_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.2")); + QCOMPARE(index2_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(model.rowCount(index2_2), 0); + + const QModelIndex index3 = model.index(7, 0); + QCOMPARE(index3.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 3")); + QCOMPARE(index3.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(model.rowCount(index3), 0); + + const QModelIndex index4 = model.index(8, 0); + QCOMPARE(index4, QModelIndex()); +} +QTEST_MAIN(tst_QPdfBookmarkModel) + +#include "tst_qpdfbookmarkmodel.moc" -- cgit v1.2.3 From 34f81299d8655c637526dcd0dfe522b72c58f1a0 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 25 Aug 2016 12:06:04 +0200 Subject: change the license to LGPLv3 (with the commercial option) Change-Id: I2caed38ece8067ecdad877dcc278f7828a3cb0bb Reviewed-by: Lars Knoll Reviewed-by: Frederik Gladhorn --- .../qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp | 26 +++++++++++++--- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 36 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp index afaaf4d6f..b0ce136d0 100644 --- a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp +++ b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp @@ -1,12 +1,11 @@ -/****************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** -** This file is part of the Qt PDF Module. -** -** $QT_BEGIN_LICENSE:COMM$ +** This file is part of the test suite of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:LGPL3$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -15,9 +14,26 @@ ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** ** $QT_END_LICENSE$ ** -******************************************************************************/ +****************************************************************************/ + #include diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 96619e5e0..105abc87f 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -1,3 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include -- cgit v1.2.3 From 8bd52f014ac0f2f9f8f948d8c63715d53e871962 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Tue, 21 Feb 2017 12:48:56 +0100 Subject: Add 'PageNumberRole' to QPdfBookmarkModel Provide the referenced page of an bookmark entry through a model role. Change-Id: Ia1657d75acf0128389ef0de896b242b4e8df87fe Reviewed-by: Simon Hausmann --- .../pdf-sample.bookmarks_pages.pdf | Bin 0 -> 27523 bytes .../qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp | 25 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks_pages.pdf (limited to 'tests') diff --git a/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks_pages.pdf b/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks_pages.pdf new file mode 100644 index 000000000..c4e1aa36e Binary files /dev/null and b/tests/auto/pdf/qpdfbookmarkmodel/pdf-sample.bookmarks_pages.pdf differ diff --git a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp index b0ce136d0..fddc98011 100644 --- a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp +++ b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp @@ -58,6 +58,7 @@ private slots: void unloadDocument(); void testTreeStructure(); void testListStructure(); + void testPageNumberRole(); }; void tst_QPdfBookmarkModel::emptyModel() @@ -257,6 +258,30 @@ void tst_QPdfBookmarkModel::testListStructure() const QModelIndex index4 = model.index(8, 0); QCOMPARE(index4, QModelIndex()); } + +void tst_QPdfBookmarkModel::testPageNumberRole() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks_pages.pdf")), QPdfDocument::NoError); + + QPdfBookmarkModel model; + model.setDocument(&document); + + QCOMPARE(model.rowCount(), 3); + + const QModelIndex index1 = model.index(0, 0); + QCOMPARE(index1.data(QPdfBookmarkModel::PageNumberRole).toInt(), 0); + + const QModelIndex index2 = model.index(1, 0); + QCOMPARE(index2.data(QPdfBookmarkModel::PageNumberRole).toInt(), 1); + + const QModelIndex index2_1 = model.index(0, 0, index2); + QCOMPARE(index2_1.data(QPdfBookmarkModel::PageNumberRole).toInt(), 1); + + const QModelIndex index3 = model.index(2, 0); + QCOMPARE(index3.data(QPdfBookmarkModel::PageNumberRole).toInt(), 2); +} + QTEST_MAIN(tst_QPdfBookmarkModel) #include "tst_qpdfbookmarkmodel.moc" -- cgit v1.2.3 From 44abdb16fcff4898dc81ea3ed4b65b92c4f19d7a Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Mon, 27 Feb 2017 13:34:23 +0100 Subject: Fix emission of QPdfDocument::pageCountChanged signal Emit the signal whenever the amount of pages changes on loading/closing the document. Change-Id: I0555a9cad93cb1f125ded19889eda91e08725592 Reviewed-by: Simon Hausmann --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 105abc87f..b6a00e00c 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -102,9 +102,13 @@ void tst_QPdfDocument::pageCount() TemporaryPdf tempPdf; QPdfDocument doc; + QSignalSpy pageCountChangedSpy(&doc, SIGNAL(pageCountChanged(int))); + QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); QCOMPARE(doc.pageSize(0).toSize(), tempPdf.pageLayout.fullRectPoints().size()); } @@ -114,12 +118,15 @@ void tst_QPdfDocument::loadFromIODevice() TemporaryPdf tempPdf; QPdfDocument doc; QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(&doc, SIGNAL(pageCountChanged(int))); doc.load(&tempPdf); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.error(), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); } void tst_QPdfDocument::loadAsync() @@ -133,6 +140,7 @@ void tst_QPdfDocument::loadAsync() QPdfDocument doc; QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(&doc, SIGNAL(pageCountChanged(int))); doc.load(reply.data()); @@ -140,6 +148,8 @@ void tst_QPdfDocument::loadAsync() QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.pageCount(), 2); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); } void tst_QPdfDocument::password() @@ -166,19 +176,26 @@ void tst_QPdfDocument::close() QPdfDocument doc; QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(&doc, SIGNAL(pageCountChanged(int))); doc.load(&tempPdf); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); + statusChangedSpy.clear(); + pageCountChangedSpy.clear(); doc.close(); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); QCOMPARE(doc.pageCount(), 0); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); } void tst_QPdfDocument::loadAfterClose() @@ -187,18 +204,25 @@ void tst_QPdfDocument::loadAfterClose() QPdfDocument doc; QSignalSpy statusChangedSpy(&doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(&doc, SIGNAL(pageCountChanged(int))); doc.load(&tempPdf); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Loading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); statusChangedSpy.clear(); + pageCountChangedSpy.clear(); doc.close(); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); statusChangedSpy.clear(); + pageCountChangedSpy.clear(); doc.load(&tempPdf); QCOMPARE(statusChangedSpy.count(), 2); @@ -206,6 +230,8 @@ void tst_QPdfDocument::loadAfterClose() QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Ready); QCOMPARE(doc.error(), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); } void tst_QPdfDocument::closeOnDestroy() @@ -219,12 +245,15 @@ void tst_QPdfDocument::closeOnDestroy() doc->load(&tempPdf); QSignalSpy statusChangedSpy(doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(doc, SIGNAL(pageCountChanged(int))); delete doc; QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value(), QPdfDocument::Unloading); QCOMPARE(statusChangedSpy[1][0].value(), QPdfDocument::Null); + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), 0); } // deleting a closed document should not emit any signal @@ -234,10 +263,12 @@ void tst_QPdfDocument::closeOnDestroy() doc->close(); QSignalSpy statusChangedSpy(doc, SIGNAL(statusChanged(QPdfDocument::Status))); + QSignalSpy pageCountChangedSpy(doc, SIGNAL(pageCountChanged(int))); delete doc; QCOMPARE(statusChangedSpy.count(), 0); + QCOMPARE(pageCountChangedSpy.count(), 0); } } -- cgit v1.2.3 From b67822d16d219dbee9d0819cd3c4a8c18d7e0356 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Tue, 21 Feb 2017 15:21:08 +0100 Subject: Add QPdfPageNavigation class The QPdfPageNavigation class encapsulates the logic of navigating inside a QPdfDocument. It has the notion of a 'current' page and provides slots to navigate to the previous/next page or jump directly to a given page. Additionally it provides properties to indicate whether there is a previous or next page, relative to the current one. Change-Id: I053f3c49ab4a70b2610b64d96d2c274c3d0f629b Reviewed-by: Marc Mutz --- tests/auto/pdf/pdf.pro | 5 +- .../pdf-sample.pagenavigation.pdf | Bin 0 -> 27523 bytes .../pdf/qpdfpagenavigation/qpdfpagenavigation.pro | 5 + .../qpdfpagenavigation/tst_qpdfpagenavigation.cpp | 200 +++++++++++++++++++++ 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 tests/auto/pdf/qpdfpagenavigation/pdf-sample.pagenavigation.pdf create mode 100644 tests/auto/pdf/qpdfpagenavigation/qpdfpagenavigation.pro create mode 100644 tests/auto/pdf/qpdfpagenavigation/tst_qpdfpagenavigation.cpp (limited to 'tests') diff --git a/tests/auto/pdf/pdf.pro b/tests/auto/pdf/pdf.pro index 04e36b3dc..388b8853d 100644 --- a/tests/auto/pdf/pdf.pro +++ b/tests/auto/pdf/pdf.pro @@ -1,4 +1,7 @@ TEMPLATE = subdirs -SUBDIRS = qpdfbookmarkmodel +SUBDIRS = \ + qpdfbookmarkmodel \ + qpdfpagenavigation + qtHaveModule(printsupport): SUBDIRS += qpdfdocument diff --git a/tests/auto/pdf/qpdfpagenavigation/pdf-sample.pagenavigation.pdf b/tests/auto/pdf/qpdfpagenavigation/pdf-sample.pagenavigation.pdf new file mode 100644 index 000000000..c4e1aa36e Binary files /dev/null and b/tests/auto/pdf/qpdfpagenavigation/pdf-sample.pagenavigation.pdf differ diff --git a/tests/auto/pdf/qpdfpagenavigation/qpdfpagenavigation.pro b/tests/auto/pdf/qpdfpagenavigation/qpdfpagenavigation.pro new file mode 100644 index 000000000..8de99543f --- /dev/null +++ b/tests/auto/pdf/qpdfpagenavigation/qpdfpagenavigation.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qpdfpagenavigation +QT += pdf testlib network +macos:CONFIG -= app_bundle +SOURCES += tst_qpdfpagenavigation.cpp diff --git a/tests/auto/pdf/qpdfpagenavigation/tst_qpdfpagenavigation.cpp b/tests/auto/pdf/qpdfpagenavigation/tst_qpdfpagenavigation.cpp new file mode 100644 index 000000000..ff6a02750 --- /dev/null +++ b/tests/auto/pdf/qpdfpagenavigation/tst_qpdfpagenavigation.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#include +#include + +class tst_QPdfPageNavigation: public QObject +{ + Q_OBJECT + +private slots: + void defaultValues(); + void setEmptyDocument(); + void setEmptyDocumentAndLoad(); + void setLoadedDocument(); + void unloadDocument(); + void navigate(); +}; + +void tst_QPdfPageNavigation::defaultValues() +{ + QPdfPageNavigation pageNavigation; + + QCOMPARE(pageNavigation.document(), nullptr); + QCOMPARE(pageNavigation.currentPage(), 0); + QCOMPARE(pageNavigation.pageCount(), 0); + QCOMPARE(pageNavigation.canGoToPreviousPage(), false); + QCOMPARE(pageNavigation.canGoToNextPage(), false); +} + +void tst_QPdfPageNavigation::setEmptyDocument() +{ + QPdfDocument document; + QPdfPageNavigation pageNavigation; + + pageNavigation.setDocument(&document); + + QCOMPARE(pageNavigation.document(), &document); + QCOMPARE(pageNavigation.currentPage(), 0); + QCOMPARE(pageNavigation.pageCount(), 0); + QCOMPARE(pageNavigation.canGoToPreviousPage(), false); + QCOMPARE(pageNavigation.canGoToNextPage(), false); +} + +void tst_QPdfPageNavigation::setEmptyDocumentAndLoad() +{ + QPdfDocument document; + QPdfPageNavigation pageNavigation; + + pageNavigation.setDocument(&document); + + QSignalSpy currentPageChangedSpy(&pageNavigation, &QPdfPageNavigation::currentPageChanged); + QSignalSpy pageCountChangedSpy(&pageNavigation, &QPdfPageNavigation::pageCountChanged); + QSignalSpy canGoToPreviousPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged); + QSignalSpy canGoToNextPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged); + + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagenavigation.pdf")), QPdfDocument::NoError); + + QCOMPARE(currentPageChangedSpy.count(), 0); // current page stays '0' + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), 3); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 0); // still no previous page available + QCOMPARE(canGoToNextPageChangedSpy.count(), 1); + QCOMPARE(canGoToNextPageChangedSpy[0][0].toBool(), true); +} + +void tst_QPdfPageNavigation::setLoadedDocument() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagenavigation.pdf")), QPdfDocument::NoError); + + QPdfPageNavigation pageNavigation; + + QSignalSpy currentPageChangedSpy(&pageNavigation, &QPdfPageNavigation::currentPageChanged); + QSignalSpy pageCountChangedSpy(&pageNavigation, &QPdfPageNavigation::pageCountChanged); + QSignalSpy canGoToPreviousPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged); + QSignalSpy canGoToNextPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged); + + pageNavigation.setDocument(&document); + + QCOMPARE(currentPageChangedSpy.count(), 0); // current page stays '0' + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), 3); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 0); // still no previous page available + QCOMPARE(canGoToNextPageChangedSpy.count(), 1); + QCOMPARE(canGoToNextPageChangedSpy[0][0].toBool(), true); +} + +void tst_QPdfPageNavigation::unloadDocument() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagenavigation.pdf")), QPdfDocument::NoError); + + QPdfPageNavigation pageNavigation; + pageNavigation.setDocument(&document); + + QSignalSpy currentPageChangedSpy(&pageNavigation, &QPdfPageNavigation::currentPageChanged); + QSignalSpy pageCountChangedSpy(&pageNavigation, &QPdfPageNavigation::pageCountChanged); + QSignalSpy canGoToPreviousPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged); + QSignalSpy canGoToNextPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged); + + document.close(); + + QCOMPARE(currentPageChangedSpy.count(), 0); // current page stays '0' + QCOMPARE(pageCountChangedSpy.count(), 1); + QCOMPARE(pageCountChangedSpy[0][0].toInt(), 0); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 0); // still no previous page available + QCOMPARE(canGoToNextPageChangedSpy.count(), 1); + QCOMPARE(canGoToNextPageChangedSpy[0][0].toBool(), false); +} + +void tst_QPdfPageNavigation::navigate() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagenavigation.pdf")), QPdfDocument::NoError); + + QPdfPageNavigation pageNavigation; + pageNavigation.setDocument(&document); + + QSignalSpy currentPageChangedSpy(&pageNavigation, &QPdfPageNavigation::currentPageChanged); + QSignalSpy canGoToPreviousPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged); + QSignalSpy canGoToNextPageChangedSpy(&pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged); + + QCOMPARE(pageNavigation.currentPage(), 0); + + // try to go to previous page while there is none + QCOMPARE(pageNavigation.canGoToPreviousPage(), false); + pageNavigation.goToPreviousPage(); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 0); + QCOMPARE(pageNavigation.currentPage(), 0); + QCOMPARE(pageNavigation.canGoToPreviousPage(), false); + + // try to go to next page + QCOMPARE(pageNavigation.canGoToNextPage(), true); + pageNavigation.goToNextPage(); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 1); + QCOMPARE(canGoToNextPageChangedSpy.count(), 0); + QCOMPARE(currentPageChangedSpy.count(), 1); + QCOMPARE(pageNavigation.currentPage(), 1); + QCOMPARE(pageNavigation.canGoToPreviousPage(), true); + + currentPageChangedSpy.clear(); + canGoToPreviousPageChangedSpy.clear(); + canGoToNextPageChangedSpy.clear(); + + // try to go to last page + pageNavigation.setCurrentPage(2); + QCOMPARE(canGoToPreviousPageChangedSpy.count(), 0); + QCOMPARE(canGoToNextPageChangedSpy.count(), 1); + QCOMPARE(currentPageChangedSpy.count(), 1); + QCOMPARE(pageNavigation.currentPage(), 2); + QCOMPARE(pageNavigation.canGoToNextPage(), false); + + // check that invalid requests are ignored + pageNavigation.setCurrentPage(-1); + QCOMPARE(pageNavigation.currentPage(), 2); + + pageNavigation.setCurrentPage(3); + QCOMPARE(pageNavigation.currentPage(), 2); +} + +QTEST_MAIN(tst_QPdfPageNavigation) + +#include "tst_qpdfpagenavigation.moc" -- cgit v1.2.3 From 40ab2b6127ee8dc0f81192fcb2041e2406a87475 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Wed, 22 Feb 2017 12:50:50 +0100 Subject: Add QPdfPageRenderer class The QPdfPageRenderer renders a page of a QPdfDocument for a given zoom factor. Depending on its render mode, it does the rendering in the UI thread or a worker thread. Subsequent requests are queued and processed in order. Change-Id: I95820cd318cb443b2572f6d3db5a0bee53939bd1 Reviewed-by: Giuseppe D'Angelo --- tests/auto/pdf/pdf.pro | 3 +- .../qpdfpagerenderer/pdf-sample.pagerenderer.pdf | Bin 0 -> 27523 bytes .../auto/pdf/qpdfpagerenderer/qpdfpagerenderer.pro | 5 + .../pdf/qpdfpagerenderer/tst_qpdfpagerenderer.cpp | 184 +++++++++++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 tests/auto/pdf/qpdfpagerenderer/pdf-sample.pagerenderer.pdf create mode 100644 tests/auto/pdf/qpdfpagerenderer/qpdfpagerenderer.pro create mode 100644 tests/auto/pdf/qpdfpagerenderer/tst_qpdfpagerenderer.cpp (limited to 'tests') diff --git a/tests/auto/pdf/pdf.pro b/tests/auto/pdf/pdf.pro index 388b8853d..a2b3fcff2 100644 --- a/tests/auto/pdf/pdf.pro +++ b/tests/auto/pdf/pdf.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = \ qpdfbookmarkmodel \ - qpdfpagenavigation + qpdfpagenavigation \ + qpdfpagerenderer qtHaveModule(printsupport): SUBDIRS += qpdfdocument diff --git a/tests/auto/pdf/qpdfpagerenderer/pdf-sample.pagerenderer.pdf b/tests/auto/pdf/qpdfpagerenderer/pdf-sample.pagerenderer.pdf new file mode 100644 index 000000000..c4e1aa36e Binary files /dev/null and b/tests/auto/pdf/qpdfpagerenderer/pdf-sample.pagerenderer.pdf differ diff --git a/tests/auto/pdf/qpdfpagerenderer/qpdfpagerenderer.pro b/tests/auto/pdf/qpdfpagerenderer/qpdfpagerenderer.pro new file mode 100644 index 000000000..9ccb4e82c --- /dev/null +++ b/tests/auto/pdf/qpdfpagerenderer/qpdfpagerenderer.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qpdfpagerenderer +QT += pdf testlib network +macos:CONFIG -= app_bundle +SOURCES += tst_qpdfpagerenderer.cpp diff --git a/tests/auto/pdf/qpdfpagerenderer/tst_qpdfpagerenderer.cpp b/tests/auto/pdf/qpdfpagerenderer/tst_qpdfpagerenderer.cpp new file mode 100644 index 000000000..8eaef7c6e --- /dev/null +++ b/tests/auto/pdf/qpdfpagerenderer/tst_qpdfpagerenderer.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias König +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtPDF module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +class tst_QPdfPageRenderer: public QObject +{ + Q_OBJECT + +private slots: + void defaultValues(); + void withNoDocument(); + void withEmptyDocument(); + void withLoadedDocumentSingleThreaded(); + void withLoadedDocumentMultiThreaded(); + void switchingRenderMode(); +}; + +void tst_QPdfPageRenderer::defaultValues() +{ + QPdfPageRenderer pageRenderer; + + QCOMPARE(pageRenderer.document(), nullptr); + QCOMPARE(pageRenderer.renderMode(), QPdfPageRenderer::SingleThreadedRenderMode); +} + +void tst_QPdfPageRenderer::withNoDocument() +{ + QPdfPageRenderer pageRenderer; + + const QSize imageSize(100, 100); + const quint64 requestId = pageRenderer.requestPage(0, imageSize); + + QCOMPARE(requestId, quint64(0)); +} + +void tst_QPdfPageRenderer::withEmptyDocument() +{ + QPdfDocument document; + QPdfPageRenderer pageRenderer; + + pageRenderer.setDocument(&document); + + const QSize imageSize(100, 100); + const quint64 requestId = pageRenderer.requestPage(0, imageSize); + + QCOMPARE(requestId, quint64(0)); +} + +void tst_QPdfPageRenderer::withLoadedDocumentSingleThreaded() +{ + QPdfDocument document; + QPdfPageRenderer pageRenderer; + pageRenderer.setDocument(&document); + + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagerenderer.pdf")), QPdfDocument::NoError); + + QSignalSpy pageRenderedSpy(&pageRenderer, &QPdfPageRenderer::pageRendered); + + const QSize imageSize(100, 100); + const quint64 requestId = pageRenderer.requestPage(0, imageSize); + + QCOMPARE(requestId, quint64(1)); + QTRY_COMPARE(pageRenderedSpy.count(), 1); + QCOMPARE(pageRenderedSpy[0][0].toInt(), 0); + QCOMPARE(pageRenderedSpy[0][1].toSize(), imageSize); + QCOMPARE(pageRenderedSpy[0][2].value().size(), imageSize); + QCOMPARE(pageRenderedSpy[0][4].toULongLong(), requestId); +} + +void tst_QPdfPageRenderer::withLoadedDocumentMultiThreaded() +{ + QPdfDocument document; + + QPdfPageRenderer pageRenderer; + pageRenderer.setDocument(&document); + pageRenderer.setRenderMode(QPdfPageRenderer::MultiThreadedRenderMode); + + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagerenderer.pdf")), QPdfDocument::NoError); + + QSignalSpy pageRenderedSpy(&pageRenderer, &QPdfPageRenderer::pageRendered); + + const QSize imageSize(100, 100); + const quint64 requestId = pageRenderer.requestPage(0, imageSize); + + QCOMPARE(requestId, quint64(1)); + QTRY_COMPARE(pageRenderedSpy.count(), 1); + QCOMPARE(pageRenderedSpy[0][0].toInt(), 0); + QCOMPARE(pageRenderedSpy[0][1].toSize(), imageSize); + QCOMPARE(pageRenderedSpy[0][2].value().size(), imageSize); + QCOMPARE(pageRenderedSpy[0][4].toULongLong(), requestId); +} + +void tst_QPdfPageRenderer::switchingRenderMode() +{ + QPdfDocument document; + QPdfPageRenderer pageRenderer; + pageRenderer.setDocument(&document); + + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.pagerenderer.pdf")), QPdfDocument::NoError); + + QSignalSpy pageRenderedSpy(&pageRenderer, &QPdfPageRenderer::pageRendered); + + // render single threaded + const QSize imageSize(100, 100); + const quint64 firstRequestId = pageRenderer.requestPage(0, imageSize); + + QTRY_COMPARE(pageRenderedSpy.count(), 1); + QCOMPARE(pageRenderedSpy[0][0].toInt(), 0); + QCOMPARE(pageRenderedSpy[0][1].toSize(), imageSize); + QCOMPARE(pageRenderedSpy[0][2].value().size(), imageSize); + QCOMPARE(pageRenderedSpy[0][4].toULongLong(), firstRequestId); + + const QImage image = pageRenderedSpy[0][2].value(); + + pageRenderedSpy.clear(); + + // switch to multi threaded + pageRenderer.setRenderMode(QPdfPageRenderer::MultiThreadedRenderMode); + + const quint64 secondRequestId = pageRenderer.requestPage(0, imageSize); + + QVERIFY(firstRequestId != secondRequestId); + QTRY_COMPARE(pageRenderedSpy.count(), 1); + QCOMPARE(pageRenderedSpy[0][0].toInt(), 0); + QCOMPARE(pageRenderedSpy[0][1].toSize(), imageSize); + QCOMPARE(pageRenderedSpy[0][2].value(), image); + QCOMPARE(pageRenderedSpy[0][2].value().size(), imageSize); + QCOMPARE(pageRenderedSpy[0][4].toULongLong(), secondRequestId); + + pageRenderedSpy.clear(); + + // switch back to single threaded + pageRenderer.setRenderMode(QPdfPageRenderer::SingleThreadedRenderMode); + + const quint64 thirdRequestId = pageRenderer.requestPage(0, imageSize); + + QTRY_COMPARE(pageRenderedSpy.count(), 1); + QCOMPARE(pageRenderedSpy[0][0].toInt(), 0); + QCOMPARE(pageRenderedSpy[0][1].toSize(), imageSize); + QCOMPARE(pageRenderedSpy[0][2].value(), image); + QCOMPARE(pageRenderedSpy[0][2].value().size(), imageSize); + QCOMPARE(pageRenderedSpy[0][4].toULongLong(), thirdRequestId); +} + +QTEST_MAIN(tst_QPdfPageRenderer) + +#include "tst_qpdfpagerenderer.moc" -- cgit v1.2.3 From 71663751e74c814e516e22d8a5e5532381e015e6 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Fri, 9 Aug 2019 11:37:32 +0200 Subject: Initial import of qtpdf source code Code has been imported from git://code.qt.io/qt-labs/qtpdf to src/pdf, src/pdfwidgets, examples/pdfwidgets and tests/auto/pdf. Some git revision history was rewritten to remove conflicting files like src.pro, examples.pro, tests.pro, .gitingnore, .gitmodules, sync.profile, .qmake.conf, 3rdparty Removed unneeded leftovers after import. Change-Id: Ifc1e02828adfefe8db68d596cd2cb238de22408b Reviewed-by: Shawn Rutledge Reviewed-by: Kai Koehne --- tests/auto/pdf/cmake/cmake.pro | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/auto/pdf/cmake/cmake.pro (limited to 'tests') diff --git a/tests/auto/pdf/cmake/cmake.pro b/tests/auto/pdf/cmake/cmake.pro deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3 From 883f2a9969f02941f018b828749fea97d8b56582 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Wed, 18 Jul 2018 11:06:14 +0200 Subject: Add QtPdf and QtPdfWidgets modules This change adds two new modules to qtwebengine repository. New modules do not depend on webengine module, however webengine chromium source code and Chromium "gn" configuration is required to build QtPdf. Adding two unrelated modules to webengine might look crazy: however sharing gn build configuration and Chromium code base with necessary qt adaptations simplifies code maintenance and minimises required code checkouts. Back porting of security patches for Chromium also affects Pdfium. Moreover, Pdfium is no longer a separate project, but integrated into Chromium: therefore moving it out of Chromium source tree would require extra effort. Rename webengine-core feature to build-qtwebengine-core, this makes consistent feature naming with build-qtpdf At the moment two new modules have integrated build, with possible shortcuts: qmake -- --no-build-qtwebengine-core qmake -- --no-build-qtpdf Webengine build is disabled by default now. Change-Id: Iac3d9927d51f3ac316db0148d275eda843dcc19b Reviewed-by: Shawn Rutledge --- tests/auto/auto.pro | 5 +++++ tests/auto/pdf/qpdfdocument/BLACKLIST | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/auto/pdf/qpdfdocument/BLACKLIST (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 59bcd5aef..9b71e1183 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -7,3 +7,8 @@ qtHaveModule(webengine) { qtHaveModule(webenginewidgets) { SUBDIRS += core widgets } + +qtHaveModule(pdf) { + SUBDIRS += pdf +} + diff --git a/tests/auto/pdf/qpdfdocument/BLACKLIST b/tests/auto/pdf/qpdfdocument/BLACKLIST new file mode 100644 index 000000000..b8db556d6 --- /dev/null +++ b/tests/auto/pdf/qpdfdocument/BLACKLIST @@ -0,0 +1,6 @@ +[password] +* + +[passwordClearedOnClose] +* + -- cgit v1.2.3 From e3802e913e1d6a3694d0084a35516145e2be32df Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 21 Aug 2019 20:18:45 +0200 Subject: tst_qpdfdocument: use QElapsedTimer instead of QTime Change-Id: Ifdac9ae6b216605166cefc9dbab60f5ab4b1dcbf Reviewed-by: Michal Klocek --- tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index b6a00e00c..29b85fc89 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -316,13 +316,12 @@ void tst_QPdfDocument::status() doc.load(reply.data()); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); forever { QCoreApplication::instance()->processEvents(); if (statusChangedSpy.count() == 2) break; - if (stopWatch.elapsed() >= 30000) break; } -- cgit v1.2.3 From 25fb3b04706752932e33b9d96fab74fa8469400d Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 22 Aug 2019 09:59:38 +0200 Subject: Add a QImageIOHandler to render PDF with QtQuick Image Now you can use Image in QML to display the first page of a PDF file by default. (The implementation is very similar to the handler plugin in the QtSVG module.) To display other pages, you can set the new currentFrame property that is being added to Image in 5.14. QPdfIOHandler uses its own instance of QPdfDocument to do the rendering. An instance will be created each time the image needs to read a frame from the file (on creation; each time the currentFrame property is changed; each time sourceSize is changed to require a different resolution rendering). This approach is not as efficient as it would be to share the QPdfDocument instance among multiple Images that are rendering different pages at the same time, as well as sharing with the QML Document declaration that we plan to add. However, if you set asynchronous: true, each Image will render its page from the PDF in its own thread. PDFium is not thread-safe, so sharing the QPdfDocument among multiple threads is not safe. It may be possible to make it safe by having a dedicated PDF-rendering thread, but that is not yet done in this patch. Change-Id: I7a1f8cd7bd5b8f93d45fa9350752b2d9356b04fe Reviewed-by: Michal Klocek --- tests/manual/quick/pdf/simplest.qml | 54 ++++++++++++++++++++++++++++++++++++ tests/manual/quick/pdf/test.pdf | Bin 0 -> 80045 bytes 2 files changed, 54 insertions(+) create mode 100644 tests/manual/quick/pdf/simplest.qml create mode 100644 tests/manual/quick/pdf/test.pdf (limited to 'tests') diff --git a/tests/manual/quick/pdf/simplest.qml b/tests/manual/quick/pdf/simplest.qml new file mode 100644 index 000000000..05d8c53c4 --- /dev/null +++ b/tests/manual/quick/pdf/simplest.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.14 + +Image { + source: "test.pdf" +} diff --git a/tests/manual/quick/pdf/test.pdf b/tests/manual/quick/pdf/test.pdf new file mode 100644 index 000000000..a9dc1bc29 Binary files /dev/null and b/tests/manual/quick/pdf/test.pdf differ -- cgit v1.2.3 From 0e533e924df25ecc6c0f5e16f88bdae0513b8445 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 9 Sep 2019 16:35:56 +0200 Subject: Add page stepping shortcuts to simplest.qml PDF manual test Change-Id: I3300fb68dd0b2f3701ca53cd118a4b11a0ac5ede Reviewed-by: Michal Klocek --- tests/manual/quick/pdf/simplest.qml | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/manual/quick/pdf/simplest.qml b/tests/manual/quick/pdf/simplest.qml index 05d8c53c4..37d388d0a 100644 --- a/tests/manual/quick/pdf/simplest.qml +++ b/tests/manual/quick/pdf/simplest.qml @@ -50,5 +50,17 @@ import QtQuick 2.14 Image { + id: image source: "test.pdf" + fillMode: Image.PreserveAspectFit + Shortcut { + sequence: StandardKey.MoveToNextPage + enabled: image.currentFrame < image.frameCount - 1 + onActivated: image.currentFrame++ + } + Shortcut { + sequence: StandardKey.MoveToPreviousPage + enabled: image.currentFrame > 0 + onActivated: image.currentFrame-- + } } -- cgit v1.2.3 From 9968e2578f96081d2a242340620fcb2b96d9a1d3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Aug 2019 10:13:55 +0200 Subject: Add QtQuick.Pdf module with QQuickPdfDocument; manual tests QQuickPdfDocument is a wrapper for QPdfDocument providing appropriate QML API. Task-number: QTBUG-77506 Change-Id: Ifa2ef50d3d31179f1955c2f673495e727b962bd1 Reviewed-by: Michal Klocek --- tests/manual/quick/pdf/listview.qml | 95 ++++++++++++++ tests/manual/quick/pdf/pessimizedListView.qml | 174 ++++++++++++++++++++++++++ tests/manual/quick/pdf/simplest.qml | 2 +- tests/manual/quick/pdf/withdoc.qml | 159 +++++++++++++++++++++++ 4 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 tests/manual/quick/pdf/listview.qml create mode 100644 tests/manual/quick/pdf/pessimizedListView.qml create mode 100644 tests/manual/quick/pdf/withdoc.qml (limited to 'tests') diff --git a/tests/manual/quick/pdf/listview.qml b/tests/manual/quick/pdf/listview.qml new file mode 100644 index 000000000..361ae7d89 --- /dev/null +++ b/tests/manual/quick/pdf/listview.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.14 +import QtQuick.Window 2.14 +import QtQuick.Pdf 5.15 + +Window { + width: 600 + height: 440 + color: "lightgrey" + title: doc.source + visible: true + + PdfDocument { + id: doc + source: "test.pdf" + } + + ListView { + id: listView + anchors.fill: parent + model: doc.pageCount + spacing: 6 + delegate: Column { + Rectangle { + id: paper + width: image.width + height: image.height + Image { + id: image + objectName: "PDF page " + index + source: doc.source + currentFrame: index + asynchronous: true + } + } + Text { + text: "Page " + (image.currentFrame + 1) + } + } + } + + Text { + anchors.bottom: parent.bottom + anchors.right: parent.right + text: "page " + Math.max(1, (listView.indexAt(0, listView.contentY) + 1)) + " of " + doc.pageCount + } +} diff --git a/tests/manual/quick/pdf/pessimizedListView.qml b/tests/manual/quick/pdf/pessimizedListView.qml new file mode 100644 index 000000000..4ae0edabe --- /dev/null +++ b/tests/manual/quick/pdf/pessimizedListView.qml @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.14 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.14 +import QtQuick.Pdf 5.15 +import Qt.labs.platform 1.1 as P + +ApplicationWindow { + width: 900 + height: 1000 + color: "lightgrey" + title: doc.source + " scale " + imageScale.toFixed(2) + visible: true + property real imageScale: 1 + + header: ToolBar { + RowLayout { + anchors.fill: parent + anchors.rightMargin: 6 + ToolButton { + action: Action { + text: "🗁" + shortcut: StandardKey.Open + onTriggered: fileDialog.open() + } + } + ToolButton { + action: Action { + text: "⊕" + shortcut: StandardKey.ZoomIn + onTriggered: imageScale *= Math.sqrt(2) + } + } + ToolButton { + action: Action { + text: "⊖" + shortcut: StandardKey.ZoomOut + onTriggered: imageScale /= Math.sqrt(2) + } + } + ToolButton { + action: Action { + text: "1x" + shortcut: "Ctrl+0" + onTriggered: imageScale = 1 + } + } + + Label { + text: "Pixels/point:" + } + SpinBox { + id: oversamplingSB + from: 1; to: 8; value: 4 + } + + Label { + text: "cacheBuffer:" + } + SpinBox { + id: cacheBufferSB + from: 0; to: 1000; stepSize: 50; value: 100 + } + + CheckBox { + id: asyncCB + text: "async" + } + + CheckBox { + id: cacheCB + text: "cache" + } + } + } + + PdfDocument { + id: doc + source: "test.pdf" + } + + P.FileDialog { + id: fileDialog + title: "Open a PDF file" + nameFilters: [ "PDF files (*.pdf)" ] + onAccepted: doc.source = file + } + + ListView { + id: listView + anchors.fill: parent + anchors.margins: 10 + model: doc.pageCount + spacing: 6 + cacheBuffer: cacheBufferSB.value + ScrollBar.vertical: ScrollBar { } + delegate: Rectangle { + id: paper + width: Math.max(60, image.width) * imageScale + height: 100 * imageScale + BusyIndicator { + anchors.centerIn: parent + running: image.status === Image.Loading + } + Image { + id: image + scale: imageScale + anchors.centerIn: parent + sourceSize.width: doc.pagePointSize(index).width * oversamplingSB.value + height: 100 + fillMode: Image.PreserveAspectFit + objectName: "PDF page " + index + source: doc.source + currentFrame: index + asynchronous: asyncCB.checked + cache: cacheCB.checked + } + } + } + + Text { + anchors.bottom: parent.bottom + anchors.right: parent.right + text: "page " + Math.max(1, (listView.indexAt(0, listView.contentY) + 1)) + " of " + doc.pageCount + } +} diff --git a/tests/manual/quick/pdf/simplest.qml b/tests/manual/quick/pdf/simplest.qml index 37d388d0a..0571493af 100644 --- a/tests/manual/quick/pdf/simplest.qml +++ b/tests/manual/quick/pdf/simplest.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. diff --git a/tests/manual/quick/pdf/withdoc.qml b/tests/manual/quick/pdf/withdoc.qml new file mode 100644 index 000000000..0fed5b16e --- /dev/null +++ b/tests/manual/quick/pdf/withdoc.qml @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.14 +import QtQuick.Controls 2.14 +import Qt.labs.platform 1.1 as Platform +import QtQuick.Pdf 5.15 +import QtQuick.Window 2.14 + +Window { + width: 800 + height: 940 + color: "lightgrey" + title: doc.source + visible: true + + PdfDocument { + id: doc + source: "test.pdf" + } + + Platform.FileDialog { + id: fileDialog + title: "Open a PDF file" + nameFilters: [ "PDF files (*.pdf)" ] + onAccepted: doc.source = file + } + + Column { + id: column + anchors.fill: parent + anchors.margins: 6 + spacing: 6 + Text { text: "title: " + doc.title; visible: doc.title !== "" } + Text { text: "author: " + doc.author; visible: doc.author !== "" } + Text { text: "subject: " + doc.subject; visible: doc.subject !== "" } + Text { text: "keywords: " + doc.keywords; visible: doc.keywords !== "" } + Text { text: "producer: " + doc.producer; visible: doc.producer !== "" } + Text { text: "creator: " + doc.creator; visible: doc.creator !== "" } + Text { text: "creationDate: " + doc.creationDate; visible: doc.creationDate !== "" } + Text { text: "modificationDate: " + doc.modificationDate; visible: doc.modificationDate !== "" } + Text { text: "implicit size: " + image.implicitWidth + "x" + image.implicitHeight } + Text { text: "source size: " + image.sourceSize.width + "x" + image.sourceSize.height } + Text { text: "painted size: " + image.paintedWidth + "x" + image.paintedHeight } + + Flickable { + width: column.width + height: width + contentWidth: paper.width + contentHeight: paper.height + z: -1 + Rectangle { + id: paper + width: image.width + height: image.height + Image { + id: image + source: doc.status === PdfDocument.Ready ? doc.source : "" + + property real zoomFactor: Math.sqrt(2) + + DragHandler { + id: dragHandler + target: null + } + + Shortcut { + sequence: StandardKey.MoveToNextPage + enabled: image.currentFrame < image.frameCount - 1 + onActivated: image.currentFrame++ + } + Shortcut { + sequence: StandardKey.MoveToPreviousPage + enabled: image.currentFrame > 0 + onActivated: image.currentFrame-- + } + Shortcut { + sequence: StandardKey.ZoomIn + enabled: image.sourceSize.width < 5000 + onActivated: { + image.sourceSize.width = image.implicitWidth * image.zoomFactor + image.sourceSize.height = image.implicitHeight * image.zoomFactor + } + } + Shortcut { + sequence: StandardKey.ZoomOut + enabled: image.width > 50 + onActivated: { + image.sourceSize.width = image.implicitWidth / image.zoomFactor + image.sourceSize.height = image.implicitHeight / image.zoomFactor + } + } + Shortcut { + sequence: "Ctrl+0" + onActivated: image.sourceSize = undefined + } + Shortcut { + sequence: StandardKey.Open + onActivated: fileDialog.open() + } + Shortcut { + sequence: StandardKey.Quit + onActivated: Qt.quit() + } + } + } + } + } + Text { + anchors.bottom: parent.bottom + text: "page " + (image.currentFrame + 1) + " of " + doc.pageCount + } +} -- cgit v1.2.3 From b6dd845ec4a6bfb6b620686681e20d38a2f24101 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Aug 2019 15:31:00 +0200 Subject: Add QPdfSearchModel, QML PdfSearchModel and PdfPageView This enables searching a PDF for a text string and getting the boundaries of the areas where it is found. The boundaries are returned as polygons intended to be rendered with PathMultiline. PdfPageView is a QML component intended to be a drop-in viewer for use in applications that need the most common PDF viewing functionality. More advanced applications are free to use it as a starting point for customization. Task-number: QTBUG-77507 Task-number: QTBUG-77514 Change-Id: Id08ac30224e41b6cdfb9300cc4288d5750259f78 Reviewed-by: Shawn Rutledge --- tests/auto/pdf/qpdfsearchmodel/qpdfsearchmodel.pro | 5 ++ tests/auto/pdf/qpdfsearchmodel/test.pdf | Bin 0 -> 80045 bytes .../pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp | 69 +++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/auto/pdf/qpdfsearchmodel/qpdfsearchmodel.pro create mode 100644 tests/auto/pdf/qpdfsearchmodel/test.pdf create mode 100644 tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp (limited to 'tests') diff --git a/tests/auto/pdf/qpdfsearchmodel/qpdfsearchmodel.pro b/tests/auto/pdf/qpdfsearchmodel/qpdfsearchmodel.pro new file mode 100644 index 000000000..205fef175 --- /dev/null +++ b/tests/auto/pdf/qpdfsearchmodel/qpdfsearchmodel.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qpdfsearchmodel +QT += pdf testlib network +macos:CONFIG -= app_bundle +SOURCES += tst_qpdfsearchmodel.cpp diff --git a/tests/auto/pdf/qpdfsearchmodel/test.pdf b/tests/auto/pdf/qpdfsearchmodel/test.pdf new file mode 100644 index 000000000..a9dc1bc29 Binary files /dev/null and b/tests/auto/pdf/qpdfsearchmodel/test.pdf differ diff --git a/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp b/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp new file mode 100644 index 000000000..e690bfc11 --- /dev/null +++ b/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#include +#include + +class tst_QPdfSearchModel: public QObject +{ + Q_OBJECT + +public: + tst_QPdfSearchModel() {} + +private slots: + void findText(); +}; + +void tst_QPdfSearchModel::findText() +{ + QPdfDocument document; + QCOMPARE(document.load(QFINDTESTDATA("test.pdf")), QPdfDocument::NoError); + + QPdfSearchModel model; + model.setDocument(&document); + QVector matches = model.matches(1, "ai"); + + qDebug() << matches; + QCOMPARE(matches.count(), 3); +} + +QTEST_MAIN(tst_QPdfSearchModel) + +#include "tst_qpdfsearchmodel.moc" -- cgit v1.2.3