Commit 45c72ff0 authored by Ahmad Samir's avatar Ahmad Samir Committed by Albert Astals Cid

Port from deprecated foreach to range-for

autotests/*, conf/* , mobile/* , shell/*, part.cpp, extension.cpp

The code compiles and all unit tests pass (except for the two that
fail on master too).
parent 3403a16f
......@@ -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<Okular::Annotation *> annotations = m_document->page( 0 )->annotations();
for ( Okular::Annotation* annotation : annotations ) {
m_document->removePageAnnotation( 0, annotation );
}
}
}
......
......@@ -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 );
......
......@@ -94,7 +94,8 @@ private:
QList<Shell*> getShells()
{
QList<Shell*> shells;
foreach( KMainWindow* kmw, KMainWindow::memberList() )
const QList< KMainWindow * > mainWindows = KMainWindow::memberList();
for ( KMainWindow* kmw : mainWindows )
{
Shell* shell = qobject_cast<Shell*>( kmw );
if( shell )
......@@ -107,7 +108,8 @@ QList<Shell*> getShells()
Shell *findShell(Shell *ignore = nullptr)
{
foreach (QWidget *widget, QApplication::topLevelWidgets())
const QWidgetList wList = QApplication::topLevelWidgets();
for (QWidget *widget : wList )
{
Shell *s = qobject_cast<Shell*>(widget);
if (s && s != ignore)
......@@ -145,12 +147,12 @@ void MainShellTest::init()
Okular::Settings::self()->setDefaults();
// Clean docdatas
QList<QUrl> 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<QUrl> 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<Shell*> 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();
......
......@@ -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
......
......@@ -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 ) )
......
......@@ -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 ) )
......
......@@ -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("\\'") );
......
......@@ -153,7 +153,8 @@ QVariantList DocumentItem::bookmarkedPages() const
{
QList<int> list;
QSet<int> 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;
......
......@@ -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;
......
......@@ -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) )
{
......
......@@ -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
......
......@@ -447,7 +447,7 @@ void Shell::fileOpen()
QMimeDatabase mimeDatabase;
QSet<QString> globPatterns;
QMap<QString, QStringList> 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<QUrl> urlList = dlg->selectedUrls();
for (const QUrl &url : urlList)
{
openUrl( url );
}
......@@ -774,7 +773,7 @@ int Shell::findTabIndex( QObject* sender )
void Shell::handleDroppedUrls( const QList<QUrl>& urls )
{
foreach( const QUrl& url, urls )
for ( const QUrl &url : urls )
{
openUrl( url );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment