MCPcopy Create free account
hub / github.com/TeXworks/texworks / load

Method load

modules/QtPDF/src/PDFDocumentWidget.cpp:41–66  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

39// displayed and true is returned. Otherwise, the view is not altered and false
40// is returned
41bool 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
68QWeakPointer<Backend::Document> PDFDocumentWidget::document() const
69{

Callers 3

PDFViewerMethod · 0.45
openMethod · 0.45
switchInterfaceLocaleMethod · 0.45

Calls 5

reloadDocumentMethod · 0.80
documentMethod · 0.45
dataMethod · 0.45
fileNameMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected