diff --git a/autotests/annotationstest.cpp b/autotests/annotationstest.cpp index 803613df4..5e160280d 100644 --- a/autotests/annotationstest.cpp +++ b/autotests/annotationstest.cpp @@ -49,9 +49,12 @@ void AnnotationTest::initTestCase() void AnnotationTest::cleanupTestCase() { - if ( m_document->isOpened() ) - foreach ( Okular::Annotation* annotation, m_document->page( 0 )->annotations() ) + if ( m_document->isOpened() ) { + const QLinkedList annotations = m_document->page( 0 )->annotations(); + for ( Okular::Annotation* annotation : annotations ) { m_document->removePageAnnotation( 0, annotation ); + } + } } diff --git a/autotests/kjsfunctionstest.cpp b/autotests/kjsfunctionstest.cpp index 00f418b8e..c52fca280 100644 --- a/autotests/kjsfunctionstest.cpp +++ b/autotests/kjsfunctionstest.cpp @@ -45,9 +45,9 @@ public: private slots: void closeMessageBox() { - QWidgetList allToplevelWidgets = QApplication::topLevelWidgets(); + const QWidgetList allToplevelWidgets = QApplication::topLevelWidgets(); QMessageBox *mb = nullptr; - foreach ( QWidget *w, allToplevelWidgets ) { + for ( QWidget *w : allToplevelWidgets ) { if ( w->inherits( "QMessageBox" ) ) { mb = qobject_cast< QMessageBox * >( w ); QCOMPARE( mb->text(), m_message ); diff --git a/autotests/mainshelltest.cpp b/autotests/mainshelltest.cpp index 58a4749b4..2d14ed698 100644 --- a/autotests/mainshelltest.cpp +++ b/autotests/mainshelltest.cpp @@ -94,7 +94,8 @@ private: QList getShells() { QList shells; - foreach( KMainWindow* kmw, KMainWindow::memberList() ) + const QList< KMainWindow * > mainWindows = KMainWindow::memberList(); + for ( KMainWindow* kmw : mainWindows ) { Shell* shell = qobject_cast( kmw ); if( shell ) @@ -107,7 +108,8 @@ QList getShells() Shell *findShell(Shell *ignore = nullptr) { - foreach (QWidget *widget, QApplication::topLevelWidgets()) + const QWidgetList wList = QApplication::topLevelWidgets(); + for (QWidget *widget : wList ) { Shell *s = qobject_cast(widget); if (s && s != ignore) @@ -145,12 +147,12 @@ void MainShellTest::init() Okular::Settings::self()->setDefaults(); // Clean docdatas - QList urls; - urls << QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/file1.pdf")); - urls << QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/tocreload.pdf")); - urls << QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/contents.epub")); + const QList urls = { QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/file1.pdf")) + , QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/tocreload.pdf")) + , QUrl::fromUserInput(QStringLiteral("file://" KDESRCDIR "data/contents.epub")) + }; - foreach (const QUrl &url, urls) + for (const QUrl &url : urls) { QFileInfo fileReadTest( url.toLocalFile() ); const QString docDataPath = Okular::DocumentPrivate::docDataFileName(url, fileReadTest.size()); @@ -296,7 +298,7 @@ void MainShellTest::testShell() QCOMPARE(partDocument(part2)->currentPage(), expectedPage); openUrls << part2->url().url(); - foreach(const QString &path, paths) + for (const QString &path : qAsConst(paths)) { QVERIFY(openUrls.contains(QStringLiteral("file://%1").arg(path))); } @@ -531,7 +533,7 @@ void MainShellTest::testSessionRestore() QList shells = getShells(); QVERIFY( !shells.isEmpty() ); int numDocs = 0; - foreach( Shell* shell, shells ) + for ( Shell *shell : qAsConst(shells) ) { QVERIFY( QTest::qWaitForWindowExposed( shell ) ); numDocs += shell->m_tabs.size(); @@ -552,7 +554,7 @@ void MainShellTest::testSessionRestore() int numWindows = 0; { // Scope for config so that we can reconstruct from file KConfig config( configFile.fileName(), KConfig::SimpleConfig ); - foreach( Shell* shell, shells ) + for ( Shell *shell : qAsConst(shells) ) { shell->savePropertiesInternal( &config, ++numWindows ); // Windows aren't necessarily closed on shutdown, but we'll use @@ -587,7 +589,7 @@ void MainShellTest::testSessionRestore() shells = getShells(); QVERIFY( !shells.isEmpty() ); numDocs = 0; - foreach( Shell* shell, shells ) + for ( Shell* shell : qAsConst(shells) ) { QVERIFY( QTest::qWaitForWindowExposed( shell ) ); numDocs += shell->m_tabs.size(); diff --git a/conf/dlgaccessibility.cpp b/conf/dlgaccessibility.cpp index cbeba7c94..86532fb56 100644 --- a/conf/dlgaccessibility.cpp +++ b/conf/dlgaccessibility.cpp @@ -30,8 +30,9 @@ DlgAccessibility::DlgAccessibility( QWidget * parent ) m_color_pages.append( m_dlg->page_paperColor ); m_color_pages.append( m_dlg->page_darkLight ); m_color_pages.append( m_dlg->page_bw ); - foreach ( QWidget * page, m_color_pages ) + for ( QWidget *page : qAsConst(m_color_pages) ) { page->hide(); + } m_color_pages[ m_selected ]->show(); #ifdef HAVE_SPEECH diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index 5f565cc26..32f7294dc 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -85,7 +85,7 @@ void WidgetAnnotTools::setTools(const QStringList& items) m_list->clear(); // Parse each string and populate the list widget - foreach ( const QString &toolXml, items ) + for ( const QString &toolXml : items ) { QDomDocument entryParser; if ( !entryParser.setContent( toolXml ) ) diff --git a/conf/widgetdrawingtools.cpp b/conf/widgetdrawingtools.cpp index 7fbb802b6..f221e0d4b 100644 --- a/conf/widgetdrawingtools.cpp +++ b/conf/widgetdrawingtools.cpp @@ -75,7 +75,7 @@ void WidgetDrawingTools::setTools( const QStringList &items ) m_list->clear(); // Parse each string and populate the list widget - foreach ( const QString &toolXml, items ) + for ( const QString &toolXml : items ) { QDomDocument entryParser; if ( !entryParser.setContent( toolXml ) ) diff --git a/extensions.cpp b/extensions.cpp index 3c0d8a8f0..5568039fe 100644 --- a/extensions.cpp +++ b/extensions.cpp @@ -106,7 +106,7 @@ QString OkularLiveConnectExtension::eval( const QString &script ) void OkularLiveConnectExtension::postMessage( const QStringList &args ) { QStringList arrayargs; - Q_FOREACH ( const QString &arg, args ) + for ( const QString &arg : args ) { QString newarg = arg; newarg.replace( QLatin1Char('\''), QLatin1String("\\'") ); diff --git a/mobile/components/documentitem.cpp b/mobile/components/documentitem.cpp index 44f102fc6..cc2fed151 100644 --- a/mobile/components/documentitem.cpp +++ b/mobile/components/documentitem.cpp @@ -153,7 +153,8 @@ QVariantList DocumentItem::bookmarkedPages() const { QList list; QSet pages; - foreach (const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) { + const KBookmark::List bMarks = m_document->bookmarkManager()->bookmarks(); + for (const KBookmark &bookmark : bMarks) { Okular::DocumentViewport viewport(bookmark.url().fragment()); pages << viewport.pageNumber; } @@ -161,7 +162,7 @@ QVariantList DocumentItem::bookmarkedPages() const std::sort(list.begin(), list.end()); QVariantList variantList; - foreach (const int page, list) { + for (const int page : qAsConst(list)) { variantList << page; } return variantList; @@ -170,7 +171,8 @@ QVariantList DocumentItem::bookmarkedPages() const QStringList DocumentItem::bookmarks() const { QStringList list; - foreach(const KBookmark &bookmark, m_document->bookmarkManager()->bookmarks()) { + const KBookmark::List bMarks = m_document->bookmarkManager()->bookmarks(); + for (const KBookmark &bookmark : bMarks) { list << bookmark.url().toString(); } return list; diff --git a/mobile/components/pageitem.cpp b/mobile/components/pageitem.cpp index 75930bfe9..d7f4cc917 100644 --- a/mobile/components/pageitem.cpp +++ b/mobile/components/pageitem.cpp @@ -215,7 +215,9 @@ void PageItem::setBookmarked(bool bookmarked) QStringList PageItem::bookmarks() const { QStringList list; - foreach(const KBookmark &bookmark, m_documentItem.data()->document()->bookmarkManager()->bookmarks(m_viewPort.pageNumber)) { + const KBookmark::List pageMarks = + m_documentItem.data()->document()->bookmarkManager()->bookmarks(m_viewPort.pageNumber); + for (const KBookmark &bookmark : pageMarks) { list << bookmark.url().toString(); } return list; diff --git a/part.cpp b/part.cpp index eff4bf027..b0a1c9832 100644 --- a/part.cpp +++ b/part.cpp @@ -254,7 +254,7 @@ static Okular::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *parent && ( QByteArray( "KHTMLPart" ) == parent->metaObject()->className() ) ) return Okular::KHTMLPartMode; - Q_FOREACH ( const QVariant &arg, args ) + for ( const QVariant &arg : args ) { if ( arg.type() == QVariant::String ) { @@ -274,7 +274,7 @@ static Okular::EmbedMode detectEmbedMode( QWidget *parentWidget, QObject *parent static QString detectConfigFileName( const QVariantList &args ) { - Q_FOREACH ( const QVariant &arg, args ) + for ( const QVariant &arg : args ) { if ( arg.type() == QVariant::String ) { @@ -2909,8 +2909,8 @@ void Part::checkNativeSaveDataLoss(bool *out_wontSaveForms, bool *out_wontSaveAn for ( int pageno = 0; pageno < pagecount; ++pageno ) { - const Okular::Page *page = m_document->page( pageno ); - foreach ( const Okular::Annotation *ann, page->annotations() ) + const QLinkedList< Okular::Annotation* > annotations = m_document->page( pageno )->annotations(); + for ( const Okular::Annotation *ann : annotations ) { if ( !(ann->flags() & Okular::Annotation::External) ) { diff --git a/shell/okular_main.cpp b/shell/okular_main.cpp index fdbaf6e68..bd54349cf 100644 --- a/shell/okular_main.cpp +++ b/shell/okular_main.cpp @@ -56,7 +56,7 @@ static bool attachExistingInstance(const QStringList &paths, const QString &seri const int desktop = KWindowSystem::currentDesktop(); // Select the first instance that isn't us (metric may change in future) - foreach ( const QString& service, services ) + for ( const QString &service : services ) { if ( service.startsWith(pattern) && !service.endsWith( myPid ) ) { @@ -74,7 +74,7 @@ static bool attachExistingInstance(const QStringList &paths, const QString &seri if ( !bestService ) return false; - foreach( const QString &arg, paths ) + for ( const QString &arg : paths ) { // Copy stdin to temporary file which can be opened by the existing // window. The temp file is automatically deleted after it has been diff --git a/shell/shell.cpp b/shell/shell.cpp index 8c0c62e5b..fe994dab5 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -447,7 +447,7 @@ void Shell::fileOpen() QMimeDatabase mimeDatabase; QSet globPatterns; QMap namedGlobs; - foreach ( const QString &mimeName, m_fileformats ) { + for ( const QString &mimeName : qAsConst(m_fileformats) ) { QMimeType mimeType = mimeDatabase.mimeTypeForName( mimeName ); const QStringList globs( mimeType.globPatterns() ); if ( globs.isEmpty() ) { @@ -460,11 +460,9 @@ void Shell::fileOpen() } QStringList namePatterns; - foreach( const QString &name, namedGlobs.keys()) { - namePatterns.append( name + - QStringLiteral(" (") + - namedGlobs[name].join( QLatin1Char(' ') ) + - QStringLiteral(")") + for ( auto it = namedGlobs.cbegin(); it != namedGlobs.cend(); ++it ) { + namePatterns.append( it.key() + QLatin1String(" (") + + it.value().join( QLatin1Char(' ') ) + QLatin1Char(')') ); } @@ -474,7 +472,8 @@ void Shell::fileOpen() dlg->setWindowTitle( i18n("Open Document") ); if ( dlg->exec() && dlg ) { - foreach(const QUrl& url, dlg->selectedUrls()) + const QList urlList = dlg->selectedUrls(); + for (const QUrl &url : urlList) { openUrl( url ); } @@ -774,7 +773,7 @@ int Shell::findTabIndex( QObject* sender ) void Shell::handleDroppedUrls( const QList& urls ) { - foreach( const QUrl& url, urls ) + for ( const QUrl &url : urls ) { openUrl( url ); }