This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l-utils: clang-tidy: convert to for range loop
Author:  Rosen Penev <ros...@gmail.com>
Date:    Tue Jul 2 18:13:39 2024 -0700

Found with: modernize-loop-convert

Signed-off-by: Rosen Penev <ros...@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
[hverkuil: dropped the changes to the generated (re)trace-gen.cpp files]

 utils/qv4l2/ctrl-tab.cpp                      | 54 ++++++++++++---------------
 utils/qv4l2/general-tab.cpp                   | 37 +++++++++---------
 utils/qv4l2/qv4l2.cpp                         |  8 ++--
 utils/qvidcap/capture.cpp                     | 12 +++---
 utils/v4l2-compliance/v4l2-compliance.h       |  4 +-
 utils/v4l2-compliance/v4l2-test-buffers.cpp   |  5 +--
 utils/v4l2-compliance/v4l2-test-controls.cpp  | 19 ++++------
 utils/v4l2-compliance/v4l2-test-time32-64.cpp |  5 +--
 utils/v4l2-tracer/retrace-helper.cpp          |  4 +-
 9 files changed, 65 insertions(+), 83 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=fb90ccb39b00b30630045a904527f0f0cdcef4a9
diff --git a/utils/qv4l2/ctrl-tab.cpp b/utils/qv4l2/ctrl-tab.cpp
index 24c11e0897a1..4ff7b6f2877b 100644
--- a/utils/qv4l2/ctrl-tab.cpp
+++ b/utils/qv4l2/ctrl-tab.cpp
@@ -105,16 +105,15 @@ void ApplicationWindow::addTabs(int m_winWidth)
                m_ctrlMap[qec.id] = qec;
        }
 
