mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +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:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -33,54 +33,6 @@ class IndependentTextItem;
|
||||
class DiagramImageItem;
|
||||
class QetGraphicsItem;
|
||||
|
||||
/**
|
||||
@brief The AddItemCommand class
|
||||
This command add an item in a diagram
|
||||
The item to add is template, but must be QGraphicsItem or derived.
|
||||
*/
|
||||
template <typename QGI>
|
||||
class AddItemCommand : public QUndoCommand {
|
||||
public:
|
||||
AddItemCommand(QGI item, Diagram *diagram,
|
||||
const QPointF &pos = QPointF(),
|
||||
QUndoCommand *parent = nullptr) :
|
||||
QUndoCommand (parent),
|
||||
m_item (item),
|
||||
m_diagram (diagram),
|
||||
m_pos(pos)
|
||||
{
|
||||
setText(QObject::tr("Ajouter ") + itemText(item));
|
||||
m_diagram -> qgiManager().manage(m_item);
|
||||
}
|
||||
|
||||
~AddItemCommand() override {
|
||||
m_diagram -> qgiManager().release(m_item);
|
||||
}
|
||||
|
||||
void undo() override {
|
||||
m_diagram -> showMe();
|
||||
m_diagram -> removeItem(m_item);
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
void redo() override {
|
||||
m_diagram -> showMe();
|
||||
m_diagram -> addItem(m_item);
|
||||
m_item -> setPos(m_pos);
|
||||
QUndoCommand::redo();
|
||||
}
|
||||
|
||||
private:
|
||||
QGI m_item;
|
||||
Diagram *m_diagram;
|
||||
QPointF m_pos;
|
||||
};
|
||||
|
||||
//Return a string to describe a QGraphicsItem
|
||||
QString itemText(const QetGraphicsItem *item);
|
||||
QString itemText(const IndependentTextItem *item);
|
||||
QString itemText(const Conductor *item);
|
||||
|
||||
/**
|
||||
@brief The PasteDiagramCommand class
|
||||
This command pastes some content onto a particular diagram.
|
||||
|
||||
Reference in New Issue
Block a user