From e85b6a3ff1b8b3f21a75209c2bff1bf02c7fdb1b Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@qt.io>
Date: Tue, 31 Jul 2018 13:27:20 +0200
Subject: [PATCH] Qt Designer: Fix clang-tidy warnings about loops

- Replace index-based loops by range-based for

Change-Id: I074a52631cbf5233e1c762cee99064b8897abc30
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
---
 .../src/components/formeditor/dpi_chooser.cpp  |  9 ++++-----
 .../src/components/formeditor/formwindow.cpp   | 11 +++++------
 .../components/formeditor/widgetselection.cpp  |  9 +++------
 .../propertyeditor/brushpropertymanager.cpp    |  5 ++---
 .../propertyeditor/designerpropertymanager.cpp |  5 +----
 src/designer/src/lib/shared/dialoggui.cpp      |  9 +++------
 .../src/lib/shared/htmlhighlighter.cpp         |  4 +---
 src/designer/src/lib/shared/morphmenu.cpp      |  8 +++-----
 src/designer/src/lib/shared/newformwidget.cpp  |  7 ++-----
 .../src/lib/shared/qdesigner_command.cpp       | 18 +++++++++---------
 .../src/lib/shared/qdesigner_introspection.cpp |  7 +++----
 .../src/lib/shared/qdesigner_stackedbox.cpp    |  5 +----
 .../src/lib/shared/qdesigner_tabwidget.cpp     |  5 +----
 .../src/lib/shared/qdesigner_toolbar.cpp       |  5 +----
 .../src/lib/shared/qdesigner_toolbox.cpp       |  5 +----
 src/designer/src/lib/shared/qlayout_widget.cpp |  7 ++++---
 .../src/lib/shared/qsimpleresource.cpp         |  3 +--
 src/designer/src/lib/shared/richtexteditor.cpp |  6 +++---
 src/designer/src/lib/shared/zoomwidget.cpp     |  4 +---
 .../src/lib/uilib/abstractformbuilder.cpp      | 13 +++++--------
 20 files changed, 54 insertions(+), 91 deletions(-)

diff --git a/src/designer/src/components/formeditor/dpi_chooser.cpp b/src/designer/src/components/formeditor/dpi_chooser.cpp
index 13927dfca..20e8f02fc 100644
--- a/src/designer/src/components/formeditor/dpi_chooser.cpp
+++ b/src/designer/src/components/formeditor/dpi_chooser.cpp
@@ -87,11 +87,10 @@ DPI_Chooser::DPI_Chooser(QWidget *parent) :
     //: System resolution
     m_predefinedCombo->addItem(tr("System (%1 x %2)").arg(m_systemEntry->dpiX).arg(m_systemEntry->dpiY), QVariant::fromValue(systemEntry));
     // Devices. Exclude the system values as not to duplicate the entries
-    const int predefinedCount = sizeof(dpiEntries)/sizeof(DPI_Entry);
-    const struct DPI_Entry *ecend = dpiEntries + predefinedCount;
-    for (const struct DPI_Entry *it = dpiEntries; it < ecend; ++it)
-        if (it->dpiX != m_systemEntry->dpiX || it->dpiY != m_systemEntry->dpiY)
-            m_predefinedCombo->addItem(tr(it->description), QVariant::fromValue(it));
+    for (const DPI_Entry &e : dpiEntries) {
+        if (e.dpiX != m_systemEntry->dpiX || e.dpiY != m_systemEntry->dpiY)
+            m_predefinedCombo->addItem(tr(e.description), QVariant::fromValue(&e));
+    }
     m_predefinedCombo->addItem(tr("User defined"));
 
     setFocusProxy(m_predefinedCombo);
