From 006fecc8243ca28347609976c39aea7335f545b2 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 7 Aug 2023 00:49:29 +0300 Subject: [PATCH] QTableView: add an operator<<(QDebug, SpanList) Simplifies the code at the call site. Even though QDebug has support for streaming std::list (SpanList), the format of the output would be different than what's already used here, hence the custom operator<<(). Drive-by, port from Q_FOREACH to ranged-for Task-number: QTBUG-115803 Change-Id: I30953c92e0c9febc01497c1117fa472b4718820e Reviewed-by: Marc Mutz --- src/widgets/itemviews/qtableview.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 2b1e46a044..3807c80647 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -172,6 +172,13 @@ QDebug operator<<(QDebug str, const QSpanCollection::Span &span) str << '(' << span.top() << ',' << span.left() << ',' << span.bottom() << ',' << span.right() << ')'; return str; } + +QDebug operator<<(QDebug debug, const QSpanCollection::SpanList &spans) +{ + for (const auto *span : spans) + debug << span << *span; + return debug; +} #endif /** \internal @@ -202,8 +209,7 @@ void QSpanCollection::updateInsertedRows(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug("After"); - foreach (QSpanCollection::Span *span, spans) - qDebug() << span << *span; + qDebug() << spans; #endif for (Index::iterator it_y = index.begin(); it_y != index.end(); ) { @@ -249,8 +255,7 @@ void QSpanCollection::updateInsertedColumns(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug("After"); - foreach (QSpanCollection::Span *span, spans) - qDebug() << span << *span; + qDebug() << spans; #endif for (Index::iterator it_y = index.begin(); it_y != index.end(); ++it_y) { @@ -354,8 +359,7 @@ void QSpanCollection::updateRemovedRows(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug("After"); - foreach (QSpanCollection::Span *span, spans) - qDebug() << span << *span; + qDebug() << spans; #endif if (spans.empty()) { qDeleteAll(spansToBeDeleted); @@ -422,8 +426,7 @@ void QSpanCollection::updateRemovedRows(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug() << index; qDebug("Deleted"); - foreach (QSpanCollection::Span *span, spansToBeDeleted) - qDebug() << span << *span; + qDebug() << spansToBeDeleted; #endif qDeleteAll(spansToBeDeleted); } @@ -481,8 +484,7 @@ void QSpanCollection::updateRemovedColumns(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug("After"); - foreach (QSpanCollection::Span *span, spans) - qDebug() << span << *span; + qDebug() << spans; #endif if (spans.empty()) { qDeleteAll(toBeDeleted); @@ -501,8 +503,7 @@ void QSpanCollection::updateRemovedColumns(int start, int end) #ifdef DEBUG_SPAN_UPDATE qDebug() << index; qDebug("Deleted"); - foreach (QSpanCollection::Span *span, toBeDeleted) - qDebug() << span << *span; + qDebug() << toBeDeleted; #endif qDeleteAll(toBeDeleted); }