[qet] [4251] fix weird behavior when zooming at the same time of cr?\195? \169ation of shape item

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4251
Author:   blacksun
Date:     2015-11-07 13:28:43 +0100 (Sat, 07 Nov 2015)
Log Message:
-----------
fix weird behavior when zooming at the same time of cr?\195?\169ation of shape item

Modified Paths:
--------------
    trunk/sources/diagramevent/diagrameventaddelement.h
    trunk/sources/diagramevent/diagrameventinterface.cpp
    trunk/sources/diagramevent/diagrameventinterface.h
    trunk/sources/qetdiagrameditor.cpp

Added Paths:
-----------
    trunk/sources/diagramevent/diagrameventaddshape.cpp
    trunk/sources/diagramevent/diagrameventaddshape.h

Removed Paths:
-------------
    trunk/sources/dvevent/dveventaddshape.cpp
    trunk/sources/dvevent/dveventaddshape.h

Modified: trunk/sources/diagramevent/diagrameventaddelement.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.h	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/diagramevent/diagrameventaddelement.h	2015-11-07 12:28:43 UTC (rev 4251)
@@ -30,6 +30,8 @@
  */
 class DiagramEventAddElement : public DiagramEventInterface
 {
+		Q_OBJECT
+
 	public:
 		DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos = QPointF(0,0));
 		virtual ~DiagramEventAddElement();