-       for (ClassMap::iterator iter = m_classMap.begin(); iter != 
m_classMap.end(); ++iter) {
-               if (iter->second.size() == 0)
+       for (const auto &c : m_classMap) {
+               if (c.second.size() == 0)
                        continue;
-               which = V4L2_CTRL_ID2WHICH(iter->second[0]);
+               which = V4L2_CTRL_ID2WHICH(c.second[0]);
                id = which | 1;
                m_col = m_row = 0;
                m_cols = 4;
-               for (int j = 0; j < m_cols; j++) {
-                       m_maxw[j] = 0;
-               }
+               for (auto &w : m_maxw)
+                       w = 0;
 
                const v4l2_query_ext_ctrl &qec = m_ctrlMap[id];
                QWidget *t = new QWidget(m_tabs);
@@ -142,11 +141,11 @@ void ApplicationWindow::addTabs(int m_winWidth)
                        m_row++;
                }
                m_tabs->addTab(t, tabName);
-               for (i = 0; i < iter->second.size(); i++) {
+               for (i = 0; i < c.second.size(); i++) {
                        if (i & 1)
-                               id = iter->second[(1+iter->second.size()) / 2 + 
i / 2];
+                               id = c.second[(1 + c.second.size()) / 2 + i / 
2];
                        else
-                               id = iter->second[i / 2];
+                               id = c.second[i / 2];
                        addCtrl(grid, m_ctrlMap[id]);
                }
                grid->addWidget(new QWidget(w), grid->rowCount(), 0, 1, m_cols);
@@ -157,9 +156,8 @@ void ApplicationWindow::addTabs(int m_winWidth)
 
                int totalw = 0;
                int diff = 0;
-               for (int i = 0; i < m_cols; i++) {
-                       totalw += m_maxw[i] + m_pxw;
-               }
+               for (const auto &w : m_maxw)
+                       totalw += w + m_pxw;
                if (totalw > m_winWidth)
                        m_winWidth = totalw;
                else {
@@ -176,12 +174,11 @@ void ApplicationWindow::fixWidth(QGridLayout *grid)
        grid->setContentsMargins(m_vMargin, m_hMargin, m_vMargin, m_hMargin);
        grid->setColumnStretch(3, 1);
        QList<QWidget *> list = 
grid->parentWidget()->parentWidget()->findChildren<QWidget *>();
-       QList<QWidget *>::iterator it;
 
-       for (it = list.begin(); it != list.end(); ++it) {
-               if (((*it)->sizeHint().width()) > m_minWidth) {
-                       m_increment = (int) ceil(((*it)->sizeHint().width() - 
m_minWidth) / m_pxw);
-                       (*it)->setMinimumWidth(m_minWidth + m_increment * 
m_pxw); // for stepsize expantion of widgets
+       for (auto &it : list) {
+               if ((it->sizeHint().width()) > m_minWidth) {
+                       m_increment = (int)ceil((it->sizeHint().width() - 
m_minWidth) / m_pxw);
+                       it->setMinimumWidth(m_minWidth + m_increment * m_pxw); 
// for stepsize expantion of widgets
                }
        }
 
@@ -415,9 +412,7 @@ void ApplicationWindow::ctrlAction(int id)
        struct v4l2_ext_controls ctrls;
        int idx = 0;
 
-       for (unsigned i = 0; i < count; i++) {
-               unsigned id = m_classMap[which][i];
-
+       for (unsigned int id : m_classMap[which]) {
                if (m_ctrlMap[id].flags & CTRL_FLAG_DISABLED)
                        continue;
                c[idx].id = id;
@@ -639,9 +634,8 @@ void ApplicationWindow::updateCtrlRange(unsigned id, __s32 
new_val)
 
 void ApplicationWindow::subscribeCtrlEvents()
 {
-       for (ClassMap::iterator iter = m_classMap.begin(); iter != 
m_classMap.end(); ++iter) {
-               for (unsigned i = 0; i < m_classMap[iter->first].size(); i++) {
-                       unsigned id = m_classMap[iter->first][i];
+       for (auto &iter : m_classMap) {
+               for (unsigned int id : m_classMap[iter.first]) {
                        struct v4l2_event_subscription sub;
 
                        memset(&sub, 0, sizeof(sub));
@@ -659,9 +653,9 @@ void ApplicationWindow::refresh(unsigned which)
        struct v4l2_ext_control *c = new v4l2_ext_control[count];
        struct v4l2_ext_controls ctrls;
 
-       for (unsigned i = 0; i < count; i++) {
-               unsigned id = c[cnt].id = m_classMap[which][i];
-               
+       for (unsigned int i : m_classMap[which]) {
+               unsigned id = c[cnt].id = i;
+
                c[cnt].size = 0;
                c[cnt].reserved2[0] = 0;
                if (m_ctrlMap[id].type == V4L2_CTRL_TYPE_BUTTON)
@@ -715,8 +709,8 @@ void ApplicationWindow::refresh(unsigned which)
 
 void ApplicationWindow::refresh()
 {
-       for (ClassMap::iterator iter = m_classMap.begin(); iter != 
m_classMap.end(); ++iter)
-               refresh(iter->first);
+       for (auto &iter : m_classMap)
+               refresh(iter.first);
 }
 
 void ApplicationWindow::setWhat(QWidget *w, unsigned id, const QString &v)
@@ -889,9 +883,7 @@ void ApplicationWindow::setString(unsigned id, const 
QString &v)
 
 void ApplicationWindow::setDefaults(unsigned which)
 {
-       for (unsigned i = 0; i < m_classMap[which].size(); i++) {
-               unsigned id = m_classMap[which][i];
-
+       for (unsigned int id : m_classMap[which]) {
                if (m_ctrlMap[id].flags & V4L2_CTRL_FLAG_READ_ONLY)
                        continue;
                if (m_ctrlMap[id].flags & V4L2_CTRL_FLAG_GRABBED)
diff --git a/utils/qv4l2/general-tab.cpp b/utils/qv4l2/general-tab.cpp
index 7cbefdbf5c81..2fb165770150 100644
--- a/utils/qv4l2/general-tab.cpp
+++ b/utils/qv4l2/general-tab.cpp
@@ -917,40 +917,37 @@ void GeneralTab::fixWidth()
        setColumnStretch(3, 1);
 
        QList<QWidget *> list = parentWidget()->findChildren<QWidget *>();
-       QList<QWidget *>::iterator it;
-       for (it = list.begin(); it != list.end(); ++it) {
-               if (!qobject_cast<QComboBox *>(*it) &&
-                   !qobject_cast<QSpinBox *>(*it) &&
-                   !qobject_cast<QSlider *>(*it))
+       for (const auto &child : list) {
+               if (!qobject_cast<QComboBox *>(child) && !qobject_cast<QSpinBox 
*>(child) &&
+                   !qobject_cast<QSlider *>(child))
                        continue;
 
-               if (((*it)->sizeHint().width()) > m_minWidth) {
-                       m_increment = (int) ceil(((*it)->sizeHint().width() - 
m_minWidth) / m_pxw);
-                       (*it)->setMinimumWidth(m_minWidth + m_increment * 
m_pxw); // for stepsize expansion of widgets
+               if ((child->sizeHint().width()) > m_minWidth) {
+                       m_increment = (int)ceil((child->sizeHint().width() - 
m_minWidth) / m_pxw);
+                       child->setMinimumWidth(m_minWidth + m_increment * 
m_pxw); // for stepsize expansion of widgets
                }
        }
 
        // fix width of subgrids
-       QList<QGridLayout *>::iterator i;
-       for (i = m_grids.begin(); i != m_grids.end(); ++i) {
-               (*i)->setColumnStretch(3, 1);
-               (*i)->setContentsMargins(0, 0, 0, 0);
-               for (int n = 0; n < (*i)->count(); n++) {
-                       if ((*i)->itemAt(n)->widget()->sizeHint().width() > 
m_maxw[n % 4]) {
-                               m_maxw[n % 4] = 
(*i)->itemAt(n)->widget()->sizeHint().width();
+       for (const auto &grid : m_grids) {
+               grid->setColumnStretch(3, 1);
+               grid->setContentsMargins(0, 0, 0, 0);
+               for (int n = 0; n < grid->count(); n++) {
+                       if (grid->itemAt(n)->widget()->sizeHint().width() > 
m_maxw[n % 4]) {
+                               m_maxw[n % 4] = 
grid->itemAt(n)->widget()->sizeHint().width();
                        }
                        if (n % 2) {
-                               if 
(!qobject_cast<QToolButton*>((*i)->itemAt(n)->widget()))
-                                       
(*i)->itemAt(n)->widget()->setMinimumWidth(m_minWidth);
+                               if (!qobject_cast<QToolButton 
*>(grid->itemAt(n)->widget()))
+                                       
grid->itemAt(n)->widget()->setMinimumWidth(m_minWidth);
                        } else {
-                               
(*i)->itemAt(n)->widget()->setMinimumWidth(m_maxw[n % 4]);
+                               
grid->itemAt(n)->widget()->setMinimumWidth(m_maxw[n % 4]);
                        }
                }
                for (int j = 0; j < m_cols; j++) {
                        if (j % 2)
-                               (*i)->setColumnMinimumWidth(j,m_maxw[j] + 
m_pxw);
+                               grid->setColumnMinimumWidth(j, m_maxw[j] + 
m_pxw);
                        else
-                               (*i)->setColumnMinimumWidth(j,m_maxw[j]);
+                               grid->setColumnMinimumWidth(j, m_maxw[j]);
                }
        }
 
diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index ddb43e3834f9..7bca57850677 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -127,8 +127,8 @@ ApplicationWindow::ApplicationWindow() :
        m_tpgYCbCrEnc = 0;
        m_tpgQuantRange = 0;
        m_tpgLimRGBRange = NULL;
-       for (unsigned b = 0; b < sizeof(m_clear); b++)
-               m_clear[b] = false;
+       for (bool &b : m_clear)
+               b = false;
 
        QAction *openAct = new QAction(QIcon(":/fileopen.png"), "&Open Device", 
this);
        openAct->setStatusTip("Open a v4l device, use libv4l2 wrapper if 
possible");
@@ -1254,8 +1254,8 @@ void ApplicationWindow::updateCropping()
 void ApplicationWindow::clearBuffers()
 {
        if (m_capture)
-               for (unsigned b = 0; b < sizeof(m_clear); b++)
-                       m_clear[b] = true;
+               for (bool &b : m_clear)
+                       b = true;
 }
 
 void ApplicationWindow::startAudio()
diff --git a/utils/qvidcap/capture.cpp b/utils/qvidcap/capture.cpp
index 1e3597b0be14..e3c081c9a409 100644
--- a/utils/qvidcap/capture.cpp
+++ b/utils/qvidcap/capture.cpp
@@ -194,14 +194,12 @@ enum {
 
 static void checkSubMenuItem(QMenu *menu, __u32 value)
 {
-       QList<QAction *> actions = menu->actions();
-       QList<QAction *>::iterator iter;
-
-       for (iter = actions.begin(); iter != actions.end(); ++iter)
-               if ((*iter)->data() == value)
+       for (auto &action : menu->actions()) {
+               if (action->data() == value) {
+                       action->setChecked(true);
                        break;
-       if (iter != actions.end())
-               (*iter)->setChecked(true);
+               }
+       }
 }
 
 static QAction *addSubMenuItem(QActionGroup *grp, QMenu *menu, const QString 
&text, int val)
diff --git a/utils/v4l2-compliance/v4l2-compliance.h 
b/utils/v4l2-compliance/v4l2-compliance.h
index 3517bd07a452..948b62fd5f7e 100644
--- a/utils/v4l2-compliance/v4l2-compliance.h
+++ b/utils/v4l2-compliance/v4l2-compliance.h
@@ -189,8 +189,8 @@ public:
        filehandles() {}
        ~filehandles()
        {
-               for (std::set<int>::const_iterator iter = fhs.begin(); iter != 
fhs.end(); ++iter)
-                       close(*iter);
+               for (int fh : fhs)
+                       close(fh);
        }
 
        int add(int fd)
diff --git a/utils/v4l2-compliance/v4l2-test-buffers.cpp 
b/utils/v4l2-compliance/v4l2-test-buffers.cpp
index 3d09b6c7b331..2ec7d7cf5e1a 100644
--- a/utils/v4l2-compliance/v4l2-test-buffers.cpp
+++ b/utils/v4l2-compliance/v4l2-test-buffers.cpp
@@ -2242,7 +2242,6 @@ int testRequests(struct node *node, bool test_streaming)
        filehandles fhs;
        int media_fd = fhs.add(mi_get_media_fd(node->g_fd(), node->bus_info));
        int req_fd;
-       qctrl_map::iterator iter;
        struct test_query_ext_ctrl valid_qctrl;
        v4l2_ext_controls ctrls;
        v4l2_ext_control ctrl;
@@ -2302,8 +2301,8 @@ int testRequests(struct node *node, bool test_streaming)
        memset(&valid_qctrl, 0, sizeof(valid_qctrl));
        memset(&ctrls, 0, sizeof(ctrls));
        memset(&ctrl, 0, sizeof(ctrl));
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (auto &control : node->controls) {
+               test_query_ext_ctrl &qctrl = control.second;
 
                if (qctrl.type != V4L2_CTRL_TYPE_INTEGER &&
                    qctrl.type != V4L2_CTRL_TYPE_BOOLEAN)
diff --git a/utils/v4l2-compliance/v4l2-test-controls.cpp 
b/utils/v4l2-compliance/v4l2-test-controls.cpp
index d7f6be4321f8..e29174ec6fca 100644
--- a/utils/v4l2-compliance/v4l2-test-controls.cpp
+++ b/utils/v4l2-compliance/v4l2-test-controls.cpp
@@ -433,13 +433,12 @@ static int checkSimpleCtrl(const struct v4l2_control 
&ctrl, const struct test_qu
 
 int testSimpleControls(struct node *node)
 {
-       qctrl_map::iterator iter;
        struct v4l2_control ctrl;
        int ret;
        int i;
 
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (auto &control : node->controls) {
+               test_query_ext_ctrl &qctrl = control.second;
 
                if (qctrl.type >= V4L2_CTRL_COMPOUND_TYPES || qctrl.nr_of_dims)
                        continue;
@@ -881,8 +880,8 @@ int testExtendedControls(struct node *node)
        if (check_0(ctrls.reserved, sizeof(ctrls.reserved)))
                return fail("reserved not zeroed\n");
 
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (auto &control : node->controls) {
+               test_query_ext_ctrl &qctrl = control.second;
 
                if (is_vivid && V4L2_CTRL_ID2WHICH(qctrl.id) == 
V4L2_CTRL_CLASS_VIVID)
                        continue;
@@ -1003,8 +1002,8 @@ int testExtendedControls(struct node *node)
        if (ctrls.error_idx != ctrls.count)
                return fail("s_ext_ctrls(0) invalid error_idx %u\n", 
ctrls.error_idx);
 
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (auto &control : node->controls) {
+               test_query_ext_ctrl &qctrl = control.second;
                struct v4l2_ext_control ctrl;
 
                if (qctrl.flags & (V4L2_CTRL_FLAG_READ_ONLY | 
V4L2_CTRL_FLAG_WRITE_ONLY))
@@ -1089,10 +1088,8 @@ int testExtendedControls(struct node *node)
 
 int testEvents(struct node *node)
 {
-       qctrl_map::iterator iter;
-
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (auto &control : node->controls) {
+               test_query_ext_ctrl &qctrl = control.second;
                struct v4l2_event_subscription sub = { 0 };
                struct v4l2_event ev;
                struct timeval timeout = { 0, 100 };
diff --git a/utils/v4l2-compliance/v4l2-test-time32-64.cpp 
b/utils/v4l2-compliance/v4l2-test-time32-64.cpp
index e175c05523dc..752045df8c8e 100644
--- a/utils/v4l2-compliance/v4l2-test-time32-64.cpp
+++ b/utils/v4l2-compliance/v4l2-test-time32-64.cpp
@@ -123,7 +123,6 @@ int testTime32_64(struct node *node)
        struct v4l2_event_time32 ev32;
        struct v4l2_event_time64 ev64;
        struct v4l2_event ev;
-       qctrl_map::iterator iter;
 
        if (node->controls.empty())
                return 0;
@@ -131,8 +130,8 @@ int testTime32_64(struct node *node)
        fail_on_test(VIDIOC_DQEVENT != VIDIOC_DQEVENT_TIME32 &&
                     VIDIOC_DQEVENT != VIDIOC_DQEVENT_TIME64);
 
-       for (iter = node->controls.begin(); iter != node->controls.end(); 
++iter) {
-               test_query_ext_ctrl &qctrl = iter->second;
+       for (const auto &control : node->controls) {
+               const test_query_ext_ctrl &qctrl = control.second;
                if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS)
                        continue;
 
diff --git a/utils/v4l2-tracer/retrace-helper.cpp 
b/utils/v4l2-tracer/retrace-helper.cpp
index db24c6674f98..8efc00f8f290 100644
--- a/utils/v4l2-tracer/retrace-helper.cpp
+++ b/utils/v4l2-tracer/retrace-helper.cpp
@@ -103,8 +103,8 @@ void print_fds(void)
 {
        if (ctx_retrace.retrace_fds.empty())
                fprintf(stderr, "all devices closed\n");
-       for (auto it = ctx_retrace.retrace_fds.cbegin(); it != 
ctx_retrace.retrace_fds.cend(); ++it)
-               fprintf(stderr, "fd_trace: %d, fd_retrace: %d\n", it->first, 
it->second);
+       for (auto retrace_fd : ctx_retrace.retrace_fds)
+               fprintf(stderr, "fd_trace: %d, fd_retrace: %d\n", 
retrace_fd.first, retrace_fd.second);
 }
 
 std::string get_path_retrace_from_path_trace(std::string path_trace, 
json_object *open_obj)

Reply via email to