From 2f9b101c19e8e8e8807dfe05a56e358bc37d4035 Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 16 May 2019 17:38:13 +0000 Subject: [PATCH] Diagram editor : when user add a polygon, if the last point is at the same position of the first, then the polygon is closed. Undo commit 5862 git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5863 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramevent/diagrameventaddshape.cpp | 9 +++++++++ sources/qetdiagrameditor.cpp | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/diagramevent/diagrameventaddshape.cpp b/sources/diagramevent/diagrameventaddshape.cpp index 8067d166a..ff8d2cac7 100644 --- a/sources/diagramevent/diagrameventaddshape.cpp +++ b/sources/diagramevent/diagrameventaddshape.cpp @@ -182,6 +182,15 @@ void DiagramEventAddShape::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event //removePoints(); + + //If the last is at the same pos of the first point + //that mean user want a closed polygon, so we remove the last point and close polygon + QPolygonF polygon = m_shape_item->polygon(); + if (polygon.first() == polygon.last()) + { + m_shape_item->removePoints(); + m_shape_item->setClosed(true); + } m_diagram->undoStack().push (new AddItemCommand (m_shape_item, m_diagram)); m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic event->setAccepted(true); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index e1d401648..24500d310 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -601,7 +601,7 @@ void QETDiagramEditor::setUpActions() add_rectangle->setData("rectangle"); add_ellipse ->setData("ellipse"); add_polyline ->setData("polyline"); - + for(QAction *action : m_add_item_actions_group.actions()) { action->setCheckable(true); } @@ -1300,11 +1300,8 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) diagram_event = new DiagramEventAddShape (d, QetShapeItem::Rectangle); else if (value == "ellipse") diagram_event = new DiagramEventAddShape (d, QetShapeItem::Ellipse); - else if (value == "polyline") { + else if (value == "polyline") diagram_event = new DiagramEventAddShape (d, QetShapeItem::Polygon); - setToolTip(tr("Double-click pour terminer la forme")); - setToolTipDuration(2000); - } else if (value == "image") { DiagramEventAddImage *deai = new DiagramEventAddImage(d);