Added: trunk/sources/diagramevent/diagrameventaddshape.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddshape.cpp	                        (rev 0)
+++ trunk/sources/diagramevent/diagrameventaddshape.cpp	2015-11-07 12:28:43 UTC (rev 4251)
@@ -0,0 +1,235 @@
+/*
+	Copyright 2006-2015 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "diagrameventaddshape.h"
+#include "diagram.h"
+#include "diagramcommands.h"
+
+/**
+ * @brief DiagramEventAddShape::DiagramEventAddShape
+ * Default constructor
+ * @param diagram : the diagram where this event must operate
+ * @param shape_type : the type of shape to draw
+ */
+DiagramEventAddShape::DiagramEventAddShape(Diagram *diagram, QetShapeItem::ShapeType shape_type) :
+	DiagramEventInterface(diagram),
+	m_shape_type (shape_type),
+	m_shape_item (nullptr),
+	m_help_horiz (nullptr),
+	m_help_verti (nullptr)
+{
+	m_running = true;
+	init();
+}
+
+/**
+ * @brief DiagramEventAddShape::~DiagramEventAddShape
+ */
+DiagramEventAddShape::~DiagramEventAddShape()
+{
+	if ((m_running || m_abort) && m_shape_item)
+	{
+		m_diagram->removeItem(m_shape_item);
+		delete m_shape_item;
+	}
+	delete m_help_horiz;
+	delete m_help_verti;
+
+	foreach (QGraphicsView *v, m_diagram->views())
+		v->setContextMenuPolicy(Qt::DefaultContextMenu);
+}
+
+/**
+ * @brief DiagramEventAddShape::mousePressEvent
+ * Action when mouse is pressed
+ * @param event : event of mouse press
+ * @return : true if this event is managed, otherwise false
+ */
+bool DiagramEventAddShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+	if (Q_UNLIKELY(m_diagram->isReadOnly())) return false;
+
+	QPointF pos = event->scenePos();
+	if (event->modifiers() != Qt::ControlModifier)
+		pos = Diagram::snapToGrid(pos);
+
+		//Action for left mouse click
+	if (event->button() == Qt::LeftButton)
+	{
+			//Create shape item
+		if (!m_shape_item)
+		{
+			m_shape_item = new QetShapeItem(pos, pos, m_shape_type);
+			m_diagram->addItem (m_shape_item);
+			return true;
+		}
+
+			//If current item isn't a polyline, add it with an undo command
+		if (m_shape_type != QetShapeItem::Polygon)
+		{
+			m_shape_item->setP2 (pos);
+			m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
+			m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
+		}
+			//Else add a new point to polyline
+		else
+		{
+			m_shape_item->setNextPoint (pos);
+		}
+
+		return true;
+	}
+
+	if (event->button() == Qt::RightButton)
+		return true;
+
+	return false;
+
+}
+
+/**
+ * @brief DiagramEventAddShape::mouseMoveEvent
+ * Action when mouse move
+ * @param event : event of mouse move
+ * @return : true if this event is managed, otherwise false
+ */
+bool DiagramEventAddShape::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+	updateHelpCross(event->scenePos());
+
+	if (m_shape_item && event->buttons() == Qt::NoButton)
+	{
+		QPointF pos = event->scenePos();
+		if (event->modifiers() != Qt::ControlModifier)
+			pos = Diagram::snapToGrid(pos);
+
+		m_shape_item->setP2 (pos);
+		return true;
+	}
+
+	return false;
+}
+
+/**
+ * @brief DiagramEventAddShape::mouseReleaseEvent
+ * Action when mouse button is released
+ * @param event : event of mouse release
+ * @return : true if this event is managed, otherwise false
+ */
+bool DiagramEventAddShape::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+	if (event->button() == Qt::RightButton)
+	{
+			//If shape is created, we manage right click
+		if (m_shape_item)
+		{
+				//Shape is a polyline and have three points or more we just remove the last point
+			if (m_shape_type == QetShapeItem::Polygon && (m_shape_item->pointsCount() >= 3) )
+			{
+				m_shape_item->removePoints();
+
+				QPointF pos = event->scenePos();
+				if (event->modifiers() != Qt::ControlModifier)
+					pos = Diagram::snapToGrid(pos);
+
+				m_shape_item->setP2(pos); //Set the new last point under the cursor
+				return true;
+			}
+
+				//For other case, we remove item from scene
+			m_diagram->removeItem(m_shape_item);
+			delete m_shape_item;
+			m_shape_item = nullptr;
+			return true;
+		}
+
+			//Else (no shape), we set to false the running status
+			//for indicate to the owner of this event that everything is done
+		m_running = false;
+		emit finish();
+		return true;
+	}
+
+	return false;
+}
+
+/**
+ * @brief DiagramEventAddShape::mouseDoubleClickEvent
+ * Action when mouse button is double clicked
+ * @param event : event of mouse double click
+ * @return : true if this event is managed, otherwise false
+ */
+bool DiagramEventAddShape::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+		//If current item is a polyline, add it with an undo command
+	if (m_shape_item && m_shape_type == QetShapeItem::Polygon && event->button() == Qt::LeftButton)
+	{
+			//<double clic is used to finish polyline, but they also add two points at the same pos
+			//<(double clic is a double press event), so we remove the last point of polyline
+		m_shape_item->removePoints();
+		m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
+		m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
+		return true;
+	}
+
+	return false;
+}
+
+void DiagramEventAddShape::init()
+{
+	foreach (QGraphicsView *v, m_diagram->views())
+		v->setContextMenuPolicy(Qt::NoContextMenu);
+}
+
+/**
+ * @brief DiagramEventAddShape::updateHelpCross
+ * Create and update the position of the cross to help user for draw new shape
+ * @param p : the center of the cross
+ */
+void DiagramEventAddShape::updateHelpCross(const QPointF &p)
+{
+		//If line isn't created yet, we create it.
+	if (!m_help_horiz || !m_help_verti)
+	{
+		QPen pen;
+		pen.setWidthF(0.4);
+		pen.setCosmetic(true);
+		pen.setColor(Diagram::background_color == Qt::darkGray ? Qt::lightGray : Qt::darkGray);
+
+		QRectF rect = m_diagram->border_and_titleblock.insideBorderRect();
+
+		if (!m_help_horiz)
+		{
+			m_help_horiz = new QGraphicsLineItem(rect.topLeft().x(), 0, rect.topRight().x(), 0);
+			m_help_horiz->setPen(pen);
+			m_diagram->addItem(m_help_horiz);
+		}
+
+		if (!m_help_verti)
+		{
+			m_help_verti = new QGraphicsLineItem(0, rect.topLeft().y(), 0, rect.bottomLeft().y());
+			m_help_verti->setPen(pen);
+			m_diagram->addItem(m_help_verti);
+		}
+	}
+
+		//Update the position of the cross
+	QPointF point = Diagram::snapToGrid(p);
+
+	m_help_horiz->setY(point.y());
+	m_help_verti->setX(point.x());
+}

