diff options
Diffstat (limited to 'examples/widgets/graphicsview/elasticnodes')
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes/graphwidget.cpp | 10 | ||||
-rw-r--r-- | examples/widgets/graphicsview/elasticnodes/node.cpp | 11 |
2 files changed, 12 insertions, 9 deletions
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp index 81928a4ee1..6b817b2a21 100644 --- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp +++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp @@ -164,16 +164,17 @@ void GraphWidget::timerEvent(QTimerEvent *event) Q_UNUSED(event); QList<Node *> nodes; - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { if (Node *node = qgraphicsitem_cast<Node *>(item)) nodes << node; } - foreach (Node *node, nodes) + for (Node *node : qAsConst(nodes)) node->calculateForces(); bool itemsMoved = false; - foreach (Node *node, nodes) { + for (Node *node : qAsConst(nodes)) { if (node->advancePosition()) itemsMoved = true; } @@ -246,7 +247,8 @@ void GraphWidget::scaleView(qreal scaleFactor) void GraphWidget::shuffle() { - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { if (qgraphicsitem_cast<Node *>(item)) item->setPos(-150 + QRandomGenerator::global()->bounded(300), -150 + QRandomGenerator::global()->bounded(300)); } diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp index 71737c984b..8d44a167fa 100644 --- a/examples/widgets/graphicsview/elasticnodes/node.cpp +++ b/examples/widgets/graphicsview/elasticnodes/node.cpp @@ -94,7 +94,8 @@ void Node::calculateForces() // Sum up all forces pushing this item away qreal xvel = 0; qreal yvel = 0; - foreach (QGraphicsItem *item, scene()->items()) { + const QList<QGraphicsItem *> items = scene()->items(); + for (QGraphicsItem *item : items) { Node *node = qgraphicsitem_cast<Node *>(item); if (!node) continue; @@ -113,7 +114,7 @@ void Node::calculateForces() //! [4] // Now subtract all forces pulling items together double weight = (edgeList.size() + 1) * 10; - foreach (Edge *edge, edgeList) { + for (const Edge *edge : qAsConst(edgeList)) { QPointF vec; if (edge->sourceNode() == this) vec = mapToItem(edge->destNode(), 0, 0); @@ -176,8 +177,8 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid if (option->state & QStyle::State_Sunken) { gradient.setCenter(3, 3); gradient.setFocalPoint(3, 3); - gradient.setColorAt(1, QColor(Qt::yellow).light(120)); - gradient.setColorAt(0, QColor(Qt::darkYellow).light(120)); + gradient.setColorAt(1, QColor(Qt::yellow).lighter(120)); + gradient.setColorAt(0, QColor(Qt::darkYellow).lighter(120)); } else { gradient.setColorAt(0, Qt::yellow); gradient.setColorAt(1, Qt::darkYellow); @@ -194,7 +195,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) { switch (change) { case ItemPositionHasChanged: - foreach (Edge *edge, edgeList) + for (Edge *edge : qAsConst(edgeList)) edge->adjust(); graph->itemMoved(); break; |