Skip to content

Commit

Permalink
- Replaced foreach() macros with C++ for() constructs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rncbc committed Oct 28, 2023
1 parent 55bcc16 commit 64a0de3
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/qjackctlAlsaGraph.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// qjackctlAlsaGraph.cpp
//
/****************************************************************************
Copyright (C) 2003-2020, rncbc aka Rui Nuno Capela. All rights reserved.
Copyright (C) 2003-2023, rncbc aka Rui Nuno Capela. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -191,15 +191,15 @@ bool qjackctlAlsaGraph::findClientPort (
if (add_new && *node) {
int nchanged = 0;
QString node_title = (*node)->nodeTitle();
foreach (qjackctlAliasList *node_aliases, item_aliases(*node))
for (qjackctlAliasList *node_aliases : item_aliases(*node))
node_title = node_aliases->clientAlias(client_name);
if ((*node)->nodeTitle() != node_title) {
(*node)->setNodeTitle(node_title);
++nchanged;
}
if (*port) {
QString port_title = (*port)->portTitle();
foreach (qjackctlAliasList *port_aliases, item_aliases(*port))
for (qjackctlAliasList *port_aliases : item_aliases(*port))
port_title = port_aliases->portAlias(client_name, port_name);
if ((*port)->portTitle() != port_title) {
(*port)->setPortTitle(port_title);
Expand Down
2 changes: 1 addition & 1 deletion src/qjackctlAlsaGraph.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// qjackctlAlsaGraph.h
//
/****************************************************************************
Copyright (C) 2003-2020, rncbc aka Rui Nuno Capela. All rights reserved.
Copyright (C) 2003-2023, rncbc aka Rui Nuno Capela. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
82 changes: 41 additions & 41 deletions src/qjackctlGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void qjackctlGraphPort::removeConnect ( qjackctlGraphConnect *connect )

void qjackctlGraphPort::removeConnects (void)
{
foreach (qjackctlGraphConnect *connect, m_connects) {
for (qjackctlGraphConnect *connect : m_connects) {
if (connect->port1() != this)
connect->setPort1(nullptr);
if (connect->port2() != this)
Expand All @@ -363,7 +363,7 @@ void qjackctlGraphPort::removeConnects (void)

qjackctlGraphConnect *qjackctlGraphPort::findConnect ( qjackctlGraphPort *port ) const
{
foreach (qjackctlGraphConnect *connect, m_connects) {
for (qjackctlGraphConnect *connect : m_connects) {
if (connect->port1() == port || connect->port2() == port)
return connect;
}
Expand Down Expand Up @@ -421,15 +421,15 @@ QVariant qjackctlGraphPort::itemChange (
GraphicsItemChange change, const QVariant& value )
{
if (change == QGraphicsItem::ItemScenePositionHasChanged) {
foreach (qjackctlGraphConnect *connect, m_connects) {
for (qjackctlGraphConnect *connect : m_connects) {
connect->updatePath();
}
}
else
if (change == QGraphicsItem::ItemSelectedHasChanged && m_selectx < 1) {
const bool is_selected = value.toBool();
setHighlightEx(is_selected);
foreach (qjackctlGraphConnect *connect, m_connects)
for (qjackctlGraphConnect *connect : m_connects)
connect->setSelectedEx(this, is_selected);
}

Expand All @@ -441,7 +441,7 @@ QVariant qjackctlGraphPort::itemChange (
void qjackctlGraphPort::setSelectedEx ( bool is_selected )
{
if (!is_selected) {
foreach (qjackctlGraphConnect *connect, m_connects) {
for (qjackctlGraphConnect *connect : m_connects) {
if (connect->isSelected()) {
setHighlightEx(true);
return;
Expand Down Expand Up @@ -470,7 +470,7 @@ void qjackctlGraphPort::setHighlightEx ( bool is_highlight )

qjackctlGraphItem::setHighlight(is_highlight);

foreach (qjackctlGraphConnect *connect, m_connects)
for (qjackctlGraphConnect *connect : m_connects)
connect->setHighlightEx(this, is_highlight);

--m_hilitex;
Expand All @@ -489,7 +489,7 @@ void qjackctlGraphPort::updatePortTypeColors ( qjackctlGraphCanvas *canvas )
: color.darker());
qjackctlGraphItem::setBackground(color);
if (m_mode & Output) {
foreach (qjackctlGraphConnect *connect, m_connects) {
for (qjackctlGraphConnect *connect : m_connects) {
connect->updatePortTypeColors();
connect->update();
}
Expand Down Expand Up @@ -794,7 +794,7 @@ void qjackctlGraphNode::removePort ( qjackctlGraphPort *port )

void qjackctlGraphNode::removePorts (void)
{
foreach (qjackctlGraphPort *port, m_ports)
for (qjackctlGraphPort *port : m_ports)
port->removeConnects();

// Do not delete ports here as they are node's child items...
Expand Down Expand Up @@ -826,15 +826,15 @@ void qjackctlGraphNode::resetMarkedPorts (void)
{
QList<qjackctlGraphPort *> ports;

foreach (qjackctlGraphPort *port, m_ports) {
for (qjackctlGraphPort *port : m_ports) {
if (port->isMarked()) {
port->setMarked(false);
} else {
ports.append(port);
}
}

foreach (qjackctlGraphPort *port, ports) {
for (qjackctlGraphPort *port : ports) {
port->removeConnects();
removePort(port);
delete port;
Expand All @@ -849,7 +849,7 @@ void qjackctlGraphNode::updatePath (void)
int width = rect.width() / 2 + 24;
int wi, wo;
wi = wo = width;
foreach (qjackctlGraphPort *port, m_ports) {
for (qjackctlGraphPort *port : m_ports) {
const int w = port->itemRect().width();
if (port->isOutput()) {
if (wo < w) wo = w;
Expand All @@ -865,7 +865,7 @@ void qjackctlGraphNode::updatePath (void)
int type = 0;
int yi, yo;
yi = yo = height;
foreach (qjackctlGraphPort *port, m_ports) {
for (qjackctlGraphPort *port : m_ports) {
const QRectF& port_rect = port->itemRect();
const int w = port_rect.width();
const int h = port_rect.height() + 1;
Expand Down Expand Up @@ -938,7 +938,7 @@ QVariant qjackctlGraphNode::itemChange (
{
if (change == QGraphicsItem::ItemSelectedHasChanged) {
const bool is_selected = value.toBool();
foreach (qjackctlGraphPort *port, m_ports)
for (qjackctlGraphPort *port : m_ports)
port->setSelected(is_selected);
}

Expand Down Expand Up @@ -1373,7 +1373,7 @@ qjackctlGraphItem *qjackctlGraphCanvas::currentItem (void) const
item = nullptr;

if (item == nullptr) {
foreach (QGraphicsItem *item2, m_scene->selectedItems()) {
for (QGraphicsItem *item2 : m_scene->selectedItems()) {
if (item2->type() == qjackctlGraphConnect::Type)
continue;
item = static_cast<qjackctlGraphItem *> (item2);
Expand All @@ -1392,7 +1392,7 @@ bool qjackctlGraphCanvas::canConnect (void) const
int nins = 0;
int nouts = 0;

foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
if (item->type() == qjackctlGraphNode::Type) {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
if (node) {
Expand Down Expand Up @@ -1424,13 +1424,13 @@ bool qjackctlGraphCanvas::canConnect (void) const

bool qjackctlGraphCanvas::canDisconnect (void) const
{
foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
switch (item->type()) {
case qjackctlGraphConnect::Type:
return true;
case qjackctlGraphNode::Type: {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
foreach (qjackctlGraphPort *port, node->ports()) {
for (qjackctlGraphPort *port : node->ports()) {
if (!port->connects().isEmpty())
return true;
}
Expand Down Expand Up @@ -1502,7 +1502,7 @@ void qjackctlGraphCanvas::resetNodes ( uint node_type )
{
QList<qjackctlGraphNode *> nodes;

foreach (qjackctlGraphNode *node, m_nodes) {
for (qjackctlGraphNode *node : m_nodes) {
if (node->nodeType() == node_type) {
if (node->isMarked()) {
node->resetMarkedPorts();
Expand All @@ -1522,7 +1522,7 @@ void qjackctlGraphCanvas::clearNodes ( uint node_type )
{
QList<qjackctlGraphNode *> nodes;

foreach (qjackctlGraphNode *node, m_nodes) {
for (qjackctlGraphNode *node : m_nodes) {
if (node->nodeType() == node_type) {
m_nodekeys.remove(qjackctlGraphNode::NodeKey(node));
m_nodes.removeAll(node);
Expand Down Expand Up @@ -1579,7 +1579,7 @@ qjackctlGraphItem *qjackctlGraphCanvas::itemAt ( const QPointF& pos ) const
const QList<QGraphicsItem *>& items
= m_scene->items(QRectF(pos - QPointF(2, 2), QSizeF(5, 5)));

foreach (QGraphicsItem *item, items) {
for (QGraphicsItem *item : items) {
if (item->type() >= QGraphicsItem::UserType)
return static_cast<qjackctlGraphItem *> (item);
}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ void qjackctlGraphCanvas::mouseMoveEvent ( QMouseEvent *event )
if (!m_zoomrange) {
if (event->modifiers()
& (Qt::ControlModifier | Qt::ShiftModifier)) {
foreach (QGraphicsItem *item, m_selected) {
for (QGraphicsItem *item : m_selected) {
item->setSelected(!item->isSelected());
++nchanged;
}
Expand All @@ -1737,7 +1737,7 @@ void qjackctlGraphCanvas::mouseMoveEvent ( QMouseEvent *event )
++nchanged;
}
const QRectF range_rect(m_pos, pos);
foreach (QGraphicsItem *item,
for (QGraphicsItem *item :
m_scene->items(range_rect.normalized())) {
if (item->type() >= QGraphicsItem::UserType) {
if (item->type() != qjackctlGraphNode::Type)
Expand Down Expand Up @@ -1765,7 +1765,7 @@ void qjackctlGraphCanvas::mouseMoveEvent ( QMouseEvent *event )
if (m_item && m_item->type() == qjackctlGraphNode::Type) {
snapPos(pos);
const QPointF delta = (pos - m_pos);
foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
if (item->type() == qjackctlGraphNode::Type) {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
if (node)
Expand Down Expand Up @@ -1887,7 +1887,7 @@ void qjackctlGraphCanvas::mouseReleaseEvent ( QMouseEvent *event )
const QPointF& pos
= QGraphicsView::mapToScene(event->pos());
QList<qjackctlGraphNode *> nodes;
foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
if (item->type() == qjackctlGraphNode::Type) {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
if (node)
Expand Down Expand Up @@ -1978,7 +1978,7 @@ void qjackctlGraphCanvas::connectItems (void)
QList<qjackctlGraphPort *> outs;
QList<qjackctlGraphPort *> ins;

foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
if (item->type() == qjackctlGraphPort::Type) {
qjackctlGraphPort *port = static_cast<qjackctlGraphPort *> (item);
if (port) {
Expand Down Expand Up @@ -2039,7 +2039,7 @@ void qjackctlGraphCanvas::disconnectItems (void)
QList<qjackctlGraphConnect *> connects;
QList<qjackctlGraphNode *> nodes;

foreach (QGraphicsItem *item, m_scene->selectedItems()) {
for (QGraphicsItem *item : m_scene->selectedItems()) {
switch (item->type()) {
case qjackctlGraphConnect::Type: {
qjackctlGraphConnect *connect = static_cast<qjackctlGraphConnect *> (item);
Expand All @@ -2056,9 +2056,9 @@ void qjackctlGraphCanvas::disconnectItems (void)
}

if (connects.isEmpty()) {
foreach (qjackctlGraphNode *node, nodes) {
foreach (qjackctlGraphPort *port, node->ports()) {
foreach (qjackctlGraphConnect *connect, port->connects()) {
for (qjackctlGraphNode *node : nodes) {
for (qjackctlGraphPort *port : node->ports()) {
for (qjackctlGraphConnect *connect : port->connects()) {
if (!connects.contains(connect))
connects.append(connect);
}
Expand All @@ -2076,7 +2076,7 @@ void qjackctlGraphCanvas::disconnectItems (void)

m_commands->beginMacro(tr("Disconnect"));

foreach (qjackctlGraphConnect *connect, connects) {
for (qjackctlGraphConnect *connect : connects) {
// Submit command; notify eventual observers...
qjackctlGraphPort *port1 = connect->port1();
qjackctlGraphPort *port2 = connect->port2();
Expand All @@ -2091,7 +2091,7 @@ void qjackctlGraphCanvas::disconnectItems (void)
// Select actions.
void qjackctlGraphCanvas::selectAll (void)
{
foreach (QGraphicsItem *item, m_scene->items()) {
for (QGraphicsItem *item : m_scene->items()) {
if (item->type() == qjackctlGraphNode::Type)
item->setSelected(true);
else
Expand All @@ -2113,7 +2113,7 @@ void qjackctlGraphCanvas::selectNone (void)

void qjackctlGraphCanvas::selectInvert (void)
{
foreach (QGraphicsItem *item, m_scene->items()) {
for (QGraphicsItem *item : m_scene->items()) {
if (item->type() == qjackctlGraphNode::Type)
item->setSelected(!item->isSelected());
else
Expand Down Expand Up @@ -2237,7 +2237,7 @@ void qjackctlGraphCanvas::zoomReset (void)
// Update all nodes.
void qjackctlGraphCanvas::updateNodes (void)
{
foreach (QGraphicsItem *item, m_scene->items()) {
for (QGraphicsItem *item : m_scene->items()) {
if (item->type() == qjackctlGraphNode::Type) {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
if (node)
Expand All @@ -2250,7 +2250,7 @@ void qjackctlGraphCanvas::updateNodes (void)
// Update all connectors.
void qjackctlGraphCanvas::updateConnects (void)
{
foreach (QGraphicsItem *item, m_scene->items()) {
for (QGraphicsItem *item : m_scene->items()) {
if (item->type() == qjackctlGraphConnect::Type) {
qjackctlGraphConnect *connect = static_cast<qjackctlGraphConnect *> (item);
if (connect)
Expand Down Expand Up @@ -2362,7 +2362,7 @@ bool qjackctlGraphCanvas::saveState (void) const

m_settings->beginGroup(NodePosGroup);
const QList<QGraphicsItem *> items(m_scene->items());
foreach (QGraphicsItem *item, items) {
for (QGraphicsItem *item : items) {
if (item->type() == qjackctlGraphNode::Type) {
qjackctlGraphNode *node = static_cast<qjackctlGraphNode *> (item);
if (node)
Expand Down Expand Up @@ -2428,7 +2428,7 @@ const QColor& qjackctlGraphCanvas::portTypeColor ( uint port_type )

void qjackctlGraphCanvas::updatePortTypeColors ( uint port_type )
{
foreach (QGraphicsItem *item, m_scene->items()) {
for (QGraphicsItem *item : m_scene->items()) {
if (item->type() == qjackctlGraphPort::Type) {
qjackctlGraphPort *port = static_cast<qjackctlGraphPort *> (item);
if (port && (0 >= port_type || port->portType() == port_type)) {
Expand Down Expand Up @@ -2577,7 +2577,7 @@ void qjackctlGraphSect::resetItems ( uint node_type )
{
const QList<qjackctlGraphConnect *> connects(m_connects);

foreach (qjackctlGraphConnect *connect, connects) {
for (qjackctlGraphConnect *connect : connects) {
if (connect->isMarked()) {
connect->setMarked(false);
} else {
Expand Down Expand Up @@ -2622,7 +2622,7 @@ void qjackctlGraphSect::renameItem (
if (node) {
node->setNodeTitle(name);
const QString& node_title = node->nodeTitle();
foreach (qjackctlAliasList *node_aliases, item_aliases(item)) {
for (qjackctlAliasList *node_aliases : item_aliases(item)) {
node_aliases->setClientAlias(node->nodeName(), node_title);
++nchanged;
}
Expand All @@ -2635,7 +2635,7 @@ void qjackctlGraphSect::renameItem (
node = port->portNode();
if (port && node) {
port->setPortTitle(name);
foreach (qjackctlAliasList *port_aliases, item_aliases(item)) {
for (qjackctlAliasList *port_aliases : item_aliases(item)) {
port_aliases->setPortAlias(
node->nodeName(), port->portName(), name);
++nchanged;
Expand Down Expand Up @@ -2681,7 +2681,7 @@ void qjackctlGraphCanvas::repelOverlappingNodes ( qjackctlGraphNode *node,
-2.0 * MIN_NODE_GAP, -MIN_NODE_GAP,
+2.0 * MIN_NODE_GAP, +MIN_NODE_GAP);

foreach (qjackctlGraphNode *node2, m_nodes) {
for (qjackctlGraphNode *node2 : m_nodes) {
if (node2->isMarked())
continue;
const QPointF& pos1
Expand Down Expand Up @@ -2742,7 +2742,7 @@ void qjackctlGraphCanvas::repelOverlappingNodes ( qjackctlGraphNode *node,
void qjackctlGraphCanvas::repelOverlappingNodesAll (
qjackctlGraphMoveCommand *move_command )
{
foreach (qjackctlGraphNode *node, m_nodes)
for (qjackctlGraphNode *node : m_nodes)
repelOverlappingNodes(node, move_command);
}

Expand Down
Loading

0 comments on commit 64a0de3

Please sign in to comment.