diff --git a/src/designer/src/components/formeditor/formwindow.cpp b/src/designer/src/components/formeditor/formwindow.cpp
index f680cc008..52a0e3b13 100644
--- a/src/designer/src/components/formeditor/formwindow.cpp
+++ b/src/designer/src/components/formeditor/formwindow.cpp
@@ -2554,17 +2554,16 @@ void FormWindow::highlightWidget(QWidget *widget, const QPoint &pos, HighlightMo
 
 QWidgetList FormWindow::widgets(QWidget *widget) const
 {
-    const  QObjectList children = widget->children();
-    if (children.empty())
+    if (widget->children().isEmpty())
         return QWidgetList();
     QWidgetList rc;
-    const QObjectList::const_iterator cend = children.constEnd();
-    for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it)
-        if ((*it)->isWidgetType()) {
-            QWidget *w = qobject_cast<QWidget*>(*it);
+    for (QObject *o : widget->children()) {
+        if (o->isWidgetType()) {
+            QWidget *w = qobject_cast<QWidget*>(o);
             if (isManaged(w))
                 rc.push_back(w);
         }
+    }
     return rc;
 }
 
diff --git a/src/designer/src/components/formeditor/widgetselection.cpp b/src/designer/src/components/formeditor/widgetselection.cpp
index 4c343b6cd..40c0cfb6b 100644
--- a/src/designer/src/components/formeditor/widgetselection.cpp
+++ b/src/designer/src/components/formeditor/widgetselection.cpp
@@ -681,8 +681,7 @@ void WidgetSelection::updateGeometry()
 
 void WidgetSelection::hide()
 {
-    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
-        WidgetHandle *h = m_handles[ i ];
+    for (WidgetHandle *h : m_handles) {
         if (h)
             h->hide();
     }
@@ -690,8 +689,7 @@ void WidgetSelection::hide()
 
 void WidgetSelection::show()
 {
-    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
-        WidgetHandle *h = m_handles[ i ];
+    for (WidgetHandle *h : m_handles) {
         if (h) {
             h->show();
             h->raise();
@@ -701,8 +699,7 @@ void WidgetSelection::show()
 
 void WidgetSelection::update()
 {
-    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
-        WidgetHandle *h = m_handles[ i ];
+    for (WidgetHandle *h : m_handles) {
         if (h)
             h->update();
     }
diff --git a/src/designer/src/components/propertyeditor/brushpropertymanager.cpp b/src/designer/src/components/propertyeditor/brushpropertymanager.cpp
index 895a6152c..e50dc0451 100644
--- a/src/designer/src/components/propertyeditor/brushpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/brushpropertymanager.cpp
@@ -152,9 +152,8 @@ void BrushPropertyManager::initializeProperty(QtVariantPropertyManager *vm, QtPr
     QtVariantProperty *styleSubProperty = vm->addProperty(enumTypeId, QCoreApplication::translate("BrushPropertyManager", "Style"));
     property->addSubProperty(styleSubProperty);
     QStringList styles;
-    const int brushStyleCount = sizeof(brushStyles)/sizeof(const char *);
-    for (int i = 0; i < brushStyleCount; i++)
-        styles.push_back(QCoreApplication::translate("BrushPropertyManager", brushStyles[i]));
+    for (const char *brushStyle : brushStyles)
+        styles.push_back(QCoreApplication::translate("BrushPropertyManager", brushStyle));
     styleSubProperty->setAttribute(QStringLiteral("enumNames"), styles);
     styleSubProperty->setAttribute(QStringLiteral("enumIcons"), QVariant::fromValue(brushStyleIcons()));
     m_brushPropertyToStyleSubProperty.insert(property, styleSubProperty);
diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
index 9b73139f8..f954962f6 100644
--- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
+++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp
@@ -2824,10 +2824,7 @@ void ResetDecorator::slotPropertyChanged(QtProperty *property)
     if (prIt == m_createdResetWidgets.constEnd())
         return;
 
-    const QList<ResetWidget *> editors = prIt.value();
-    const QList<ResetWidget *>::ConstIterator cend = editors.constEnd();
-    for (QList<ResetWidget *>::ConstIterator itEditor = editors.constBegin(); itEditor != cend; ++itEditor) {
-        ResetWidget *widget = *itEditor;
+    for (ResetWidget *widget : prIt.value()) {
         widget->setResetEnabled(property->isModified() || isModifiedInMultiSelection(m_core, property->propertyName()));
         widget->setValueText(property->valueText());
         widget->setValueIcon(property->valueIcon());
diff --git a/src/designer/src/lib/shared/dialoggui.cpp b/src/designer/src/lib/shared/dialoggui.cpp
index b4d7a2fbb..febd7ad13 100644
--- a/src/designer/src/lib/shared/dialoggui.cpp
+++ b/src/designer/src/lib/shared/dialoggui.cpp
@@ -65,14 +65,11 @@ private:
 IconProvider::IconProvider()
 {
     // Determine a list of readable extensions (upper and lower case)
-    typedef QList<QByteArray> ByteArrayList;
-    const ByteArrayList fmts = QImageReader::supportedImageFormats();
-    const ByteArrayList::const_iterator cend = fmts.constEnd();
-    for (ByteArrayList::const_iterator it = fmts.constBegin(); it != cend; ++it) {
-        const QString suffix = QString::fromUtf8(it->constData());
+    const auto &fmts = QImageReader::supportedImageFormats();
+    for (const QByteArray &fmt : fmts) {
+        const QString suffix = QString::fromUtf8(fmt);
         m_imageFormats.insert(suffix.toLower());
         m_imageFormats.insert(suffix.toUpper());
-
     }
 }
 
diff --git a/src/designer/src/lib/shared/htmlhighlighter.cpp b/src/designer/src/lib/shared/htmlhighlighter.cpp
index 14e5b8d41..a3b7b3391 100644
--- a/src/designer/src/lib/shared/htmlhighlighter.cpp
+++ b/src/designer/src/lib/shared/htmlhighlighter.cpp
@@ -128,13 +128,11 @@ void HtmlHighlighter::highlightBlock(const QString &text)
             break;
         case InComment:
             start = pos;
-            while (pos < len) {
+            for ( ; pos < len; ++pos) {
                 if (text.mid(pos, 3) == endComment) {
                     pos += 3;
                     state = NormalState;
                     break;
-                } else {
-                    ++pos;
                 }
             }
             setFormat(start, pos - start, m_formats[Comment]);
diff --git a/src/designer/src/lib/shared/morphmenu.cpp b/src/designer/src/lib/shared/morphmenu.cpp
index d21a5fa1e..00597b856 100644
--- a/src/designer/src/lib/shared/morphmenu.cpp
+++ b/src/designer/src/lib/shared/morphmenu.cpp
@@ -418,11 +418,9 @@ void MorphWidgetCommand::morph(QWidget *before, QWidget *after)
             afterChildContainer->setLayout(childLayout);
         } else {
             // Non-Laid-out: Reparent, move over
-            const QObjectList c = beforeChildContainer->children();
-            const QObjectList::const_iterator cend = c.constEnd();
-            for (QObjectList::const_iterator it =  c.constBegin(); it != cend; ++it) {
-                if ( (*it)->isWidgetType()) {
-                    QWidget *w = static_cast<QWidget*>(*it);
+            for (QObject *o : beforeChildContainer->children()) {
+                if (o->isWidgetType()) {
+                    QWidget *w = static_cast<QWidget*>(o);
                     if (fw->isManaged(w)) {
                         const QRect geom = w->geometry();
                         w->setParent(afterChildContainer);
diff --git a/src/designer/src/lib/shared/newformwidget.cpp b/src/designer/src/lib/shared/newformwidget.cpp
index 1b09e4073..600d0c151 100644
--- a/src/designer/src/lib/shared/newformwidget.cpp
+++ b/src/designer/src/lib/shared/newformwidget.cpp
@@ -194,11 +194,8 @@ NewFormWidget::NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parent
             m_ui->profileComboBox->setCurrentIndex(ci + profileComboIndexOffset);
     }
     // Fill size combo
-    const int sizeCount =  sizeof(templateSizes)/ sizeof(TemplateSize);
-    for (int i = 0; i < sizeCount; i++) {
-        const QSize size = QSize(templateSizes[i].width, templateSizes[i].height);
-        m_ui->sizeComboBox->addItem(tr(templateSizes[i].name), size);
-    }
+    for (const TemplateSize &t : templateSizes)
+        m_ui->sizeComboBox->addItem(tr(t.name), QSize(t.width, t.height));
 
     setTemplateSize(settings.newFormSize());
 
diff --git a/src/designer/src/lib/shared/qdesigner_command.cpp b/src/designer/src/lib/shared/qdesigner_command.cpp
index 212d9e0af..ea85d57e3 100644
--- a/src/designer/src/lib/shared/qdesigner_command.cpp
+++ b/src/designer/src/lib/shared/qdesigner_command.cpp
@@ -2112,7 +2112,7 @@ void ChangeCurrentPageCommand::undo()
     containerExtension()->setCurrentIndex(m_oldIndex);
 }
 
-static int itemRoles[] = {
+static const int itemRoles[] = {
     Qt::DecorationPropertyRole,
     Qt::DisplayPropertyRole,
     Qt::ToolTipPropertyRole,
@@ -2122,8 +2122,7 @@ static int itemRoles[] = {
     Qt::TextAlignmentRole,
     Qt::BackgroundRole,
     Qt::ForegroundRole,
-    Qt::CheckStateRole,
-    -1
+    Qt::CheckStateRole
 };
 
 template<class T>
@@ -2139,8 +2138,8 @@ static void copyRolesFromItem(ItemData *id, const T *item, bool editor)
 {
     static const Qt::ItemFlags defaultFlags = T().flags();
 
-    for (int i = 0; itemRoles[i] != -1; i++)
-        copyRoleFromItem<T>(id, itemRoles[i], item);
+    for (int i : itemRoles)
+        copyRoleFromItem<T>(id, i, item);
 
     if (editor)
         copyRoleFromItem<T>(id, ItemFlagsShadowRole, item);
@@ -2221,8 +2220,8 @@ ItemData::ItemData(const QTreeWidgetItem *item, int column)
     PropertySheetStringValue str(item->text(column));
     m_properties.insert(Qt::DisplayPropertyRole, QVariant::fromValue(str));
 
-    for (int i = 0; itemRoles[i] != -1; i++)
-        copyRoleFromItem(this, itemRoles[i], item, column);
+    for (int i : itemRoles)
+        copyRoleFromItem(this, i, item, column);
 }
 
 void ItemData::fillTreeItemColumn(QTreeWidgetItem *item, int column, DesignerIconCache *iconCache) const
@@ -2368,9 +2367,10 @@ bool TableWidgetContents::nonEmpty(const QTableWidgetItem *item, int headerColum
         return true;
     }
 
-    for (int i = 0; itemRoles[i] != -1; i++)
-        if (itemRoles[i] != Qt::DisplayPropertyRole && item->data(itemRoles[i]).isValid())
+    for (int i : itemRoles) {
+        if (i != Qt::DisplayPropertyRole && item->data(i).isValid())
             return true;
+    }
 
     return false;
 }
diff --git a/src/designer/src/lib/shared/qdesigner_introspection.cpp b/src/designer/src/lib/shared/qdesigner_introspection.cpp
index 7d08ae5ce..9884c6bba 100644
--- a/src/designer/src/lib/shared/qdesigner_introspection.cpp
+++ b/src/designer/src/lib/shared/qdesigner_introspection.cpp
@@ -35,14 +35,13 @@
 QT_BEGIN_NAMESPACE
 
 // Qt Implementation
-static QStringList byteArrayListToStringList(const QList<QByteArray> &l)
+static QStringList byteArrayListToStringList(const QByteArrayList &l)
 {
     if (l.empty())
         return QStringList();
     QStringList rc;
-    const QList<QByteArray>::const_iterator cend = l.constEnd();
-    for (QList<QByteArray>::const_iterator it = l.constBegin(); it != cend; ++it)
-        rc += QString::fromUtf8(*it);
+    for (const QByteArray &b : l)
+        rc += QString::fromUtf8(b);
     return rc;
 }
 
diff --git a/src/designer/src/lib/shared/qdesigner_stackedbox.cpp b/src/designer/src/lib/shared/qdesigner_stackedbox.cpp
index da7d315bd..e132a23ec 100644
--- a/src/designer/src/lib/shared/qdesigner_stackedbox.cpp
+++ b/src/designer/src/lib/shared/qdesigner_stackedbox.cpp
@@ -206,10 +206,7 @@ void QStackedWidgetEventFilter::install(QStackedWidget *stackedWidget)
 QStackedWidgetEventFilter *QStackedWidgetEventFilter::eventFilterOf(const QStackedWidget *stackedWidget)
 {
     // Look for 1st order children only..otherwise, we might get filters of nested widgets
-    const QObjectList children = stackedWidget->children();
-    const QObjectList::const_iterator cend = children.constEnd();
-    for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) {
-        QObject *o = *it;
+    for (QObject *o : stackedWidget->children()) {
         if (!o->isWidgetType())
             if (QStackedWidgetEventFilter *ef = qobject_cast<QStackedWidgetEventFilter *>(o))
                 return ef;
diff --git a/src/designer/src/lib/shared/qdesigner_tabwidget.cpp b/src/designer/src/lib/shared/qdesigner_tabwidget.cpp
index dff5faf7f..333827eba 100644
--- a/src/designer/src/lib/shared/qdesigner_tabwidget.cpp
+++ b/src/designer/src/lib/shared/qdesigner_tabwidget.cpp
@@ -98,10 +98,7 @@ void QTabWidgetEventFilter::install(QTabWidget *tabWidget)
 QTabWidgetEventFilter *QTabWidgetEventFilter::eventFilterOf(const QTabWidget *tabWidget)
 {
     // Look for 1st order children only..otherwise, we might get filters of nested tab widgets
-    const QObjectList children = tabWidget->children();
-    const QObjectList::const_iterator cend = children.constEnd();
-    for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) {
-        QObject *o = *it;
+    for (QObject *o : tabWidget->children()) {
         if (!o->isWidgetType())
             if (QTabWidgetEventFilter *ef = qobject_cast<QTabWidgetEventFilter*>(o))
                 return ef;
diff --git a/src/designer/src/lib/shared/qdesigner_toolbar.cpp b/src/designer/src/lib/shared/qdesigner_toolbar.cpp
index baa36880d..0c0d0378a 100644
--- a/src/designer/src/lib/shared/qdesigner_toolbar.cpp
+++ b/src/designer/src/lib/shared/qdesigner_toolbar.cpp
@@ -76,10 +76,7 @@ ToolBarEventFilter::ToolBarEventFilter(QToolBar *tb) :
 ToolBarEventFilter *ToolBarEventFilter::eventFilterOf(const QToolBar *tb)
 {
     // Look for 1st order children only..otherwise, we might get filters of nested widgets
-    const QObjectList children = tb->children();
-    const QObjectList::const_iterator cend = children.constEnd();
-    for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) {
-        QObject *o = *it;
+    for (QObject *o : tb->children()) {
         if (!o->isWidgetType())
             if (ToolBarEventFilter *ef = qobject_cast<ToolBarEventFilter *>(o))
                 return ef;
diff --git a/src/designer/src/lib/shared/qdesigner_toolbox.cpp b/src/designer/src/lib/shared/qdesigner_toolbox.cpp
index 435354459..90911a9fa 100644
--- a/src/designer/src/lib/shared/qdesigner_toolbox.cpp
+++ b/src/designer/src/lib/shared/qdesigner_toolbox.cpp
@@ -105,10 +105,7 @@ bool QToolBoxHelper::eventFilter(QObject *watched, QEvent *event)
 QToolBoxHelper *QToolBoxHelper::helperOf(const QToolBox *toolbox)
 {
     // Look for 1st order children only..otherwise, we might get filters of nested widgets
-    const QObjectList children = toolbox->children();
-    const QObjectList::const_iterator cend = children.constEnd();
-    for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) {
-        QObject *o = *it;
+    for (QObject *o : toolbox->children()) {
         if (!o->isWidgetType())
             if (QToolBoxHelper *h = qobject_cast<QToolBoxHelper *>(o))
                 return h;
diff --git a/src/designer/src/lib/shared/qlayout_widget.cpp b/src/designer/src/lib/shared/qlayout_widget.cpp
index 65adb1206..2cfa7e513 100644
--- a/src/designer/src/lib/shared/qlayout_widget.cpp
+++ b/src/designer/src/lib/shared/qlayout_widget.cpp
@@ -1289,9 +1289,10 @@ void QLayoutSupport::showIndicator(Indicator i, const QRect &geometry, const QPa
 QLayoutSupport::~QLayoutSupport()
 {
     delete m_helper;
-    for (int i = 0; i < NumIndicators; i++)
-        if (m_indicators[i])
-            m_indicators[i]->deleteLater();
+    for (const QPointer<QWidget> &w : m_indicators) {
+        if (!w.isNull())
+            w->deleteLater();
+    }
 }
 
 QGridLayout * QLayoutSupport::gridLayout() const
diff --git a/src/designer/src/lib/shared/qsimpleresource.cpp b/src/designer/src/lib/shared/qsimpleresource.cpp
index 2def43570..0cedba686 100644
--- a/src/designer/src/lib/shared/qsimpleresource.cpp
+++ b/src/designer/src/lib/shared/qsimpleresource.cpp
@@ -230,8 +230,7 @@ void QSimpleResource::handleDomCustomWidgets(const QDesignerFormEditorInterface
     // Oops, there are classes left whose base class could not be found.
     // Default them to QWidget with warnings.
     const QString fallBackBaseClass = QStringLiteral("QWidget");
-    for (int i=0; i < custom_widget_list.size(); i++ ) {
-        DomCustomWidget *custom_widget = custom_widget_list[i];
+    for (DomCustomWidget *custom_widget : qAsConst(custom_widget_list)) {
         const QString customClassName = custom_widget->elementClass();
         const QString base_class = custom_widget->elementExtends();
         qDebug() << "** WARNING The base class " << base_class << " of the custom widget class " << customClassName
diff --git a/src/designer/src/lib/shared/richtexteditor.cpp b/src/designer/src/lib/shared/richtexteditor.cpp
index 6be443cb4..adf18a4c4 100644
--- a/src/designer/src/lib/shared/richtexteditor.cpp
+++ b/src/designer/src/lib/shared/richtexteditor.cpp
@@ -287,10 +287,10 @@ void HtmlTextEdit::contextMenuEvent(QContextMenuEvent *event)
         { "&&reg; (Trade Mark)", "&reg;" },
     };
 
-    for (int i = 0; i < 6; ++i) {
-        QAction *entityAction = new QAction(QLatin1String(entries[i].text),
+    for (const Entry &e : entries) {
+        QAction *entityAction = new QAction(QLatin1String(e.text),
                                             htmlMenu);
-        entityAction->setData(QLatin1String(entries[i].entity));
+        entityAction->setData(QLatin1String(e.entity));
         htmlMenu->addAction(entityAction);
     }
 
diff --git a/src/designer/src/lib/shared/zoomwidget.cpp b/src/designer/src/lib/shared/zoomwidget.cpp
index 1e3de9d29..9d0128ff4 100644
--- a/src/designer/src/lib/shared/zoomwidget.cpp
+++ b/src/designer/src/lib/shared/zoomwidget.cpp
@@ -59,9 +59,7 @@ ZoomMenu::ZoomMenu(QObject *parent) :
    m_menuActions(new QActionGroup(this))
 {
     connect(m_menuActions, &QActionGroup::triggered, this, &ZoomMenu::slotZoomMenu);
-    const int nz = sizeof(menuZoomList)/sizeof(int);
-    for (int i = 0; i < nz; i++) {
-        const int zoom = menuZoomList[i];
+    for (int zoom : menuZoomList) {
         //: Zoom factor
         QAction *a = m_menuActions->addAction(tr("%1 %").arg(zoom));
         a->setCheckable(true);
diff --git a/src/designer/src/lib/uilib/abstractformbuilder.cpp b/src/designer/src/lib/uilib/abstractformbuilder.cpp
index e57d702b0..004992511 100644
--- a/src/designer/src/lib/uilib/abstractformbuilder.cpp
+++ b/src/designer/src/lib/uilib/abstractformbuilder.cpp
@@ -970,9 +970,7 @@ void QAbstractFormBuilder::setupColorGroup(QPalette &palette, QPalette::ColorGro
     const QMetaEnum colorRole_enum = metaEnum<QAbstractFormBuilderGadget>("colorRole");
 
     const auto colorRoles = group->elementColorRole();
-    for (int role = 0; role < colorRoles.size(); ++role) {
-        const DomColorRole *colorRole = colorRoles.at(role);
-
+    for (const DomColorRole *colorRole : colorRoles) {
         if (colorRole->hasAttributeRole()) {
             const int r = colorRole_enum.keyToValue(colorRole->attributeRole().toLatin1());
             if (r != -1) {
@@ -1745,16 +1743,15 @@ DomResources *QAbstractFormBuilder::saveResources()
 DomButtonGroups *QAbstractFormBuilder::saveButtonGroups(const QWidget *mainContainer)
 {
     // Save fst order buttongroup children of maincontainer
-    const QObjectList mchildren = mainContainer->children();
+    const QObjectList &mchildren = mainContainer->children();
     if (mchildren.empty())
         return 0;
     QVector<DomButtonGroup *> domGroups;
-    const QObjectList::const_iterator cend = mchildren.constEnd();
-    for (QObjectList::const_iterator it = mchildren.constBegin(); it != cend; ++it)
-        if (QButtonGroup *bg = qobject_cast<QButtonGroup *>(*it))
+    for (QObject *o : mchildren) {
+        if (auto bg = qobject_cast<QButtonGroup *>(o))
             if (DomButtonGroup* dg = createDom(bg))
                 domGroups.push_back(dg);
-
+    }
     if (domGroups.empty())
         return 0;
     DomButtonGroups *rc = new DomButtonGroups;
-- 
GitLab