diff options
Diffstat (limited to 'examples/widgets/graphicsview/diagramscene/diagramitem.cpp')
-rw-r--r-- | examples/widgets/graphicsview/diagramscene/diagramitem.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp index 3aa685635e..8ec577170b 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp +++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp @@ -58,12 +58,10 @@ //! [0] DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu, - QGraphicsItem *parent) - : QGraphicsPolygonItem(parent) + QGraphicsItem *parent) + : QGraphicsPolygonItem(parent), myDiagramType(diagramType) + , myContextMenu(contextMenu) { - myDiagramType = diagramType; - myContextMenu = contextMenu; - QPainterPath path; switch (myDiagramType) { case StartEnd: @@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu, //! [1] void DiagramItem::removeArrow(Arrow *arrow) { - int index = arrows.indexOf(arrow); - - if (index != -1) - arrows.removeAt(index); + arrows.removeAll(arrow); } //! [1] //! [2] void DiagramItem::removeArrows() { - for (Arrow *arrow : qAsConst(arrows)) { + // need a copy here since removeArrow() will + // modify the arrows container + const auto arrowsCopy = arrows; + for (Arrow *arrow : arrowsCopy) { arrow->startItem()->removeArrow(arrow); arrow->endItem()->removeArrow(arrow); scene()->removeItem(arrow); |