Loads the file specified by filename. If this succeeds, the new file is displayed and true is returned. Otherwise, the view is not altered and false is returned
| 39 | // displayed and true is returned. Otherwise, the view is not altered and false |
| 40 | // is returned |
| 41 | bool PDFDocumentWidget::load(const QString &filename) |
| 42 | { |
| 43 | if (_scene) { |
| 44 | // If we already have the document, reload it instead of replacing it with |
| 45 | // a new instance to preserve the current state (e.g., viewing area, etc.) |
| 46 | QSharedPointer<Backend::Document> doc = _scene.data()->document().toStrongRef(); |
| 47 | if (doc && doc.data()->fileName() == filename) { |
| 48 | _scene.data()->reloadDocument(); |
| 49 | return true; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | QSharedPointer<QtPDF::Backend::Document> a_pdf_doc = QtPDF::Backend::Document::newDocument(filename); |
| 54 | |
| 55 | if (!a_pdf_doc || !a_pdf_doc->isValid()) |
| 56 | return false; |
| 57 | |
| 58 | // Note: Don't pass `this` (or any other QObject*) as parent to the new |
| 59 | // PDFDocumentScene as that would cause docScene to be destroyed with its |
| 60 | // parent, thereby bypassing the QSharedPointer mechanism. docScene will be |
| 61 | // freed automagically when the last QSharedPointer pointing to it will be |
| 62 | // destroyed. |
| 63 | _scene = QSharedPointer<QtPDF::PDFDocumentScene>(new QtPDF::PDFDocumentScene(a_pdf_doc, nullptr, _dpi, _dpi)); |
| 64 | setScene(_scene); |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | QWeakPointer<Backend::Document> PDFDocumentWidget::document() const |
| 69 | { |
no test coverage detected