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

Method reinitializeFromScene

modules/QtPDF/src/PDFDocumentView.cpp:1285–1345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1283}
1284
1285void PDFDocumentView::reinitializeFromScene()
1286{
1287 if (_pdf_scene) {
1288 _lastPage = _pdf_scene->lastPage();
1289 if (_lastPage <= 0)
1290 _currentPage = -1;
1291 else {
1292 if (_currentPage < 0)
1293 _currentPage = 0;
1294 if (_currentPage >= _lastPage)
1295 _currentPage = _lastPage - 1;
1296 }
1297 }
1298 else {
1299 _lastPage = -1;
1300 _currentPage = -1;
1301 }
1302 // Ensure the text selection marker is reset (if any) as it holds pointers to
1303 // page items (highlight path, boxes) that are now changed and/or destroyed.
1304 DocumentTool::Select * selectTool = dynamic_cast<DocumentTool::Select*>(getToolByType(DocumentTool::AbstractTool::Tool_Select));
1305 if (selectTool)
1306 selectTool->pageDestroyed();
1307 // Ensure (old) search data is destroyed as well
1308 _searcher.ensureStopped();
1309 // Also reset _searchString. Otherwise the next search for the same string
1310 // will assume the search has already been run (without results as
1311 // _searchResults is empty) and won't run it again on the new scene data.
1312 _searcher.setSearchString(QString());
1313 _searchResults.clear();
1314 _currentSearchResult = -1;
1315
1316 QSharedPointer<Backend::Document> doc{document().toStrongRef()};
1317 if (doc) {
1318 QAbstractItemModel * ocgModel = doc.data()->optionalContentModel();
1319 if (ocgModel) {
1320 connect(ocgModel, &QAbstractItemModel::dataChanged, this, [this](const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) {
1321 Q_UNUSED(topLeft)
1322 Q_UNUSED(bottomRight)
1323 // Only repaint if the check state is modified (or all states are
1324 // modified, i.e., roles is empty)
1325 if (!roles.empty() && !roles.contains(Qt::CheckStateRole)) {
1326 return;
1327 }
1328 QSharedPointer<Backend::Document> doc{document().toStrongRef()};
1329 if (doc) {
1330 // Invalidate all document tiles
1331 QtPDF::Backend::Document::pageCache().removeDocumentTiles(doc.data());
1332 // Update the view after returning to the event loop (in case other
1333 // views also display this same document --- and consequently call
1334 // pageCache().removeDocumentTiles() --- we don't want to recreate and
1335 // re-remove tiles multiple times)
1336#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
1337 QTimer::singleShot(1, viewport(), SLOT(update()));
1338#else
1339 QTimer::singleShot(1, viewport(), static_cast<void (QWidget::*)()>(&QWidget::update));
1340#endif
1341 }
1342 });

Callers

nothing calls this directly

Calls 10

documentFunction · 0.85
pageDestroyedMethod · 0.80
ensureStoppedMethod · 0.80
setSearchStringMethod · 0.80
containsMethod · 0.80
removeDocumentTilesMethod · 0.80
lastPageMethod · 0.45
clearMethod · 0.45
optionalContentModelMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected