From 8941e434887ee68dce75496cf3a51cf8e5667b33 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sat, 19 Mar 2022 19:14:39 +0100 Subject: [PATCH] Port away from more QLinkedLists QLinkedList is gone from Qt6 The 1:1 port is std::list but we don't need iterator stability on removal/insertion so just port to QList (one case to std::vector since QList needs a copy constructor) --- core/annotations.cpp | 13 +++++-------- core/annotations.h | 5 ++--- core/annotations_p.h | 2 +- core/page.cpp | 4 ++-- core/page.h | 2 +- generators/poppler/annots.cpp | 2 +- part/annotationmodel.cpp | 29 +++++++++++++---------------- part/annotationtools.h | 1 - part/pageview.cpp | 4 ++-- part/pageviewannotator.h | 1 - part/presentationwidget.cpp | 6 +++--- 11 files changed, 30 insertions(+), 39 deletions(-) diff --git a/core/annotations.cpp b/core/annotations.cpp index 5811429ea..78897d8bd 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -554,9 +554,8 @@ AnnotationPrivate::~AnnotationPrivate() return; } - QLinkedList::iterator it = m_revisions.begin(), end = m_revisions.end(); - for (; it != end; ++it) { - delete (*it).annotation(); + for (const Annotation::Revision &revision : qAsConst(m_revisions)) { + delete revision.annotation(); } } @@ -729,13 +728,13 @@ const Annotation::Window &Annotation::window() const return d->m_window; } -QLinkedList &Annotation::revisions() +QList &Annotation::revisions() { Q_D(Annotation); return d->m_revisions; } -const QLinkedList &Annotation::revisions() const +const QList &Annotation::revisions() const { Q_D(const Annotation); return d->m_revisions; @@ -870,10 +869,8 @@ void Annotation::store(QDomNode &annNode, QDomDocument &document) const } // add all revisions as children of revisions element - QLinkedList::const_iterator it = d->m_revisions.begin(), end = d->m_revisions.end(); - for (; it != end; ++it) { + for (const Revision &revision : qAsConst(d->m_revisions)) { // create revision element - const Revision &revision = *it; QDomElement r = document.createElement(QStringLiteral("revision")); annNode.appendChild(r); // set element attributes diff --git a/core/annotations.h b/core/annotations.h index a1c889a8d..e6f79f99d 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -604,12 +603,12 @@ public: /** * Returns a reference to the revision list of the annotation. */ - QLinkedList &revisions(); + QList &revisions(); /** * Returns a reference to the revision list of the annotation. */ - const QLinkedList &revisions() const; + const QList &revisions() const; /** * Sets the "native" @p id of the annotation. diff --git a/core/annotations_p.h b/core/annotations_p.h index 1b22a3148..56406a03a 100644 --- a/core/annotations_p.h +++ b/core/annotations_p.h @@ -71,7 +71,7 @@ public: Okular::Annotation::Style m_style; Okular::Annotation::Window m_window; - QLinkedList m_revisions; + QList m_revisions; Annotation::DisposeDataFunction m_disposeFunc; QVariant m_nativeId; diff --git a/core/page.cpp b/core/page.cpp index 149c29409..c82efe258 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -469,9 +469,9 @@ const ObjectRect *Page::objectRect(ObjectRect::ObjectType type, double x, double return nullptr; } -QLinkedList Page::objectRects(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const +QList Page::objectRects(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const { - QLinkedList result; + QList result; QLinkedListIterator it(m_rects); it.toBack(); diff --git a/core/page.h b/core/page.h index 571f57573..3a62cedcc 100644 --- a/core/page.h +++ b/core/page.h @@ -228,7 +228,7 @@ public: * Returns all object rects of the given @p type which are at point (@p x, @p y) at scale (@p xScale, @p yScale). * @since 0.16 (KDE 4.10) */ - QLinkedList objectRects(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const; + QList objectRects(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const; /** * Returns the object rect of the given @p type which is nearest to the point (@p x, @p y) at scale (@p xScale, @p yScale). diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp index 76515a9a4..3254c21fc 100644 --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -1143,7 +1143,7 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *p okularWindow.setSummary(popplerPopup.summary()); // Convert the poppler revisions to Okular revisions - QLinkedList &okularRevisions = okularAnnotation->revisions(); + QList &okularRevisions = okularAnnotation->revisions(); const QList popplerRevisions = popplerAnnotation->revisions(); for (Poppler::Annotation *popplerRevision : popplerRevisions) { bool deletePopplerRevision; diff --git a/part/annotationmodel.cpp b/part/annotationmodel.cpp index 6e07bb6e9..27b51b922 100644 --- a/part/annotationmodel.cpp +++ b/part/annotationmodel.cpp @@ -38,9 +38,9 @@ struct AnnItem { int page; }; -static QLinkedList filterOutWidgetAnnotations(const QLinkedList &annotations) +static QList filterOutWidgetAnnotations(const QLinkedList &annotations) { - QLinkedList result; + QList result; for (Okular::Annotation *annotation : annotations) { if (annotation->subType() == Okular::Annotation::AWidget) { @@ -154,7 +154,7 @@ void AnnotationModelPrivate::notifyPageChanged(int page, int flags) return; } - const QLinkedList annots = filterOutWidgetAnnotations(document->page(page)->annotations()); + const QList annots = filterOutWidgetAnnotations(document->page(page)->annotations()); int annItemIndex = -1; AnnItem *annItem = findItem(page, &annItemIndex); // case 1: the page has no more annotations @@ -182,12 +182,12 @@ void AnnotationModelPrivate::notifyPageChanged(int page, int flags) q->beginInsertRows(indexForItem(root), i, i); annItem->parent->children.insert(i, annItem); q->endInsertRows(); - QLinkedList::ConstIterator it = annots.begin(), itEnd = annots.end(); int newid = 0; - for (; it != itEnd; ++it, ++newid) { + for (Okular::Annotation *annot : annots) { q->beginInsertRows(indexForItem(annItem), newid, newid); - new AnnItem(annItem, *it); + new AnnItem(annItem, annot); q->endInsertRows(); + ++newid; } return; } @@ -197,10 +197,10 @@ void AnnotationModelPrivate::notifyPageChanged(int page, int flags) for (int i = annItem->children.count(); i > 0; --i) { Okular::Annotation *ref = annItem->children.at(i - 1)->annotation; bool found = false; - QLinkedList::ConstIterator it = annots.begin(), itEnd = annots.end(); - for (; !found && it != itEnd; ++it) { - if ((*it) == ref) { + for (Okular::Annotation *annot : annots) { + if (annot == ref) { found = true; + break; } } if (!found) { @@ -215,9 +215,7 @@ void AnnotationModelPrivate::notifyPageChanged(int page, int flags) // case 4: existing branch, less items than annotations // => lookup and add annotations if not in the branch if (annots.count() > annItem->children.count()) { - QLinkedList::ConstIterator it = annots.begin(), itEnd = annots.end(); - for (; it != itEnd; ++it) { - Okular::Annotation *ref = *it; + for (Okular::Annotation *ref : annots) { bool found = false; int count = annItem->children.count(); for (int i = 0; !found && i < count; ++i) { @@ -261,15 +259,14 @@ void AnnotationModelPrivate::rebuildTree(const QVector &pages) Q_EMIT q->layoutAboutToBeChanged(); for (int i = 0; i < pages.count(); ++i) { - const QLinkedList annots = filterOutWidgetAnnotations(pages.at(i)->annotations()); + const QList annots = filterOutWidgetAnnotations(pages.at(i)->annotations()); if (annots.isEmpty()) { continue; } AnnItem *annItem = new AnnItem(root, i); - QLinkedList::ConstIterator it = annots.begin(), itEnd = annots.end(); - for (; it != itEnd; ++it) { - new AnnItem(annItem, *it); + for (Okular::Annotation *annot : annots) { + new AnnItem(annItem, annot); } } Q_EMIT q->layoutChanged(); diff --git a/part/annotationtools.h b/part/annotationtools.h index 3ac0bb551..623fc6028 100644 --- a/part/annotationtools.h +++ b/part/annotationtools.h @@ -7,7 +7,6 @@ #ifndef _OKULAR_ANNOTATIONTOOLS_H_ #define _OKULAR_ANNOTATIONTOOLS_H_ -#include #include #include #include diff --git a/part/pageview.cpp b/part/pageview.cpp index ff8ae2a82..54009bba0 100644 --- a/part/pageview.cpp +++ b/part/pageview.cpp @@ -152,7 +152,7 @@ public: PageView *q; Okular::Document *document; QVector items; - QLinkedList visibleItems; + QList visibleItems; MagnifierView *magnifierView; // view layout (columns in Settings), zoom and mouse @@ -2633,7 +2633,7 @@ void PageView::mouseReleaseEvent(QMouseEvent *e) const double nX = pageItem->absToPageX(eventPos.x()); const double nY = pageItem->absToPageY(eventPos.y()); - const QLinkedList annotRects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height()); + const QList annotRects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height()); AnnotationPopup annotPopup(d->document, AnnotationPopup::MultiAnnotationMode, this); // Do not move annotPopup inside the if, it needs to live until menu->exec() diff --git a/part/pageviewannotator.h b/part/pageviewannotator.h index a89a58f99..25780cd51 100644 --- a/part/pageviewannotator.h +++ b/part/pageviewannotator.h @@ -7,7 +7,6 @@ #ifndef _OKULAR_PAGEVIEWANNOTATOR_H_ #define _OKULAR_PAGEVIEWANNOTATOR_H_ -#include #include #include diff --git a/part/presentationwidget.cpp b/part/presentationwidget.cpp index 79ddc9dbf..81902c645 100644 --- a/part/presentationwidget.cpp +++ b/part/presentationwidget.cpp @@ -105,7 +105,7 @@ struct PresentationFrame { const Okular::Page *page; QRect geometry; QHash videoWidgets; - QLinkedList drawings; + std::vector drawings; }; // a custom QToolBar that basically does not propagate the event if the widget @@ -883,7 +883,7 @@ void PresentationWidget::paintEvent(QPaintEvent *pe) pmPainter.setRenderHints(QPainter::Antialiasing); // Paint old paths - for (const SmoothPath &drawing : qAsConst(m_frames[m_frameIndex]->drawings)) { + for (const SmoothPath &drawing : m_frames[m_frameIndex]->drawings) { drawing.paint(&pmPainter, pmSize.width(), pmSize.height()); } @@ -1393,7 +1393,7 @@ QRect PresentationWidget::routeMouseDrawingEvent(QMouseEvent *e) if (m_drawingEngine->creationCompleted()) { // add drawing to current page - m_frames[m_frameIndex]->drawings << m_drawingEngine->endSmoothPath(); + m_frames[m_frameIndex]->drawings.emplace_back(m_drawingEngine->endSmoothPath()); // remove the actual drawer and create a new one just after // that - that gives continuous drawing