Changeset View
Changeset View
Standalone View
Standalone View
core/document.cpp
Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Line(s) | 267 | { | |||
---|---|---|---|---|---|
304 | // If we're still on low memory, try to free individual tiles | 304 | // If we're still on low memory, try to free individual tiles | ||
305 | 305 | | |||
306 | // Store pages that weren't completely removed | 306 | // Store pages that weren't completely removed | ||
307 | 307 | | |||
308 | QLinkedList< AllocatedPixmap * > pixmapsToKeep; | 308 | QLinkedList< AllocatedPixmap * > pixmapsToKeep; | ||
309 | while (memoryToFree > 0) | 309 | while (memoryToFree > 0) | ||
310 | { | 310 | { | ||
311 | int clean_hits = 0; | 311 | int clean_hits = 0; | ||
312 | foreach (DocumentObserver *observer, m_observers) | 312 | for (DocumentObserver *observer : qAsConst(m_observers)) | ||
313 | { | 313 | { | ||
314 | AllocatedPixmap * p = searchLowestPriorityPixmap( false, true, observer ); | 314 | AllocatedPixmap * p = searchLowestPriorityPixmap( false, true, observer ); | ||
315 | if ( !p ) // No pixmap to remove | 315 | if ( !p ) // No pixmap to remove | ||
316 | continue; | 316 | continue; | ||
317 | 317 | | |||
318 | clean_hits++; | 318 | clean_hits++; | ||
319 | 319 | | |||
320 | TilesManager *tilesManager = m_pagesVector.at( p->page )->d->tilesManager( observer ); | 320 | TilesManager *tilesManager = m_pagesVector.at( p->page )->d->tilesManager( observer ); | ||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Line(s) | 603 | { | |||
641 | { | 641 | { | ||
642 | QDomNode viewNode = infoNode.firstChild(); | 642 | QDomNode viewNode = infoNode.firstChild(); | ||
643 | while ( viewNode.isElement() ) | 643 | while ( viewNode.isElement() ) | ||
644 | { | 644 | { | ||
645 | QDomElement viewElement = viewNode.toElement(); | 645 | QDomElement viewElement = viewNode.toElement(); | ||
646 | if ( viewElement.tagName() == QLatin1String("view") ) | 646 | if ( viewElement.tagName() == QLatin1String("view") ) | ||
647 | { | 647 | { | ||
648 | const QString viewName = viewElement.attribute( QStringLiteral("name") ); | 648 | const QString viewName = viewElement.attribute( QStringLiteral("name") ); | ||
649 | Q_FOREACH ( View * view, m_views ) | 649 | for ( View *view : qAsConst(m_views) ) | ||
650 | { | 650 | { | ||
651 | if ( view->name() == viewName ) | 651 | if ( view->name() == viewName ) | ||
652 | { | 652 | { | ||
653 | loadViewsInfo( view, viewElement ); | 653 | loadViewsInfo( view, viewElement ); | ||
654 | loadedAnything = true; | 654 | loadedAnything = true; | ||
655 | break; | 655 | break; | ||
656 | } | 656 | } | ||
657 | } | 657 | } | ||
▲ Show 20 Lines • Show All 664 Lines • ▼ Show 20 Line(s) | 1319 | { | |||
1322 | historyEntry.setAttribute( QStringLiteral("viewport"), (*backIterator).toString() ); | 1322 | historyEntry.setAttribute( QStringLiteral("viewport"), (*backIterator).toString() ); | ||
1323 | historyNode.appendChild( historyEntry ); | 1323 | historyNode.appendChild( historyEntry ); | ||
1324 | ++backIterator; | 1324 | ++backIterator; | ||
1325 | } | 1325 | } | ||
1326 | } | 1326 | } | ||
1327 | // create views root node | 1327 | // create views root node | ||
1328 | QDomElement viewsNode = doc.createElement( QStringLiteral("views") ); | 1328 | QDomElement viewsNode = doc.createElement( QStringLiteral("views") ); | ||
1329 | generalInfo.appendChild( viewsNode ); | 1329 | generalInfo.appendChild( viewsNode ); | ||
1330 | Q_FOREACH ( View * view, m_views ) | 1330 | for ( View *view : qAsConst(m_views) ) | ||
1331 | { | 1331 | { | ||
1332 | QDomElement viewEntry = doc.createElement( QStringLiteral("view") ); | 1332 | QDomElement viewEntry = doc.createElement( QStringLiteral("view") ); | ||
1333 | viewEntry.setAttribute( QStringLiteral("name"), view->name() ); | 1333 | viewEntry.setAttribute( QStringLiteral("name"), view->name() ); | ||
1334 | viewsNode.appendChild( viewEntry ); | 1334 | viewsNode.appendChild( viewEntry ); | ||
1335 | saveViewsInfo( view, viewEntry ); | 1335 | saveViewsInfo( view, viewEntry ); | ||
1336 | } | 1336 | } | ||
1337 | 1337 | | |||
1338 | // 3. Save DOM to XML file | 1338 | // 3. Save DOM to XML file | ||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Line(s) | 1628 | { | |||
1644 | // which changes m_pixmaps and thus breaks the loop above | 1644 | // which changes m_pixmaps and thus breaks the loop above | ||
1645 | for ( PixmapRequest *pr : qAsConst( pixmapsToRequest ) ) | 1645 | for ( PixmapRequest *pr : qAsConst( pixmapsToRequest ) ) | ||
1646 | { | 1646 | { | ||
1647 | QLinkedList< Okular::PixmapRequest * > requestedPixmaps; | 1647 | QLinkedList< Okular::PixmapRequest * > requestedPixmaps; | ||
1648 | requestedPixmaps.push_back( pr ); | 1648 | requestedPixmaps.push_back( pr ); | ||
1649 | m_parent->requestPixmaps( requestedPixmaps, Okular::Document::NoOption ); | 1649 | m_parent->requestPixmaps( requestedPixmaps, Okular::Document::NoOption ); | ||
1650 | } | 1650 | } | ||
1651 | 1651 | | |||
1652 | foreach (DocumentObserver *observer, m_observers) | 1652 | for (DocumentObserver *observer : qAsConst(m_observers)) | ||
1653 | { | 1653 | { | ||
1654 | QLinkedList< Okular::PixmapRequest * > requestedPixmaps; | 1654 | QLinkedList< Okular::PixmapRequest * > requestedPixmaps; | ||
1655 | 1655 | | |||
1656 | TilesManager *tilesManager = page->d->tilesManager( observer ); | 1656 | TilesManager *tilesManager = page->d->tilesManager( observer ); | ||
1657 | if ( tilesManager ) | 1657 | if ( tilesManager ) | ||
1658 | { | 1658 | { | ||
1659 | tilesManager->markDirty(); | 1659 | tilesManager->markDirty(); | ||
1660 | 1660 | | |||
▲ Show 20 Lines • Show All 559 Lines • ▼ Show 20 Line(s) | 2219 | else | |||
2220 | qCDebug(OkularCoreDebug) << "PdfSync: going one level down too much"; | 2220 | qCDebug(OkularCoreDebug) << "PdfSync: going one level down too much"; | ||
2221 | } | 2221 | } | ||
2222 | else | 2222 | else | ||
2223 | qCDebug(OkularCoreDebug).nospace() << "PdfSync: unknown line format: '" << line << "'"; | 2223 | qCDebug(OkularCoreDebug).nospace() << "PdfSync: unknown line format: '" << line << "'"; | ||
2224 | 2224 | | |||
2225 | } | 2225 | } | ||
2226 | 2226 | | |||
2227 | QVector< QLinkedList< Okular::SourceRefObjectRect * > > refRects( m_pagesVector.size() ); | 2227 | QVector< QLinkedList< Okular::SourceRefObjectRect * > > refRects( m_pagesVector.size() ); | ||
2228 | foreach ( const pdfsyncpoint& pt, points ) | 2228 | for ( const pdfsyncpoint &pt : qAsConst(points) ) | ||
2229 | { | 2229 | { | ||
2230 | // drop pdfsync points not completely valid | 2230 | // drop pdfsync points not completely valid | ||
2231 | if ( pt.page < 0 || pt.page >= m_pagesVector.size() ) | 2231 | if ( pt.page < 0 || pt.page >= m_pagesVector.size() ) | ||
2232 | continue; | 2232 | continue; | ||
2233 | 2233 | | |||
2234 | // magic numbers for TeX's RSU's (Ridiculously Small Units) conversion to pixels | 2234 | // magic numbers for TeX's RSU's (Ridiculously Small Units) conversion to pixels | ||
2235 | Okular::NormalizedPoint p( | 2235 | Okular::NormalizedPoint p( | ||
2236 | ( pt.x * dpi.width() ) / ( 72.27 * 65536.0 * m_pagesVector[pt.page]->width() ), | 2236 | ( pt.x * dpi.width() ) / ( 72.27 * 65536.0 * m_pagesVector[pt.page]->width() ), | ||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 2401 | { | |||
2408 | 2408 | | |||
2409 | QMimeDatabase mimeDatabase; | 2409 | QMimeDatabase mimeDatabase; | ||
2410 | 2410 | | |||
2411 | for (const KPluginMetaData& md : available) | 2411 | for (const KPluginMetaData& md : available) | ||
2412 | { | 2412 | { | ||
2413 | if (triedOffers.contains(md)) | 2413 | if (triedOffers.contains(md)) | ||
2414 | continue; | 2414 | continue; | ||
2415 | 2415 | | |||
2416 | foreach (const QString& supported, md.mimeTypes()) | 2416 | const QStringList mimetypes = md.mimeTypes(); | ||
2417 | for (const QString &supported : mimetypes) | ||||
2417 | { | 2418 | { | ||
2418 | QMimeType mimeType = mimeDatabase.mimeTypeForName(supported); | 2419 | QMimeType mimeType = mimeDatabase.mimeTypeForName(supported); | ||
2419 | if (mimeType == type && !exactMatches.contains(md)) { | 2420 | if (mimeType == type && !exactMatches.contains(md)) { | ||
2420 | exactMatches << md; | 2421 | exactMatches << md; | ||
2421 | } | 2422 | } | ||
2422 | 2423 | | |||
2423 | if (type.inherits(supported) && !offers.contains(md)) | 2424 | if (type.inherits(supported) && !offers.contains(md)) | ||
2424 | { | 2425 | { | ||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | 2614 | { | |||
2614 | d->loadSyncFile(docFile); | 2615 | d->loadSyncFile(docFile); | ||
2615 | } | 2616 | } | ||
2616 | 2617 | | |||
2617 | d->m_generatorName = offer.pluginId(); | 2618 | d->m_generatorName = offer.pluginId(); | ||
2618 | d->m_pageController = new PageController(); | 2619 | d->m_pageController = new PageController(); | ||
2619 | connect( d->m_pageController, SIGNAL(rotationFinished(int,Okular::Page*)), | 2620 | connect( d->m_pageController, SIGNAL(rotationFinished(int,Okular::Page*)), | ||
2620 | this, SLOT(rotationFinished(int,Okular::Page*)) ); | 2621 | this, SLOT(rotationFinished(int,Okular::Page*)) ); | ||
2621 | 2622 | | |||
2622 | foreach ( Page * p, d->m_pagesVector ) | 2623 | for ( Page *p : qAsConst(d->m_pagesVector) ) | ||
2623 | p->d->m_doc = d; | 2624 | p->d->m_doc = d; | ||
2624 | 2625 | | |||
2625 | d->m_metadataLoadingCompleted = false; | 2626 | d->m_metadataLoadingCompleted = false; | ||
2626 | d->m_docdataMigrationNeeded = false; | 2627 | d->m_docdataMigrationNeeded = false; | ||
2627 | 2628 | | |||
2628 | // 2. load Additional Data (bookmarks, local annotations and metadata) about the document | 2629 | // 2. load Additional Data (bookmarks, local annotations and metadata) about the document | ||
2629 | if ( d->m_archiveData ) | 2630 | if ( d->m_archiveData ) | ||
2630 | { | 2631 | { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
2683 | } | 2684 | } | ||
2684 | 2685 | | |||
2685 | AudioPlayer::instance()->d->m_currentDocument = fromFileDescriptor ? QUrl() : d->m_url; | 2686 | AudioPlayer::instance()->d->m_currentDocument = fromFileDescriptor ? QUrl() : d->m_url; | ||
2686 | 2687 | | |||
2687 | const QStringList docScripts = d->m_generator->metaData( QStringLiteral("DocumentScripts"), QStringLiteral ( "JavaScript" ) ).toStringList(); | 2688 | const QStringList docScripts = d->m_generator->metaData( QStringLiteral("DocumentScripts"), QStringLiteral ( "JavaScript" ) ).toStringList(); | ||
2688 | if ( !docScripts.isEmpty() ) | 2689 | if ( !docScripts.isEmpty() ) | ||
2689 | { | 2690 | { | ||
2690 | d->m_scripter = new Scripter( d ); | 2691 | d->m_scripter = new Scripter( d ); | ||
2691 | Q_FOREACH ( const QString &docscript, docScripts ) | 2692 | for ( const QString &docscript : docScripts ) | ||
2692 | { | 2693 | { | ||
2693 | d->m_scripter->execute( JavaScript, docscript ); | 2694 | d->m_scripter->execute( JavaScript, docscript ); | ||
2694 | } | 2695 | } | ||
2695 | } | 2696 | } | ||
2696 | 2697 | | |||
2697 | return OpenSuccess; | 2698 | return OpenSuccess; | ||
2698 | } | 2699 | } | ||
2699 | 2700 | | |||
▲ Show 20 Lines • Show All 1111 Lines • ▼ Show 20 Line(s) | 3803 | { | |||
3811 | d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), viewport ); | 3812 | d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), viewport ); | ||
3812 | } | 3813 | } | ||
3813 | 3814 | | |||
3814 | const int currentViewportPage = (*d->m_viewportIterator).pageNumber; | 3815 | const int currentViewportPage = (*d->m_viewportIterator).pageNumber; | ||
3815 | 3816 | | |||
3816 | const bool currentPageChanged = (oldPageNumber != currentViewportPage); | 3817 | const bool currentPageChanged = (oldPageNumber != currentViewportPage); | ||
3817 | 3818 | | |||
3818 | // notify change to all other (different from id) observers | 3819 | // notify change to all other (different from id) observers | ||
3819 | foreach(DocumentObserver *o, d->m_observers) | 3820 | for (DocumentObserver *o : qAsConst(d->m_observers)) | ||
3820 | { | 3821 | { | ||
3821 | if ( o != excludeObserver ) | 3822 | if ( o != excludeObserver ) | ||
3822 | o->notifyViewportChanged( smoothMove ); | 3823 | o->notifyViewportChanged( smoothMove ); | ||
3823 | 3824 | | |||
3824 | if ( currentPageChanged ) | 3825 | if ( currentPageChanged ) | ||
3825 | o->notifyCurrentPageChanged( oldPageNumber, currentViewportPage ); | 3826 | o->notifyCurrentPageChanged( oldPageNumber, currentViewportPage ); | ||
3826 | } | 3827 | } | ||
3827 | } | 3828 | } | ||
3828 | 3829 | | |||
3829 | void Document::setZoom(int factor, DocumentObserver *excludeObserver) | 3830 | void Document::setZoom(int factor, DocumentObserver *excludeObserver) | ||
3830 | { | 3831 | { | ||
3831 | // notify change to all other (different from id) observers | 3832 | // notify change to all other (different from id) observers | ||
3832 | foreach(DocumentObserver *o, d->m_observers) | 3833 | for (DocumentObserver *o : qAsConst(d->m_observers)) | ||
3833 | if (o != excludeObserver) | 3834 | if (o != excludeObserver) | ||
3834 | o->notifyZoom( factor ); | 3835 | o->notifyZoom( factor ); | ||
3835 | } | 3836 | } | ||
3836 | 3837 | | |||
3837 | void Document::setPrevViewport() | 3838 | void Document::setPrevViewport() | ||
3838 | // restore viewport from the history | 3839 | // restore viewport from the history | ||
3839 | { | 3840 | { | ||
3840 | if ( d->m_viewportIterator != d->m_viewportHistory.begin() ) | 3841 | if ( d->m_viewportIterator != d->m_viewportHistory.begin() ) | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 3886 | { | |||
3911 | s->cachedColor = color; | 3912 | s->cachedColor = color; | ||
3912 | s->isCurrentlySearching = true; | 3913 | s->isCurrentlySearching = true; | ||
3913 | 3914 | | |||
3914 | // global data for search | 3915 | // global data for search | ||
3915 | QSet< int > *pagesToNotify = new QSet< int >; | 3916 | QSet< int > *pagesToNotify = new QSet< int >; | ||
3916 | 3917 | | |||
3917 | // remove highlights from pages and queue them for notifying changes | 3918 | // remove highlights from pages and queue them for notifying changes | ||
3918 | *pagesToNotify += s->highlightedPages; | 3919 | *pagesToNotify += s->highlightedPages; | ||
3919 | foreach(int pageNumber, s->highlightedPages) | 3920 | for (const int pageNumber : qAsConst(s->highlightedPages)) { | ||
aacid: don't do const & for basic types, it's cheaper to copy them than to reference them | |||||
ahmadsamir: Thanks. Noted. | |||||
3920 | d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID ); | 3921 | d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID ); | ||
3922 | } | ||||
3921 | s->highlightedPages.clear(); | 3923 | s->highlightedPages.clear(); | ||
3922 | 3924 | | |||
3923 | // set hourglass cursor | 3925 | // set hourglass cursor | ||
3924 | QApplication::setOverrideCursor( Qt::WaitCursor ); | 3926 | QApplication::setOverrideCursor( Qt::WaitCursor ); | ||
3925 | 3927 | | |||
3926 | // 1. ALLDOC - process all document marking pages | 3928 | // 1. ALLDOC - process all document marking pages | ||
3927 | if ( type == AllDocument ) | 3929 | if ( type == AllDocument ) | ||
3928 | { | 3930 | { | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 4020 | { | |||
4024 | QMap< int, RunningSearch * >::iterator searchIt = d->m_searches.find( searchID ); | 4026 | QMap< int, RunningSearch * >::iterator searchIt = d->m_searches.find( searchID ); | ||
4025 | if ( searchIt == d->m_searches.end() ) | 4027 | if ( searchIt == d->m_searches.end() ) | ||
4026 | return; | 4028 | return; | ||
4027 | 4029 | | |||
4028 | // get previous parameters for search | 4030 | // get previous parameters for search | ||
4029 | RunningSearch * s = *searchIt; | 4031 | RunningSearch * s = *searchIt; | ||
4030 | 4032 | | |||
4031 | // unhighlight pages and inform observers about that | 4033 | // unhighlight pages and inform observers about that | ||
4032 | foreach(int pageNumber, s->highlightedPages) | 4034 | for (const int pageNumber : qAsConst(s->highlightedPages)) | ||
aacid: same | |||||
4033 | { | 4035 | { | ||
4034 | d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID ); | 4036 | d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID ); | ||
4035 | foreachObserver( notifyPageChanged( pageNumber, DocumentObserver::Highlights ) ); | 4037 | foreachObserver( notifyPageChanged( pageNumber, DocumentObserver::Highlights ) ); | ||
4036 | } | 4038 | } | ||
4037 | 4039 | | |||
4038 | // send the setup signal too (to update views that filter on matches) | 4040 | // send the setup signal too (to update views that filter on matches) | ||
4039 | foreachObserver( notifySetup( d->m_pagesVector, 0 ) ); | 4041 | foreachObserver( notifySetup( d->m_pagesVector, 0 ) ); | ||
4040 | 4042 | | |||
▲ Show 20 Lines • Show All 1866 Lines • Show Last 20 Lines |
don't do const & for basic types, it's cheaper to copy them than to reference them