From eddbe031288e61ace9186ea165ed24b162e02785 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 20 Feb 2020 10:15:24 +0100 Subject: [PATCH] enable clazy strict-iterators --- .gitlab-ci.yml | 2 +- core/document.cpp | 11 ++++++----- core/page.cpp | 24 +++++++++--------------- ui/pageviewutils.cpp | 12 ++++++------ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e15732b0a..b96e72959 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ build_clazy_clang_tidy: script: - srcdir=`pwd` && mkdir -p /tmp/okular_build && cd /tmp/okular_build && CC=clang CXX=clazy CXXFLAGS="-Werror -Wno-deprecated-declarations" cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja $srcdir && cat compile_commands.json | jq '[.[] | select(.file | contains("'"$srcdir"'"))]' > compile_commands.aux.json && cat compile_commands.aux.json | jq '[.[] | select(.file | contains("/synctex/")| not)]' > compile_commands.json - - CLAZY_CHECKS="qstring-arg,incorrect-emit,qhash-namespace,detaching-temporary,range-loop,qdeleteall,connect-not-normalized,inefficient-qlist-soft" ninja + - CLAZY_CHECKS="qstring-arg,incorrect-emit,qhash-namespace,detaching-temporary,range-loop,qdeleteall,connect-not-normalized,inefficient-qlist-soft,strict-iterators" ninja # Fix the poppler header, remove when debian:unstable ships poppler 0.82 or later - sed -i "N;N;N;N; s#class MediaRendition\;\nclass MovieAnnotation\;\nclass ScreenAnnotation;#class MediaRendition\;#g" /usr/include/poppler/qt5/poppler-link.h - "run-clang-tidy -header-filter='.*/okular/.*' -checks='-*,performance-*,bugprone-*,readability-inconsistent-declaration-parameter-name,readability-string-compare,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-make-unique,modernize-make-shared,modernize-use-override,modernize-use-equals-delete,modernize-use-emplace,modernize-loop-convert,modernize-use-nullptr,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-bugprone-incorrect-roundings' -config=\"{WarningsAsErrors: '*'}\"" diff --git a/core/document.cpp b/core/document.cpp index 8f353a803..a2767321b 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1311,7 +1311,8 @@ void DocumentPrivate::saveDocumentInfo() const rotationNode.appendChild( doc.createTextNode( QString::number( (int)m_rotation ) ) ); } // ... save history up to OKULAR_HISTORY_SAVEDSTEPS viewports - QLinkedList< DocumentViewport >::const_iterator backIterator = m_viewportIterator; + const auto currentViewportIterator = QLinkedList< DocumentViewport >::const_iterator(m_viewportIterator); + QLinkedList< DocumentViewport >::const_iterator backIterator = currentViewportIterator; if ( backIterator != m_viewportHistory.constEnd() ) { // go back up to OKULAR_HISTORY_SAVEDSTEPS steps from the current viewportIterator @@ -1324,11 +1325,11 @@ void DocumentPrivate::saveDocumentInfo() const generalInfo.appendChild( historyNode ); // add old[backIterator] and present[viewportIterator] items - QLinkedList< DocumentViewport >::const_iterator endIt = m_viewportIterator; + QLinkedList< DocumentViewport >::const_iterator endIt = currentViewportIterator; ++endIt; while ( backIterator != endIt ) { - QString name = (backIterator == m_viewportIterator) ? QStringLiteral ("current") : QStringLiteral ("oldPage"); + QString name = (backIterator == currentViewportIterator) ? QStringLiteral ("current") : QStringLiteral ("oldPage"); QDomElement historyEntry = doc.createElement( name ); historyEntry.setAttribute( QStringLiteral("viewport"), (*backIterator).toString() ); historyNode.appendChild( historyEntry ); @@ -3871,9 +3872,9 @@ void Document::setPrevViewport() void Document::setNextViewport() // restore next viewport from the history { - QLinkedList< DocumentViewport >::const_iterator nextIterator = d->m_viewportIterator; + auto nextIterator = QLinkedList< DocumentViewport >::const_iterator(d->m_viewportIterator); ++nextIterator; - if ( nextIterator != d->m_viewportHistory.end() ) + if ( nextIterator != d->m_viewportHistory.constEnd() ) { const int oldViewportPage = (*d->m_viewportIterator).pageNumber; diff --git a/core/page.cpp b/core/page.cpp index 2336112b1..cf5a5b28c 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -406,15 +406,13 @@ void PagePrivate::rotateAt( Rotation orientation ) * Rotate the object rects on the page. */ const QTransform matrix = rotationMatrix(); - QLinkedList< ObjectRect * >::const_iterator objectIt = m_page->m_rects.begin(), end = m_page->m_rects.end(); - for ( ; objectIt != end; ++objectIt ) - (*objectIt)->transform( matrix ); + for ( ObjectRect *objRect : qAsConst(m_page->m_rects) ) + objRect->transform( matrix ); const QTransform highlightRotationMatrix = Okular::buildRotationMatrix( (Rotation)(((int)m_rotation - (int)oldRotation + 4) % 4) ); - QLinkedList< HighlightAreaRect* >::const_iterator hlIt = m_page->m_highlights.begin(), hlItEnd = m_page->m_highlights.end(); - for ( ; hlIt != hlItEnd; ++hlIt ) + for ( HighlightAreaRect *hlar : qAsConst(m_page->m_highlights) ) { - (*hlIt)->transform( highlightRotationMatrix ); + hlar->transform( highlightRotationMatrix ); } } @@ -736,10 +734,9 @@ void Page::setFormFields( const QLinkedList< FormField * >& fields ) { qDeleteAll( d->formfields ); d->formfields = fields; - QLinkedList< FormField * >::const_iterator it = d->formfields.begin(), itEnd = d->formfields.end(); - for ( ; it != itEnd; ++it ) + for ( FormField *ff : qAsConst(d->formfields) ) { - (*it)->d_ptr->setDefault(); + ff->d_ptr->setDefault(); } } @@ -813,9 +810,7 @@ void Page::deleteAnnotations() // delete ObjectRects of type Annotation deleteObjectRects( m_rects, QSet() << ObjectRect::OAnnotation ); // delete all stored annotations - QLinkedList< Annotation * >::const_iterator aIt = m_annotations.begin(), aEnd = m_annotations.end(); - for ( ; aIt != aEnd; ++aIt ) - delete *aIt; + qDeleteAll( m_annotations ); m_annotations.clear(); } @@ -877,10 +872,9 @@ bool PagePrivate::restoreLocalContents( const QDomNode & pageNode ) continue; QHash hashedforms; - QLinkedList< FormField * >::const_iterator fIt = formfields.begin(), fItEnd = formfields.end(); - for ( ; fIt != fItEnd; ++fIt ) + for ( FormField *ff : qAsConst(formfields) ) { - hashedforms[(*fIt)->id()] = (*fIt); + hashedforms[ff->id()] = ff; } // iterate over all forms diff --git a/ui/pageviewutils.cpp b/ui/pageviewutils.cpp index 310fc1c61..031204847 100644 --- a/ui/pageviewutils.cpp +++ b/ui/pageviewutils.cpp @@ -602,7 +602,7 @@ void PageViewToolBar::selectButton( int id ) button = *(d->buttons.begin() + id); else { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.constBegin(), end = d->buttons.constEnd(); for ( ; !button && it != end; ++it ) if ( (*it)->isChecked() ) button = *it; @@ -797,7 +797,7 @@ void ToolBarPrivate::buildToolBar() // 6. reposition buttons (in rows/col grid) int gridX = 0, gridY = 0; - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = buttons.constBegin(), end = buttons.constEnd(); for ( ; it != end; ++it ) { ToolBarButton * button = *it; @@ -832,7 +832,7 @@ void ToolBarPrivate::reposition() q->move( currentPosition ); // repaint all buttons (to update background) - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = buttons.constBegin(), end = buttons.constEnd(); for ( ; it != end; ++it ) (*it)->update(); } @@ -921,7 +921,7 @@ void ToolBarPrivate::selectButton( ToolBarButton * button ) if ( button ) { // deselect other buttons - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = buttons.constBegin(), end = buttons.constEnd(); for ( ; it != end; ++it ) if ( *it != button ) (*it)->setChecked( false ); @@ -932,14 +932,14 @@ void ToolBarPrivate::selectButton( ToolBarButton * button ) void PageViewToolBar::setToolsEnabled( bool on ) { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.constBegin(), end = d->buttons.constEnd(); for ( ; it != end; ++it ) (*it)->setEnabled( on ); } void PageViewToolBar::setTextToolsEnabled( bool on ) { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); + QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.constBegin(), end = d->buttons.constEnd(); for ( ; it != end; ++it ) if ( (*it)->isText() ) (*it)->setEnabled( on );