diff --git a/autotests/generatorstest.cpp b/autotests/generatorstest.cpp index 1d9c701b5..b45a39fa3 100644 --- a/autotests/generatorstest.cpp +++ b/autotests/generatorstest.cpp @@ -40,7 +40,7 @@ void GeneratorsTest::testLoadsCorrectly() } int failures = 0; int successful = 0; - foreach (const QString &lib, generatorLibs) { + for (const QString &lib : qAsConst(generatorLibs)) { KPluginLoader loader(lib); QVERIFY2(!loader.fileName().isEmpty(), qPrintable(lib)); qDebug() << loader.fileName(); diff --git a/core/document.cpp b/core/document.cpp index 1f0abee78..f03be1173 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1171,12 +1171,13 @@ void DocumentPrivate::recalculateForms() { const QVariant fco = m_parent->metaData(QStringLiteral("FormCalculateOrder")); const QVector formCalculateOrder = fco.value>(); - foreach (int formId, formCalculateOrder) { + for (int formId : formCalculateOrder) { for (uint pageIdx = 0; pageIdx < m_parent->pages(); pageIdx++) { const Page *p = m_parent->page(pageIdx); if (p) { bool pageNeedsRefresh = false; - foreach (FormField *form, p->formFields()) { + const QLinkedList forms = p->formFields(); + for (FormField *form : forms) { if (form->id() == formId) { Action *action = form->additionalAction(FormField::CalculateField); if (action) { @@ -1516,8 +1517,9 @@ void DocumentPrivate::rotationFinished(int page, Okular::Page *okularPage) return; } - foreach (DocumentObserver *o, m_observers) + for (DocumentObserver *o : qAsConst(m_observers)) { o->notifyPageChanged(page, DocumentObserver::Pixmap | DocumentObserver::Annotations); + } } void DocumentPrivate::slotFontReadingProgress(int page) @@ -1752,9 +1754,11 @@ void DocumentPrivate::doProcessSearchMatch(RegularAreaRect *match, RunningSearch } // notify observers about highlights changes - foreach (int pageNumber, *pagesToNotify) - foreach (DocumentObserver *observer, m_observers) + for (int pageNumber : qAsConst(*pagesToNotify)) { + for (DocumentObserver *observer : qAsConst(m_observers)) { observer->notifyPageChanged(pageNumber, DocumentObserver::Highlights); + } + } if (foundAMatch) { Q_EMIT m_parent->searchFinished(searchID, Document::MatchFound); @@ -1781,8 +1785,9 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void * } Q_EMIT m_parent->searchFinished(searchID, Document::SearchCancelled); - foreach (const MatchesVector &mv, *pageMatches) + for (const MatchesVector &mv : qAsConst(*pageMatches)) { qDeleteAll(mv); + } delete pageMatches; delete pagesToNotify; return; @@ -1827,7 +1832,7 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void * it = pageMatches->constBegin(); itEnd = pageMatches->constEnd(); for (; it != itEnd; ++it) { - foreach (RegularAreaRect *match, it.value()) { + for (RegularAreaRect *match : it.value()) { it.key()->d->setHighlight(searchID, match, search->cachedColor); delete match; } @@ -1835,13 +1840,16 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void * pagesToNotify->insert(it.key()->number()); } - foreach (DocumentObserver *observer, m_observers) + for (DocumentObserver *observer : qAsConst(m_observers)) { observer->notifySetup(m_pagesVector, 0); + } // notify observers about highlights changes - foreach (int pageNumber, *pagesToNotify) - foreach (DocumentObserver *observer, m_observers) + for (int pageNumber : qAsConst(*pagesToNotify)) { + for (DocumentObserver *observer : qAsConst(m_observers)) { observer->notifyPageChanged(pageNumber, DocumentObserver::Highlights); + } + } if (foundAMatch) { Q_EMIT m_parent->searchFinished(searchID, Document::MatchFound); @@ -1872,9 +1880,10 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo Q_EMIT m_parent->searchFinished(searchID, Document::SearchCancelled); - foreach (const MatchesVector &mv, *pageMatches) { - foreach (const MatchColor &mc, mv) + for (const MatchesVector &mv : qAsConst(*pageMatches)) { + for (const MatchColor &mc : mv) { delete mc.first; + } } delete pageMatches; delete pagesToNotify; @@ -1930,9 +1939,10 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo // if not all words are present in page, remove partial highlights const bool matchAll = search->cachedType == Document::GoogleAll; if (!allMatched && matchAll) { - QVector &matches = (*pageMatches)[page]; - foreach (const MatchColor &mc, matches) + const QVector &matches = (*pageMatches)[page]; + for (const MatchColor &mc : matches) { delete mc.first; + } pageMatches->remove(page); } @@ -1947,7 +1957,7 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo it = pageMatches->constBegin(); itEnd = pageMatches->constEnd(); for (; it != itEnd; ++it) { - foreach (const MatchColor &mc, it.value()) { + for (const MatchColor &mc : it.value()) { it.key()->d->setHighlight(searchID, mc.first, mc.second); delete mc.first; } @@ -1956,13 +1966,16 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo } // send page lists to update observers (since some filter on bookmarks) - foreach (DocumentObserver *observer, m_observers) + for (DocumentObserver *observer : qAsConst(m_observers)) { observer->notifySetup(m_pagesVector, 0); + } // notify observers about highlights changes - foreach (int pageNumber, *pagesToNotify) - foreach (DocumentObserver *observer, m_observers) + for (int pageNumber : qAsConst(*pagesToNotify)) { + for (DocumentObserver *observer : qAsConst(m_observers)) { observer->notifyPageChanged(pageNumber, DocumentObserver::Highlights); + } + } if (foundAMatch) { Q_EMIT m_parent->searchFinished(searchID, Document::MatchFound); @@ -3008,10 +3021,11 @@ void Document::setVisiblePageRects(const QVector &visiblePage } d->m_pageRects = visiblePageRects; // notify change to all other (different from id) observers - foreach (DocumentObserver *o, d->m_observers) + for (DocumentObserver *o : qAsConst(d->m_observers)) { if (o != excludeObserver) { o->notifyVisibleRectsChanged(); } + } } uint Document::currentPage() const @@ -3582,7 +3596,7 @@ void Document::removePageAnnotation(int page, Annotation *annotation) void Document::removePageAnnotations(int page, const QList &annotations) { d->m_undoStack->beginMacro(i18nc("remove a collection of annotations from the page", "remove annotations")); - foreach (Annotation *annotation, annotations) { + for (Annotation *annotation : annotations) { QUndoCommand *uc = new RemoveAnnotationCommand(this->d, annotation, page); d->m_undoStack->push(uc); } diff --git a/part/annotationwidgets.cpp b/part/annotationwidgets.cpp index c52d62dc3..77d0977c7 100644 --- a/part/annotationwidgets.cpp +++ b/part/annotationwidgets.cpp @@ -469,8 +469,7 @@ void StampAnnotationWidget::createStyleWidget(QFormLayout *formlayout) formlayout->addRow(i18n("Stamp symbol:"), m_pixmapSelector); m_pixmapSelector->setEditable(true); - QPair pair; - foreach (pair, defaultStamps()) { + for (const QPair &pair : defaultStamps()) { m_pixmapSelector->addItem(pair.first, pair.second); }