Commit ccf3a384 authored by Ahmad Samir's avatar Ahmad Samir Committed by Albert Astals Cid
Browse files

[core/*] replace foreach, deprecated, with range-for

The code compiles and okular seems to load and work as before, all unit
tests pass except (parttest and epubgeneratortest, but they fail on master
too).
parent abc8e13a
Pipeline #11626 passed with stage
in 15 minutes and 18 seconds
......@@ -1629,7 +1629,7 @@ double LineAnnotationPrivate::distanceSqr( double x, double y, double xScale, do
if ( m_lineInnerColor.isValid() )
{
QPolygonF polygon;
foreach ( const NormalizedPoint &p, transformedLinePoints )
for ( const NormalizedPoint &p : qAsConst(transformedLinePoints) )
polygon.append( QPointF( p.x, p.y ) );
if ( polygon.containsPoint( QPointF( x, y ), Qt::WindingFill ) )
......@@ -2091,7 +2091,7 @@ double HighlightAnnotationPrivate::distanceSqr( double x, double y, double xScal
{
NormalizedPoint point( x, y );
double outsideDistance = DBL_MAX;
foreach ( const HighlightAnnotation::Quad& quad, m_highlightQuads )
for ( const HighlightAnnotation::Quad &quad : m_highlightQuads )
{
QLinkedList<NormalizedPoint> pathPoints;
......@@ -2306,7 +2306,7 @@ void InkAnnotation::store( QDomNode & node, QDomDocument & document ) const
double InkAnnotationPrivate::distanceSqr( double x, double y, double xScale, double yScale ) const
{
double distance = DBL_MAX;
foreach ( const QLinkedList<NormalizedPoint>& path, m_transformedInkPaths )
for ( const QLinkedList<NormalizedPoint> &path : m_transformedInkPaths )
{
const double thisDistance = ::distanceSqr( x, y, xScale, yScale, path );
if ( thisDistance < distance )
......
......@@ -281,7 +281,7 @@ KBookmark::List BookmarkManager::bookmarks( int page ) const
{
const KBookmark::List bmarks = bookmarks();
KBookmark::List ret;
foreach( const KBookmark &bm, bmarks )
for ( const KBookmark &bm : bmarks )
{
DocumentViewport vp( bm.url().fragment(QUrl::FullyDecoded) );
if ( vp.isValid() && vp.pageNumber == page )
......@@ -296,7 +296,7 @@ KBookmark::List BookmarkManager::bookmarks( int page ) const
KBookmark BookmarkManager::bookmark( int page ) const
{
const KBookmark::List bmarks = bookmarks();
foreach( const KBookmark &bm, bmarks )
for ( const KBookmark &bm : bmarks )
{
DocumentViewport vp( bm.url().fragment(QUrl::FullyDecoded) );
if ( vp.isValid() && vp.pageNumber == page )
......@@ -552,7 +552,7 @@ void BookmarkManager::removeBookmarks(const QUrl &referurl, const KBookmark::Lis
const QHash<int,int> oldUrlBookmarks = d->urlBookmarks;
bool deletedAny = false;
foreach ( const KBookmark & bm, list )
for ( const KBookmark &bm : list )
{
if ( bm.parentGroup() == thebg )
{
......@@ -708,7 +708,7 @@ KBookmark BookmarkManager::nextBookmark( const DocumentViewport &viewport) const
std::sort(bmarks.begin(), bmarks.end(), bookmarkLessThan);
KBookmark bookmark;
foreach ( const KBookmark &bm, bmarks )
for ( const KBookmark &bm : qAsConst(bmarks) )
{
DocumentViewport vp( bm.url().fragment(QUrl::FullyDecoded) );
if ( viewport < vp )
......
......@@ -309,7 +309,7 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong memoryToFree )
while (memoryToFree > 0)
{
int clean_hits = 0;
foreach (DocumentObserver *observer, m_observers)
for (DocumentObserver *observer : qAsConst(m_observers))
{
AllocatedPixmap * p = searchLowestPriorityPixmap( false, true, observer );
if ( !p ) // No pixmap to remove
......@@ -646,7 +646,7 @@ bool DocumentPrivate::loadDocumentInfo( QFile &infoFile, LoadDocumentInfoFlags l
if ( viewElement.tagName() == QLatin1String("view") )
{
const QString viewName = viewElement.attribute( QStringLiteral("name") );
Q_FOREACH ( View * view, m_views )
for ( View *view : qAsConst(m_views) )
{
if ( view->name() == viewName )
{
......@@ -1327,7 +1327,7 @@ void DocumentPrivate::saveDocumentInfo() const
// create views root node
QDomElement viewsNode = doc.createElement( QStringLiteral("views") );
generalInfo.appendChild( viewsNode );
Q_FOREACH ( View * view, m_views )
for ( View *view : qAsConst(m_views) )
{
QDomElement viewEntry = doc.createElement( QStringLiteral("view") );
viewEntry.setAttribute( QStringLiteral("name"), view->name() );
......@@ -1649,7 +1649,7 @@ void DocumentPrivate::refreshPixmaps( int pageNumber )
m_parent->requestPixmaps( requestedPixmaps, Okular::Document::NoOption );
}
foreach (DocumentObserver *observer, m_observers)
for (DocumentObserver *observer : qAsConst(m_observers))
{
QLinkedList< Okular::PixmapRequest * > requestedPixmaps;
......@@ -2225,7 +2225,7 @@ void DocumentPrivate::loadSyncFile( const QString & filePath )
}
QVector< QLinkedList< Okular::SourceRefObjectRect * > > refRects( m_pagesVector.size() );
foreach ( const pdfsyncpoint& pt, points )
for ( const pdfsyncpoint &pt : qAsConst(points) )
{
// drop pdfsync points not completely valid
if ( pt.page < 0 || pt.page >= m_pagesVector.size() )
......@@ -2413,7 +2413,8 @@ KPluginMetaData DocumentPrivate::generatorForMimeType(const QMimeType& type, QWi
if (triedOffers.contains(md))
continue;
foreach (const QString& supported, md.mimeTypes())
const QStringList mimetypes = md.mimeTypes();
for (const QString &supported : mimetypes)
{
QMimeType mimeType = mimeDatabase.mimeTypeForName(supported);
if (mimeType == type && !exactMatches.contains(md)) {
......@@ -2619,7 +2620,7 @@ Document::OpenResult Document::openDocument(const QString & docFile, const QUrl
connect( d->m_pageController, SIGNAL(rotationFinished(int,Okular::Page*)),
this, SLOT(rotationFinished(int,Okular::Page*)) );
foreach ( Page * p, d->m_pagesVector )
for ( Page *p : qAsConst(d->m_pagesVector) )
p->d->m_doc = d;
d->m_metadataLoadingCompleted = false;
......@@ -2688,7 +2689,7 @@ Document::OpenResult Document::openDocument(const QString & docFile, const QUrl
if ( !docScripts.isEmpty() )
{
d->m_scripter = new Scripter( d );
Q_FOREACH ( const QString &docscript, docScripts )
for ( const QString &docscript : docScripts )
{
d->m_scripter->execute( JavaScript, docscript );
}
......@@ -3816,7 +3817,7 @@ void Document::setViewport( const DocumentViewport & viewport, DocumentObserver
const bool currentPageChanged = (oldPageNumber != currentViewportPage);
// 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->notifyViewportChanged( smoothMove );
......@@ -3829,7 +3830,7 @@ void Document::setViewport( const DocumentViewport & viewport, DocumentObserver
void Document::setZoom(int factor, DocumentObserver *excludeObserver)
{
// 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->notifyZoom( factor );
}
......@@ -3916,8 +3917,9 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
// remove highlights from pages and queue them for notifying changes
*pagesToNotify += s->highlightedPages;
foreach(int pageNumber, s->highlightedPages)
for (const int pageNumber : qAsConst(s->highlightedPages)) {
d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID );
}
s->highlightedPages.clear();
// set hourglass cursor
......@@ -4029,7 +4031,7 @@ void Document::resetSearch( int searchID )
RunningSearch * s = *searchIt;
// unhighlight pages and inform observers about that
foreach(int pageNumber, s->highlightedPages)
for (const int pageNumber : qAsConst(s->highlightedPages))
{
d->m_pagesVector.at(pageNumber)->d->deleteHighlights( searchID );
foreachObserver( notifyPageChanged( pageNumber, DocumentObserver::Highlights ) );
......
......@@ -49,7 +49,7 @@ Okular::NormalizedRect buildBoundingRectangleForButtons( const QList<Okular::For
double right = 0.0;
double bottom = 0.0;
foreach( FormFieldButton* formButton, formButtons )
for( const FormFieldButton *formButton : formButtons )
{
left = qMin<double>( left, formButton->rect().left );
top = qMin<double>( top, formButton->rect().top );
......@@ -688,7 +688,7 @@ EditFormButtonsCommand::EditFormButtonsCommand( Okular::DocumentPrivate* docPriv
m_prevButtonStates( QList< bool >() )
{
setText( i18nc( "Edit the state of a group of form buttons", "edit form button states" ) );
foreach( FormFieldButton* formButton, m_formButtons )
for ( const FormFieldButton *formButton : qAsConst(m_formButtons) )
{
m_prevButtonStates.append( formButton->state() );
}
......@@ -730,7 +730,7 @@ bool EditFormButtonsCommand::refreshInternalPageReferences( const QVector< Okula
{
const QList< FormFieldButton* > oldFormButtons = m_formButtons;
m_formButtons.clear();
foreach( FormFieldButton* oldFormButton, oldFormButtons )
for ( FormFieldButton *oldFormButton : oldFormButtons )
{
FormFieldButton *button = dynamic_cast<FormFieldButton *>(Okular::PagePrivate::findEquivalentForm( newPagesVector[m_pageNumber], oldFormButton ));
if ( !button )
......@@ -743,7 +743,7 @@ bool EditFormButtonsCommand::refreshInternalPageReferences( const QVector< Okula
void EditFormButtonsCommand::clearFormButtonStates()
{
foreach( FormFieldButton* formButton, m_formButtons )
for ( FormFieldButton *formButton : qAsConst(m_formButtons) )
{
formButton->setState( false );
}
......
......@@ -236,9 +236,9 @@ class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
void setValue( const QString& v ) override
{
Q_Q( FormFieldChoice );
QStringList choices = v.split( QLatin1Char (';'), QString::SkipEmptyParts );
const QStringList choices = v.split( QLatin1Char (';'), QString::SkipEmptyParts );
QList<int> newchoices;
foreach ( const QString& str, choices )
for ( const QString &str : choices )
{
bool ok = true;
int val = str.toInt( &ok );
......@@ -255,7 +255,7 @@ class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
QList<int> choices = q->currentChoices();
std::sort(choices.begin(), choices.end());
QStringList list;
foreach ( int c, choices )
for ( const int c : qAsConst(choices) )
{
list.append( QString::number( c ) );
}
......
......@@ -166,8 +166,8 @@ void FontExtractionThread::run()
{
for ( int i = -1; i < mNumOfPages && mGoOn; ++i )
{
FontInfo::List list = mGenerator->fontsForPage( i );
foreach ( const FontInfo& fi, list )
const FontInfo::List list = mGenerator->fontsForPage( i );
for ( const FontInfo &fi : list )
{
emit gotFont( fi );
}
......
......@@ -501,7 +501,7 @@ QLinkedList< Annotation* > Page::annotations() const
Annotation * Page::annotation( const QString & uniqueName ) const
{
foreach(Annotation *a, m_annotations)
for (Annotation *a : m_annotations)
{
if ( a->uniqueName() == uniqueName )
return a;
......@@ -627,8 +627,9 @@ void PagePrivate::setTextSelections( RegularAreaRect *r, const QColor & color )
void Page::setSourceReferences( const QLinkedList< SourceRefObjectRect * > & refRects )
{
deleteSourceReferences();
foreach( SourceRefObjectRect * rect, refRects )
for ( SourceRefObjectRect *rect : refRects ) {
m_rects << rect;
}
}
void Page::setDuration( double seconds )
......@@ -1096,19 +1097,19 @@ FormField *PagePrivate::findEquivalentForm( const Page *p, FormField *oldField )
{
// given how id is not very good of id (at least for pdf) we do a few passes
// same rect, type and id
foreach(FormField *f, p->d->formfields)
for (FormField *f : qAsConst(p->d->formfields))
{
if (f->rect() == oldField->rect() && f->type() == oldField->type() && f->id() == oldField->id())
return f;
}
// same rect and type
foreach(FormField *f, p->d->formfields)
for (FormField *f : qAsConst(p->d->formfields))
{
if (f->rect() == oldField->rect() && f->type() == oldField->type())
return f;
}
// fuzzy rect, same type and id
foreach(FormField *f, p->d->formfields)
for (FormField *f : qAsConst(p->d->formfields))
{
if (f->type() == oldField->type() && f->id() == oldField->id() && qFuzzyCompare(f->rect().left, oldField->rect().left) && qFuzzyCompare(f->rect().top, oldField->rect().top) && qFuzzyCompare(f->rect().right, oldField->rect().right) && qFuzzyCompare(f->rect().bottom, oldField->rect().bottom))
{
......@@ -1116,7 +1117,7 @@ FormField *PagePrivate::findEquivalentForm( const Page *p, FormField *oldField )
}
}
// fuzzy rect and same type
foreach(FormField *f, p->d->formfields)
for (FormField *f : qAsConst(p->d->formfields))
{
if (f->type() == oldField->type() && qFuzzyCompare(f->rect().left, oldField->rect().left) && qFuzzyCompare(f->rect().top, oldField->rect().top) && qFuzzyCompare(f->rect().right, oldField->rect().right) && qFuzzyCompare(f->rect().bottom, oldField->rect().bottom))
{
......
......@@ -308,12 +308,12 @@ Document::OpenResult TextDocumentGenerator::loadDocumentWithPassword( const QStr
// loading failed, cleanup all the stuff eventually gathered from the converter
d->mTitlePositions.clear();
Q_FOREACH ( const TextDocumentGeneratorPrivate::LinkPosition &linkPos, d->mLinkPositions )
for ( const TextDocumentGeneratorPrivate::LinkPosition &linkPos : qAsConst(d->mLinkPositions) )
{
delete linkPos.link;
}
d->mLinkPositions.clear();
Q_FOREACH ( const TextDocumentGeneratorPrivate::AnnotationPosition &annPos, d->mAnnotationPositions )
for ( const TextDocumentGeneratorPrivate::AnnotationPosition &annPos : qAsConst(d->mAnnotationPositions) )
{
delete annPos.annotation;
}
......@@ -576,7 +576,7 @@ void TextDocumentGenerator::setTextDocument( QTextDocument *textDocument )
d->mDocument = textDocument;
Q_FOREACH (Page *p, d->m_document->m_pagesVector )
for (Page *p : qAsConst(d->m_document->m_pagesVector))
{
p->setTextPage( nullptr );
}
......
......@@ -298,8 +298,9 @@ public:
inline QString string() const
{
QString res;
foreach(const WordWithCharacters &word, m_region_wordWithCharacters)
for (const WordWithCharacters &word : m_region_wordWithCharacters) {
res += word.text();
}
return res;
}
......@@ -1911,7 +1912,7 @@ void TextPagePrivate::correctTextOrder()
* Break the words into characters
*/
TextList listOfCharacters;
foreach(const WordWithCharacters &word, listWithWordsAndSpaces)
for (const WordWithCharacters &word : listWithWordsAndSpaces)
{
delete word.word;
listOfCharacters.append(word.characters);
......@@ -1927,7 +1928,7 @@ TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionB
TextEntity::List ret;
if ( area )
{
foreach (TinyTextEntity *te, d->m_words)
for (const TinyTextEntity *te : qAsConst(d->m_words))
{
if (b == AnyPixelTextAreaInclusionBehaviour)
{
......@@ -1948,7 +1949,7 @@ TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionB
}
else
{
foreach (TinyTextEntity *te, d->m_words)
for (const TinyTextEntity *te : qAsConst(d->m_words))
{
ret.append( new TextEntity( te->text(), new Okular::NormalizedRect( te->area) ) );
}
......
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