mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-22 20:49:59 +01:00
Replace AddItemCommand class by AddGraphicsObjectCommand
The class is the same except the name and the use of QPointer to avoid segfault with deleted QGraphicsObject.
This commit is contained in:
@@ -19,9 +19,10 @@
|
||||
|
||||
#include "../conductorautonumerotation.h"
|
||||
#include "../diagram.h"
|
||||
#include "../diagramcommands.h"
|
||||
#include "../undocommand/addgraphicsobjectcommand.h"
|
||||
#include "../factory/elementfactory.h"
|
||||
#include "../qetgraphicsitem/element.h"
|
||||
#include "../qetgraphicsitem/conductor.h"
|
||||
|
||||
/**
|
||||
@brief DiagramEventAddElement::DiagramEventAddElement
|
||||
@@ -228,7 +229,7 @@ void DiagramEventAddElement::addElement()
|
||||
element->m_converted_text_from_xml_description.clear();
|
||||
|
||||
QUndoCommand *undo_object = new QUndoCommand(tr("Ajouter %1").arg(element->name()));
|
||||
new AddItemCommand<Element *>(element, m_diagram, m_element -> pos(), undo_object);
|
||||
new AddGraphicsObjectCommand(element, m_diagram, m_element -> pos(), undo_object);
|
||||
|
||||
//When we search for free aligned terminal we
|
||||
//temporally remove m_element to avoid any interaction with the function Element::AlignedFreeTerminals
|
||||
@@ -242,7 +243,7 @@ void DiagramEventAddElement::addElement()
|
||||
QPair <Terminal *, Terminal *> pair = element -> AlignedFreeTerminals().takeFirst();
|
||||
|
||||
Conductor *conductor = new Conductor(pair.first, pair.second);
|
||||
new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF(), undo_object);
|
||||
new AddGraphicsObjectCommand(conductor, m_diagram, QPointF(), undo_object);
|
||||
|
||||
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
|
||||
ConductorAutoNumerotation can (conductor, m_diagram, undo_object);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "diagrameventaddimage.h"
|
||||
|
||||
#include "../diagram.h"
|
||||
#include "../diagramcommands.h"
|
||||
#include "../undocommand/addgraphicsobjectcommand.h"
|
||||
#include "../qetgraphicsitem/diagramimageitem.h"
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ void DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
QPointF pos = event->scenePos();
|
||||
pos.rx() -= m_image->boundingRect().width()/2;
|
||||
pos.ry() -= m_image->boundingRect().height()/2;
|
||||
m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
|
||||
m_diagram -> undoStack().push (new AddGraphicsObjectCommand(m_image, m_diagram, pos));
|
||||
|
||||
for (QGraphicsView *view : m_diagram->views()) {
|
||||
view->setContextMenuPolicy((Qt::DefaultContextMenu));
|
||||
@@ -88,7 +88,7 @@ void DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!m_image || event->buttons() != Qt::NoButton) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
QPointF pos = event->scenePos();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "diagrameventaddshape.h"
|
||||
|
||||
#include "../diagram.h"
|
||||
#include "../diagramcommands.h"
|
||||
#include "../undocommand/addgraphicsobjectcommand.h"
|
||||
|
||||
/**
|
||||
@brief DiagramEventAddShape::DiagramEventAddShape
|
||||
@@ -89,7 +89,7 @@ void DiagramEventAddShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
if (m_shape_item->shapeType() == QetShapeItem::Rectangle || m_shape_item->shapeType() == QetShapeItem::Ellipse) {
|
||||
m_shape_item->setRect(m_shape_item->rect().normalized());
|
||||
}
|
||||
m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
|
||||
m_diagram->undoStack().push (new AddGraphicsObjectCommand(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
|
||||
@@ -192,7 +192,7 @@ void DiagramEventAddShape::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event
|
||||
m_shape_item->removePoints();
|
||||
m_shape_item->setClosed(true);
|
||||
}
|
||||
m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
|
||||
m_diagram->undoStack().push (new AddGraphicsObjectCommand(m_shape_item, m_diagram));
|
||||
m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
|
||||
event->setAccepted(true);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "diagrameventaddtext.h"
|
||||
|
||||
#include "../diagram.h"
|
||||
#include "../diagramcommands.h"
|
||||
#include "../undocommand/addgraphicsobjectcommand.h"
|
||||
#include "../qetgraphicsitem/independenttextitem.h"
|
||||
|
||||
/**
|
||||
@@ -46,11 +46,10 @@ void DiagramEventAddText::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
IndependentTextItem *text = new IndependentTextItem();
|
||||
m_diagram -> undoStack().push(
|
||||
new AddItemCommand<IndependentTextItem *>(
|
||||
text,
|
||||
m_diagram,
|
||||
event->scenePos()));
|
||||
m_diagram->undoStack().push(new AddGraphicsObjectCommand(
|
||||
text,
|
||||
m_diagram,
|
||||
event->scenePos()));
|
||||
text->setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
text->setFocus(Qt::MouseFocusReason);
|
||||
emit finish();
|
||||
|
||||
Reference in New Issue
Block a user