Added: trunk/sources/diagramevent/diagrameventaddshape.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddshape.h	                        (rev 0)
+++ trunk/sources/diagramevent/diagrameventaddshape.h	2015-11-07 12:28:43 UTC (rev 4251)
@@ -0,0 +1,51 @@
+/*
+	Copyright 2006-2015 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef DIAGRAMEVENTADDSHAPE_H
+#define DIAGRAMEVENTADDSHAPE_H
+
+#include "diagrameventinterface.h"
+#include "qetshapeitem.h"
+
+/**
+ * @brief The DiagramEventAddShape class
+ * This event manage the creation of a shape.
+ */
+class DiagramEventAddShape : public DiagramEventInterface
+{
+		Q_OBJECT
+
+	public:
+		DiagramEventAddShape(Diagram *diagram, QetShapeItem::ShapeType shape_type);
+
+		virtual ~DiagramEventAddShape();
+		virtual bool mousePressEvent       (QGraphicsSceneMouseEvent *event);
+		virtual bool mouseMoveEvent        (QGraphicsSceneMouseEvent *event);
+		virtual bool mouseReleaseEvent     (QGraphicsSceneMouseEvent *event);
+		virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
+		virtual void init();
+
+	private:
+		void updateHelpCross (const QPointF &p);
+
+	protected:
+		QetShapeItem::ShapeType  m_shape_type;
+		QetShapeItem            *m_shape_item;
+		QGraphicsLineItem       *m_help_horiz, *m_help_verti;
+};
+
+#endif // DIAGRAMEVENTADDSHAPE_H

Modified: trunk/sources/diagramevent/diagrameventinterface.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.cpp	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/diagramevent/diagrameventinterface.cpp	2015-11-07 12:28:43 UTC (rev 4251)
@@ -66,6 +66,7 @@
 	if (event->key() == Qt::Key_Escape) {
 		m_running = false;
 		m_abort = true;
+		emit finish();
 		return true;
 	}
 	return false;

Modified: trunk/sources/diagramevent/diagrameventinterface.h
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.h	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/diagramevent/diagrameventinterface.h	2015-11-07 12:28:43 UTC (rev 4251)
@@ -18,6 +18,8 @@
 #ifndef DIAGRAMEVENTINTERFACE_H
 #define DIAGRAMEVENTINTERFACE_H
 
+#include <QObject>
+
 class QGraphicsSceneMouseEvent;
 class QGraphicsSceneWheelEvent;
 class QKeyEvent;
@@ -45,8 +47,10 @@
  * the bool m_abort is here for that at destruction time.
  *
  */
