summaryrefslogtreecommitdiffstats
path: root/src/pdf
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2016-08-06 20:30:22 +0200
committerTobias Koenig <tobias.koenig@kdab.com>2016-08-08 07:10:23 +0000
commit322ab60499477ce0860f3a9b697e9b696da9570e (patch)
tree909624573cff135bcc6f7425b5a2dd9258cc2446 /src/pdf
parentcab3f0279696c5213a33f7875a40dc6d68709d82 (diff)
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/qpdfdocument.cpp30
-rw-r--r--src/pdf/qpdfdocument.h3
2 files changed, 31 insertions, 2 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index 4d6a2e0..6802089 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -59,9 +59,9 @@ QPdfDocumentPrivate::QPdfDocumentPrivate()
QPdfDocumentPrivate::~QPdfDocumentPrivate()
{
- const QMutexLocker lock(pdfMutex());
+ q->close();
- clear();
+ const QMutexLocker lock(pdfMutex());
if (!--libraryRefCount)
FPDF_DestroyLibrary();
@@ -249,6 +249,9 @@ QPdfDocument::QPdfDocument(QObject *parent)
d->q = this;
}
+/*!
+ Destroys the document.
+*/
QPdfDocument::~QPdfDocument()
{
}
@@ -298,6 +301,29 @@ QPdfDocument::Error QPdfDocument::error() const
return d->lastError;
}
+/*!
+ \fn void QPdfDocument::aboutToBeClosed()
+
+ This signal is emitted whenever the document is closed.
+
+ \sa close()
+*/
+
+/*!
+ Closes the document.
+*/
+void QPdfDocument::close()
+{
+ if (!d->doc)
+ return;
+
+ emit aboutToBeClosed();
+
+ const QMutexLocker lock(pdfMutex());
+
+ d->clear();
+}
+
int QPdfDocument::pageCount() const
{
if (!d->doc)
diff --git a/src/pdf/qpdfdocument.h b/src/pdf/qpdfdocument.h
index 6a46c50..bb3602d 100644
--- a/src/pdf/qpdfdocument.h
+++ b/src/pdf/qpdfdocument.h
@@ -61,6 +61,8 @@ public:
Error error() const;
+ void close();
+
int pageCount() const;
QSizeF pageSize(int page) const;
@@ -71,6 +73,7 @@ Q_SIGNALS:
void passwordRequired();
void documentLoadStarted();
void documentLoadFinished();
+ void aboutToBeClosed();
void pageCountChanged();
private: