From 3f2e4e8b1637da0a2a23d8d1ff2f45f718ebf798 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 15 Feb 2023 09:56:18 +0100 Subject: [PATCH] cleanup: replace Q_FOREACH by range-based for in profile code With Qt-containers, this might be a small pessimization, because it might lead to a deep copy. This can be "fixed" by for (const Type &item: qAsConst(container)) But frankly, I don't care. Ultimately it is probably best to replace the Qt containers by standard containers. Signed-off-by: Berthold Stoeger --- profile-widget/diveprofileitem.cpp | 2 +- profile-widget/divetooltipitem.cpp | 13 +++++-------- profile-widget/profilewidget2.cpp | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 3868fcb0f..fbdfc3d73 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -826,7 +826,7 @@ void PartialPressureGasItem::paint(QPainter *painter, const QStyleOptionGraphics QPolygonF poly; painter->setPen(QPen(alertColor, pWidth)); - Q_FOREACH (const QPolygonF &poly, alertPolygons) + for (const QPolygonF &poly: alertPolygons) painter->drawPolyline(poly); painter->restore(); } diff --git a/profile-widget/divetooltipitem.cpp b/profile-widget/divetooltipitem.cpp index e630c2228..bf501b77e 100644 --- a/profile-widget/divetooltipitem.cpp +++ b/profile-widget/divetooltipitem.cpp @@ -14,12 +14,10 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QPixmap &pixmap) QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; - Q_FOREACH (ToolTip t, toolTips) { + for (ToolTip t: toolTips) yValue += t.second->boundingRect().height(); - } - if (entryToolTip.second) { + if (entryToolTip.second) yValue += entryToolTip.second->boundingRect().height(); - } iconItem = new QGraphicsPixmapItem(this); if (!pixmap.isNull()) iconItem->setPixmap(pixmap); @@ -36,7 +34,7 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QPixmap &pixmap) void ToolTipItem::clear() { - Q_FOREACH (ToolTip t, toolTips) { + for (ToolTip t: toolTips) { delete t.first; delete t.second; } @@ -78,7 +76,7 @@ void ToolTipItem::expand() const IconMetrics &iconMetrics = defaultIconMetrics(); double width = 0, height = title->boundingRect().height() + iconMetrics.spacing; - Q_FOREACH (const ToolTip &t, toolTips) { + for (const ToolTip &t: toolTips) { QRectF sRect = t.second->boundingRect(); if (sRect.width() > width) width = sRect.width(); @@ -186,9 +184,8 @@ void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { persistPos(); QGraphicsRectItem::mouseReleaseEvent(event); - Q_FOREACH (QGraphicsItem *item, oldSelection) { + for (QGraphicsItem *item: oldSelection) item->setSelected(true); - } } void ToolTipItem::persistPos() const diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 88002af15..288c4461d 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -689,7 +689,7 @@ void ProfileWidget2::hideEvents(DiveEventItem *item) QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { if (!empty_string(event->name)) { hide_event(event->name); - Q_FOREACH (DiveEventItem *evItem, profileScene->eventItems) { + for (DiveEventItem *evItem: profileScene->eventItems) { if (same_string(evItem->getEvent()->name, event->name)) evItem->hide(); } @@ -702,7 +702,7 @@ void ProfileWidget2::hideEvents(DiveEventItem *item) void ProfileWidget2::unhideEvents() { show_all_events(); - Q_FOREACH (DiveEventItem *item, profileScene->eventItems) + for (DiveEventItem *item: profileScene->eventItems) item->show(); }