-class DiagramEventInterface
+class DiagramEventInterface : public QObject
 {
+		Q_OBJECT
+
 	public:
 		DiagramEventInterface(Diagram *diagram);
 		virtual ~DiagramEventInterface() = 0;
@@ -61,6 +65,9 @@
 		virtual bool isFinish  () const;
 		virtual void init();
 
+	signals:
+		void finish(); //Emited when the interface finish is job.
+
 	protected:
 		Diagram *m_diagram;
 		bool m_running;

Deleted: trunk/sources/dvevent/dveventaddshape.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddshape.cpp	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/dvevent/dveventaddshape.cpp	2015-11-07 12:28:43 UTC (rev 4251)
@@ -1,229 +0,0 @@
-/*
-	Copyright 2006-2015 The QElectroTech Team
-	This file is part of QElectroTech.
-
-	QElectroTech is free software: you can redistribute it and/or modify
-	it under the terms of the GNU General Public License as published by
-	the Free Software Foundation, either version 2 of the License, or
-	(at your option) any later version.
-
-	QElectroTech is distributed in the hope that it will be useful,
-	but WITHOUT ANY WARRANTY; without even the implied warranty of
-	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-	GNU General Public License for more details.
-
-	You should have received a copy of the GNU General Public License
-	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "dveventaddshape.h"
-#include "diagramview.h"
-#include "qetshapeitem.h"
-#include "diagram.h"
-#include "diagramcommands.h"
-#include <QMouseEvent>
-
-/**
- * @brief DVEventAddShape::DVEventAddShape
- * Default constructor
- * @param dv, the diagram view where operate this event
- * @param shape_type, the shape type to draw
- */
-DVEventAddShape::DVEventAddShape(DiagramView *dv, QetShapeItem::ShapeType shape_type) :
-	DVEventInterface(dv),
-	m_shape_type (shape_type),
-	m_shape_item (nullptr),
-	m_help_horiz (nullptr),
-	m_help_verti (nullptr)
-{
-	m_dv -> setContextMenuPolicy(Qt::NoContextMenu);
-}
-
-/**
- * @brief DVEventAddShape::~DVEventAddShape
- */
-DVEventAddShape::~DVEventAddShape()
-{
-	if (m_running || m_abort)
-	{
-		m_diagram -> removeItem(m_shape_item);
-		delete m_shape_item;
-	}
-	delete m_help_horiz;
-	delete m_help_verti;
-	m_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
-}
-
-/**
- * @brief DVEventAddShape::mousePressEvent
- * Action when mouse is pressed
- * @param event : event of mouse press
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddShape::mousePressEvent(QMouseEvent *event)
-{
-	if (!m_dv->isInteractive() && m_diagram->isReadOnly()) return false;
-
-	QPointF pos = m_dv->mapToScene(event->pos());
-	if (event->modifiers() != Qt::ControlModifier)
-		pos = Diagram::snapToGrid(pos);
-
-		//Action for left mouse click
-	if (event -> button() == Qt::LeftButton)
-	{
-			//Create shape item
-		if (!m_shape_item)
-		{
-			m_shape_item = new QetShapeItem(pos, pos, m_shape_type);
-			m_diagram -> addItem (m_shape_item);
-			m_running = true;
-			return true;
-		}
-
-			//If current item isn't a polyline, add it with an undo command
-		if (m_shape_type != QetShapeItem::Polygon)
-		{
-			m_shape_item -> setP2 (pos);
-			m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
-			m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
-		}
-			//Else add a new point to polyline
-		else
-		{
-			m_shape_item -> setNextPoint (pos);
-		}
-
-		return true;
-	}
-
-	if (event -> button() == Qt::RightButton)
-		return true;
-
-	return false;
-}
-
-/**
- * @brief DVEventAddShape::mouseMoveEvent
- * Action when mouse move
- * @param event : event of mouse move
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddShape::mouseMoveEvent(QMouseEvent *event)
-{
-	updateHelpCross(event->pos());
-	if (!m_running) return false;
-
-	if (m_shape_item && event -> buttons() == Qt::NoButton)
-	{
-		QPointF pos = m_dv->mapToScene(event->pos());
-		if (event->modifiers() != Qt::ControlModifier)
-			pos = Diagram::snapToGrid(pos);
-
-		m_shape_item -> setP2 (pos);
-		return true;
-	}
-
-	return false;
-}
-
-/**
- * @brief DVEventAddShape::mouseReleaseEvent
- * Action when mouse button is released
- * @param event : event of mouse release
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddShape::mouseReleaseEvent(QMouseEvent *event)
-{
-	if (event -> button() == Qt::RightButton)
-	{
-			//If shape is created, we manage right click
-		if (m_shape_item)
-		{
-				//Shape is a polyline and have three points or more we just remove the last point
-			if (m_shape_type == QetShapeItem::Polygon && (m_shape_item -> pointsCount() >= 3) )
-			{
-				m_shape_item -> removePoints();
-
-				QPointF pos = m_dv->mapToScene(event->pos());
-				if (event->modifiers() != Qt::ControlModifier)
-					pos = Diagram::snapToGrid(pos);
-
-				m_shape_item -> setP2(pos); //Set the new last point under the cursor
-				return true;
-			}
-
-				//For other case, we remove item from scene
-			m_diagram -> removeItem(m_shape_item);
-			delete m_shape_item;
-			m_shape_item = nullptr;
-			return true;
-		}
-
-			//Else (no shape), we set to false the running status
-			//for indicate to the owner of this event that everything is done
-		m_running = false;
-		emit finish();
-		return true;
-	}
-
-	return false;
-}
-
-/**
- * @brief DVEventAddShape::mouseDoubleClickEvent
- * @param event
- * @return
- */
-bool DVEventAddShape::mouseDoubleClickEvent(QMouseEvent *event)
-{
-		//If current item is a polyline, add it with an undo command
-	if (m_shape_item && m_shape_type == QetShapeItem::Polygon && event -> button() == Qt::LeftButton)
-	{
-			//<double clic is used to finish polyline, but they also add two points at the same pos
-			//<(double clic is a double press event), so we remove the last point of polyline
-		m_shape_item->removePoints();
-		m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
-		m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
-		return true;
-	}
-
-	return false;
-}
-
-/**
- * @brief DVEventAddShape::updateHelpCross
- * Create and update the position of the cross to help user for draw new shape
- * @param event
- */
-void DVEventAddShape::updateHelpCross(const QPoint &p)
-{
-		//If line isn't created yet, we create it.
-	if (!m_help_horiz || !m_help_verti)
-	{
-		QPen pen;
-		pen.setWidthF(0.4);
-		pen.setCosmetic(true);
-		pen.setColor(Diagram::background_color == Qt::darkGray ? Qt::lightGray : Qt::darkGray);
-
-		QRectF rect = m_diagram -> border_and_titleblock.insideBorderRect();
-
-		if (!m_help_horiz)
-		{
-			m_help_horiz = new QGraphicsLineItem(rect.topLeft().x(), 0, rect.topRight().x(), 0);
-			m_help_horiz -> setPen(pen);
-			m_diagram -> addItem(m_help_horiz);
-		}
-
-		if (!m_help_verti)
-		{
-			m_help_verti = new QGraphicsLineItem(0, rect.topLeft().y(), 0, rect.bottomLeft().y());
-			m_help_verti -> setPen(pen);
-			m_diagram -> addItem(m_help_verti);
-		}
-	}
-
-		//Update the position of the cross
-	QPointF point = Diagram::snapToGrid(m_dv->mapToScene(p));
-
-	m_help_horiz->setY(point.y());
-	m_help_verti->setX(point.x());
-}

Deleted: trunk/sources/dvevent/dveventaddshape.h
===================================================================
--- trunk/sources/dvevent/dveventaddshape.h	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/dvevent/dveventaddshape.h	2015-11-07 12:28:43 UTC (rev 4251)
@@ -1,47 +0,0 @@
-/*
-	Copyright 2006-2015 The QElectroTech Team
-	This file is part of QElectroTech.
-
-	QElectroTech is free software: you can redistribute it and/or modify
-	it under the terms of the GNU General Public License as published by
-	the Free Software Foundation, either version 2 of the License, or
-	(at your option) any later version.
-
-	QElectroTech is distributed in the hope that it will be useful,
-	but WITHOUT ANY WARRANTY; without even the implied warranty of
-	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-	GNU General Public License for more details.
-
-	You should have received a copy of the GNU General Public License
-	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#ifndef DVEVENTADDSHAPE_H
-#define DVEVENTADDSHAPE_H
-
-#include "dveventinterface.h"
-#include "qetshapeitem.h"
-
-class QMouseEvent;
-
-class DVEventAddShape : public DVEventInterface
-{
-	Q_OBJECT
-
-	public:
-		DVEventAddShape(DiagramView *dv, QetShapeItem::ShapeType shape_type);
-		virtual ~DVEventAddShape ();
-		virtual bool mousePressEvent       (QMouseEvent *event);
-		virtual bool mouseMoveEvent        (QMouseEvent *event);
-		virtual bool mouseReleaseEvent     (QMouseEvent *event);
-		virtual bool mouseDoubleClickEvent (QMouseEvent *event);
-
-	private:
-		void updateHelpCross (const QPoint &p);
-
-	protected:
-		QetShapeItem::ShapeType  m_shape_type;
-		QetShapeItem            *m_shape_item;
-		QGraphicsLineItem       *m_help_horiz, *m_help_verti;
-};
-
-#endif // DVEVENTADDSHAPE_H

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2015-11-07 09:27:39 UTC (rev 4250)
+++ trunk/sources/qetdiagrameditor.cpp	2015-11-07 12:28:43 UTC (rev 4251)
@@ -36,10 +36,10 @@
 #include "diagramfoliolist.h"
 #include "qetshapeitem.h"
 #include "dveventaddimage.h"
-#include "dveventaddshape.h"
 #include "dveventaddtext.h"
 #include "reportproperties.h"
 #include "diagrampropertieseditordockwidget.h"
+#include "diagrameventaddshape.h"
 
 #include "ui/dialogautonum.h"
 
@@ -1158,20 +1158,33 @@
 		else
 			dvevent = event;
 	}
-	else if (value == "line")
-		dvevent = new DVEventAddShape(dv, QetShapeItem::Line);
-	else if (value == "rectangle")
-		dvevent = new DVEventAddShape(dv, QetShapeItem::Rectangle);
-	else if (value == "ellipse")
-		dvevent = new DVEventAddShape(dv, QetShapeItem::Ellipse);
-	else if (value == "polyline")
-		dvevent = new DVEventAddShape(dv, QetShapeItem::Polygon);
 
 	if (dvevent)
 	{
 		dv->setEventInterface(dvevent);
 		connect(dvevent, &DVEventInterface::finish, [action](){action->setChecked(false);});
+		return;
 	}
+
+	if (Q_UNLIKELY (!dv->diagram())) return;
+
+	Diagram *d = dv->diagram();
+	DiagramEventInterface *diagram_event = nullptr;
+
+	if (value == "line")
+		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Line);
+	else if (value == "rectangle")
+		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Rectangle);
+	else if (value == "ellipse")
+		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Ellipse);
+	else if (value == "polyline")
+		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Polygon);
+
+	if (diagram_event)
+	{
+		d->setEventInterface(diagram_event);
+		connect(diagram_event, &DiagramEventInterface::finish, [action](){action->setChecked(false);});
+	}
 }
 
 /**


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/