mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Diagram command add QGraphicsItem and derived :
Remove each comand for each type and replace it by generic class by using template class (addItemComand). git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3368 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -568,7 +568,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
// charge les caracteristiques de l'element
|
||||
if (nvel_elmt -> fromXml(element_xml, table_adr_id, handle_inputs_rotation)) {
|
||||
// ajout de l'element au schema et a la liste des elements ajoutes
|
||||
addElement(nvel_elmt);
|
||||
addItem(nvel_elmt);
|
||||
added_elements << nvel_elmt;
|
||||
} else {
|
||||
delete nvel_elmt;
|
||||
@@ -581,7 +581,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
foreach (QDomElement text_xml, QET::findInDomElement(root, "inputs", "input")) {
|
||||
IndependentTextItem *iti = new IndependentTextItem(this);
|
||||
iti -> fromXml(text_xml);
|
||||
addIndependentTextItem(iti);
|
||||
addItem(iti);
|
||||
added_texts << iti;
|
||||
}
|
||||
|
||||
@@ -727,18 +727,15 @@ void Diagram::initElementsLinks() {
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute un element sur le schema
|
||||
@param element Element a ajouter
|
||||
*/
|
||||
void Diagram::addElement(Element *element) {
|
||||
* @brief Diagram::addItem
|
||||
* Add element to diagram
|
||||
* @param element
|
||||
*/
|
||||
void Diagram::addItem(Element *element) {
|
||||
if (!element || isReadOnly()) return;
|
||||
|
||||
// ajoute l'element au schema
|
||||
if (element -> scene() != this) {
|
||||
addItem(element);
|
||||
}
|
||||
|
||||
// surveille les modifications de ses champs de texte
|
||||
if (element -> scene() != this)
|
||||
QGraphicsScene::addItem(element);
|
||||
foreach(ElementTextItem *eti, element -> texts()) {
|
||||
connect(
|
||||
eti,
|
||||
@@ -750,33 +747,31 @@ void Diagram::addElement(Element *element) {
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute un conducteur sur le schema
|
||||
@param conductor Conducteur a ajouter
|
||||
*/
|
||||
void Diagram::addConductor(Conductor *conductor) {
|
||||
* @brief Diagram::addItem
|
||||
* Add conductor to scene.
|
||||
* @param conductor
|
||||
*/
|
||||
void Diagram::addItem(Conductor *conductor) {
|
||||
if (!conductor || isReadOnly()) return;
|
||||
|
||||
// ajoute le conducteur au schema
|
||||
if (conductor -> scene() != this) {
|
||||
addItem(conductor);
|
||||
QGraphicsScene::addItem(conductor);
|
||||
conductor -> terminal1 -> addConductor(conductor);
|
||||
conductor -> terminal2 -> addConductor(conductor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Aoute un champ de texte independant sur le schema
|
||||
@param iti Champ de texte a ajouter
|
||||
*/
|
||||
void Diagram::addIndependentTextItem(IndependentTextItem *iti) {
|
||||
* @brief Diagram::addItem
|
||||
* Add text item to diagram
|
||||
* @param iti
|
||||
*/
|
||||
void Diagram::addItem(IndependentTextItem *iti) {
|
||||
if (!iti || isReadOnly()) return;
|
||||
|
||||
// ajoute le champ de texte au schema
|
||||
if (iti -> scene() != this) {
|
||||
addItem(iti);
|
||||
}
|
||||
if (iti -> scene() != this)
|
||||
QGraphicsScene::addItem(iti);
|
||||
|
||||
// surveille les modifications apportees au champ de texte
|
||||
connect(
|
||||
iti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
@@ -785,28 +780,30 @@ void Diagram::addIndependentTextItem(IndependentTextItem *iti) {
|
||||
);
|
||||
}
|
||||
|
||||
void Diagram::addDiagramImageItem(DiagramImageItem *dii) {
|
||||
if (!dii || isReadOnly()) return;
|
||||
|
||||
//add image at diagram
|
||||
if (dii -> scene() != this) {
|
||||
addItem(dii);
|
||||
}
|
||||
/**
|
||||
* @brief Diagram::addItem
|
||||
* Generique method to add item to scene
|
||||
* @param item
|
||||
*/
|
||||
void Diagram::addItem(QGraphicsItem *item) {
|
||||
if (!item || isReadOnly()) return;
|
||||
if (item -> scene() != this)
|
||||
QGraphicsScene::addItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
Enleve un element du schema
|
||||
@param element Element a enlever
|
||||
*/
|
||||
void Diagram::removeElement(Element *element) {
|
||||
* @brief Diagram::removeItem
|
||||
* Remove an element from the scene
|
||||
* @param element
|
||||
*/
|
||||
void Diagram::removeItem(Element *element) {
|
||||
if (!element || isReadOnly()) return;
|
||||
|
||||
// remove all links of element
|
||||
element->unlinkAllElements();
|
||||
// enleve l'element au schema
|
||||
removeItem(element);
|
||||
|
||||
// arrete la surveillance des modifications de ses champs de texte
|
||||
QGraphicsScene::removeItem(element);
|
||||
|
||||
foreach(ElementTextItem *eti, element -> texts()) {
|
||||
disconnect(
|
||||
eti,
|
||||
@@ -818,31 +815,29 @@ void Diagram::removeElement(Element *element) {
|
||||
}
|
||||
|
||||
/**
|
||||
Enleve un conducteur du schema
|
||||
@param conductor Conducteur a enlever
|
||||
*/
|
||||
void Diagram::removeConductor(Conductor *conductor) {
|
||||
* @brief Diagram::removeItem
|
||||
* Remove a conductor from diagram
|
||||
* @param conductor
|
||||
*/
|
||||
void Diagram::removeItem(Conductor *conductor) {
|
||||
if (!conductor || isReadOnly()) return;
|
||||
|
||||
// detache le conducteur sans le detruire
|
||||
conductor -> terminal1 -> removeConductor(conductor);
|
||||
conductor -> terminal2 -> removeConductor(conductor);
|
||||
|
||||
// enleve le conducteur du schema
|
||||
removeItem(conductor);
|
||||
QGraphicsScene::removeItem(conductor);
|
||||
}
|
||||
|
||||
/**
|
||||
Enleve un champ de texte independant du schema
|
||||
@param iti Champ de texte a enlever
|
||||
*/
|
||||
void Diagram::removeIndependentTextItem(IndependentTextItem *iti) {
|
||||
* @brief Diagram::removeItem
|
||||
* Remove text field from diagram
|
||||
* @param iti
|
||||
*/
|
||||
void Diagram::removeItem(IndependentTextItem *iti) {
|
||||
if (!iti || isReadOnly()) return;
|
||||
|
||||
// enleve le champ de texte au schema
|
||||
removeItem(iti);
|
||||
QGraphicsScene::removeItem(iti);
|
||||
|
||||
// arrete la surveillance des modifications apportees au champ de texte
|
||||
disconnect(
|
||||
iti,
|
||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||
@@ -851,6 +846,15 @@ void Diagram::removeIndependentTextItem(IndependentTextItem *iti) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::removeItem
|
||||
* Generique methode to remove QGraphicsItem from diagram
|
||||
* @param item
|
||||
*/
|
||||
void Diagram::removeItem(QGraphicsItem *item) {
|
||||
QGraphicsScene::removeItem(item);
|
||||
}
|
||||
|
||||
void Diagram::titleChanged(const QString &title) {
|
||||
emit(diagramTitleChanged(this, title));
|
||||
}
|
||||
|
||||
@@ -147,14 +147,15 @@ class Diagram : public QGraphicsScene {
|
||||
|
||||
// methods related to graphics items addition/removal on the diagram
|
||||
void initElementsLinks();
|
||||
void addElement(Element *);
|
||||
void addConductor(Conductor *);
|
||||
void addIndependentTextItem(IndependentTextItem *);
|
||||
void addDiagramImageItem(DiagramImageItem *);
|
||||
virtual void addItem (Element *element);
|
||||
virtual void addItem (Conductor *conductor);
|
||||
virtual void addItem (IndependentTextItem *iti);
|
||||
virtual void addItem (QGraphicsItem *item);
|
||||
|
||||
void removeElement(Element *);
|
||||
void removeConductor(Conductor *);
|
||||
void removeIndependentTextItem(IndependentTextItem *);
|
||||
virtual void removeItem (Element *element);
|
||||
virtual void removeItem (Conductor *conductor);
|
||||
virtual void removeItem (IndependentTextItem *iti);
|
||||
virtual void removeItem (QGraphicsItem *item);
|
||||
|
||||
// methods related to graphics options
|
||||
ExportProperties applyProperties(const ExportProperties &);
|
||||
|
||||
@@ -30,183 +30,31 @@
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param d Schema auquel on ajoute un element
|
||||
@param elmt Element ajoute
|
||||
@param p Position a laquelle l'element est ajoute
|
||||
@param parent QUndoCommand parent
|
||||
*/
|
||||
AddElementCommand::AddElementCommand(
|
||||
Diagram *d,
|
||||
Element *elmt,
|
||||
const QPointF &p,
|
||||
QUndoCommand *parent
|
||||
) :
|
||||
QUndoCommand(QString(QObject::tr("ajouter 1 %1", "undo caption - %1 is an element name")).arg(elmt -> name()), parent),
|
||||
element(elmt),
|
||||
diagram(d),
|
||||
position(p)
|
||||
{
|
||||
diagram -> qgiManager().manage(element);
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
AddElementCommand::~AddElementCommand() {
|
||||
diagram -> qgiManager().release(element);
|
||||
}
|
||||
|
||||
/// Annule l'ajout
|
||||
void AddElementCommand::undo() {
|
||||
diagram -> showMe();
|
||||
diagram -> removeElement(element);
|
||||
}
|
||||
|
||||
/// Refait l'ajout
|
||||
void AddElementCommand::redo() {
|
||||
diagram -> showMe();
|
||||
diagram -> addElement(element);
|
||||
element -> setPos(position);
|
||||
element -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param dia Schema auquel on ajoute du texte
|
||||
@param text Texte ajoute
|
||||
@param pos Position a laquelle le texte est ajoute
|
||||
@param parent QUndoCommand parent
|
||||
*/
|
||||
AddTextCommand::AddTextCommand(Diagram *dia, IndependentTextItem *text, const QPointF &pos, QUndoCommand *parent) :
|
||||
QUndoCommand(QObject::tr("Ajouter un champ de texte", "undo caption"), parent),
|
||||
textitem(text),
|
||||
diagram(dia),
|
||||
position(pos)
|
||||
{
|
||||
diagram -> qgiManager().manage(textitem);
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
AddTextCommand::~AddTextCommand() {
|
||||
diagram -> qgiManager().release(textitem);
|
||||
}
|
||||
|
||||
/// Annule l'ajout
|
||||
void AddTextCommand::undo() {
|
||||
diagram -> showMe();
|
||||
diagram -> removeIndependentTextItem(textitem);
|
||||
}
|
||||
|
||||
/// Refait l'ajout
|
||||
void AddTextCommand::redo() {
|
||||
diagram -> showMe();
|
||||
diagram -> addIndependentTextItem(textitem);
|
||||
textitem -> setPos(position);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param dia Schema auquel on ajoute une image
|
||||
@param image Image ajoute
|
||||
@param pos Position a laquelle l'image est ajoute
|
||||
@param parent QUndoCommand parent
|
||||
* Specialized template function
|
||||
*/
|
||||
AddImageCommand::AddImageCommand(Diagram *dia, DiagramImageItem *image, const QPointF &pos, QUndoCommand *parent):
|
||||
QUndoCommand(QObject::tr("Ajouter une image", "undo caption"), parent),
|
||||
imageitem(image),
|
||||
diagram(dia),
|
||||
position(pos)
|
||||
{
|
||||
diagram -> qgiManager().manage(imageitem);
|
||||
template<>
|
||||
QString itemText <DiagramImageItem *> (DiagramImageItem *item) {
|
||||
Q_UNUSED(item);
|
||||
return QObject::tr("une image");
|
||||
}
|
||||
|
||||
///Destructor
|
||||
AddImageCommand::~AddImageCommand() {
|
||||
diagram -> qgiManager().release(imageitem);
|
||||
template<>
|
||||
QString itemText <IndependentTextItem *> (IndependentTextItem *item) {
|
||||
Q_UNUSED(item);
|
||||
return QObject::tr("un champ texte");
|
||||
}
|
||||
|
||||
///Annule l'ajout
|
||||
void AddImageCommand::undo() {
|
||||
diagram -> showMe();
|
||||
diagram -> removeItem(imageitem);
|
||||
template<>
|
||||
QString itemText <Element *> (Element *item) {
|
||||
return QObject::tr("un \351l\351ment : %1").arg(item->name());
|
||||
}
|
||||
|
||||
///Refait l'ajout
|
||||
void AddImageCommand::redo() {
|
||||
diagram -> showMe();
|
||||
diagram -> addDiagramImageItem(imageitem);
|
||||
imageitem -> setPos(position - imageitem -> boundingRect().center());
|
||||
template<>
|
||||
QString itemText <QetShapeItem *> (QetShapeItem *item) {
|
||||
Q_UNUSED(item);
|
||||
return QObject::tr("une shape");
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param dia Schema auquel on ajoute une shape
|
||||
@param shape Shape ajoute
|
||||
@param pos Position a laquelle l'shape est ajoute
|
||||
@param parent QUndoCommand parent
|
||||
*/
|
||||
AddShapeCommand::AddShapeCommand(Diagram *dia, QetShapeItem *shape, const QPointF &pos, QUndoCommand *parent):
|
||||
QUndoCommand(QObject::tr("Ajouter une Shape", "undo caption"), parent),
|
||||
shapeitem(shape),
|
||||
diagram(dia),
|
||||
position(pos)
|
||||
{
|
||||
diagram -> qgiManager().manage(shapeitem);
|
||||
}
|
||||
|
||||
///Destructor
|
||||
AddShapeCommand::~AddShapeCommand() {
|
||||
diagram -> qgiManager().release(shapeitem);
|
||||
}
|
||||
|
||||
///Annule l'ajout
|
||||
void AddShapeCommand::undo() {
|
||||
diagram -> showMe();
|
||||
diagram -> removeItem(shapeitem);
|
||||
}
|
||||
|
||||
///Refait l'ajout
|
||||
void AddShapeCommand::redo() {
|
||||
diagram -> showMe();
|
||||
if (shapeitem ->diagram() != diagram)
|
||||
diagram -> addItem(shapeitem);
|
||||
//diagram -> addDiagramImageItem(imageitem);
|
||||
//imageitem -> setPos(position - imageitem -> boundingRect().center());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param d Schema auquel on ajoute un conducteur
|
||||
@param c Conducteur ajoute
|
||||
@param parent QUndoCommand parent
|
||||
*/
|
||||
AddConductorCommand::AddConductorCommand(
|
||||
Diagram *d,
|
||||
Conductor *c,
|
||||
QUndoCommand *parent
|
||||
) :
|
||||
QUndoCommand(QObject::tr("ajouter un conducteur", "undo caption"), parent),
|
||||
conductor(c),
|
||||
diagram(d)
|
||||
{
|
||||
diagram -> qgiManager().manage(conductor);
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
AddConductorCommand::~AddConductorCommand() {
|
||||
diagram -> qgiManager().release(conductor);
|
||||
}
|
||||
|
||||
/// Annule l'ajout
|
||||
void AddConductorCommand::undo() {
|
||||
diagram -> showMe();
|
||||
diagram -> removeConductor(conductor);
|
||||
}
|
||||
|
||||
/// Refait l'ajout
|
||||
void AddConductorCommand::redo() {
|
||||
diagram -> showMe();
|
||||
diagram -> addConductor(conductor);
|
||||
template<>
|
||||
QString itemText <Conductor *> (Conductor *item) {
|
||||
Q_UNUSED(item);
|
||||
return QObject::tr("un conducteur");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,17 +93,17 @@ void DeleteElementsCommand::undo() {
|
||||
diagram -> showMe();
|
||||
// remet les elements
|
||||
foreach(Element *e, removed_content.elements) {
|
||||
diagram -> addElement(e);
|
||||
diagram -> addItem(e);
|
||||
}
|
||||
|
||||
// remet les conducteurs
|
||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||
diagram -> addConductor(c);
|
||||
diagram -> addItem(c);
|
||||
}
|
||||
|
||||
// remet les textes
|
||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||
diagram -> addIndependentTextItem(t);
|
||||
diagram -> addItem(t);
|
||||
}
|
||||
|
||||
foreach(DiagramImageItem *dii, removed_content.images) {
|
||||
@@ -276,7 +124,7 @@ void DeleteElementsCommand::redo() {
|
||||
|
||||
// Remove Conductor
|
||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||
diagram -> removeConductor(c);
|
||||
diagram -> removeItem(c);
|
||||
|
||||
//If option one text per folio is enable, and the text item of
|
||||
//current conductor is visible (that mean the conductor own the single displayed text)
|
||||
@@ -293,12 +141,12 @@ void DeleteElementsCommand::redo() {
|
||||
|
||||
// Remove elements
|
||||
foreach(Element *e, removed_content.elements) {
|
||||
diagram -> removeElement(e);
|
||||
diagram -> removeItem(e);
|
||||
}
|
||||
|
||||
// Remove texts
|
||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||
diagram -> removeIndependentTextItem(t);
|
||||
diagram -> removeItem(t);
|
||||
}
|
||||
|
||||
// Remove images
|
||||
@@ -350,16 +198,16 @@ PasteDiagramCommand::~PasteDiagramCommand() {
|
||||
void PasteDiagramCommand::undo() {
|
||||
diagram -> showMe();
|
||||
// remove the conductors
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> removeConductor(c);
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> removeItem(c);
|
||||
|
||||
// remove the elements
|
||||
foreach(Element *e, content.elements) diagram -> removeElement(e);
|
||||
foreach(Element *e, content.elements) diagram -> removeItem(e);
|
||||
|
||||
// remove the texts
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> removeIndependentTextItem(t);
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> removeItem(t);
|
||||
|
||||
// remove the images
|
||||
foreach(DiagramImageItem *dii, content.images) diagram -> removeItem(dii);
|
||||
// remove the images and shapes
|
||||
foreach(QGraphicsItem *qgi, content.items(DiagramContent::Images | DiagramContent::Shapes)) diagram -> removeItem(qgi);
|
||||
}
|
||||
|
||||
/// refait le coller
|
||||
@@ -373,21 +221,18 @@ void PasteDiagramCommand::redo() {
|
||||
}
|
||||
else {
|
||||
// paste the elements
|
||||
foreach(Element *e, content.elements) diagram -> addElement(e);
|
||||
foreach(Element *e, content.elements) diagram -> addItem(e);
|
||||
|
||||
// paste the conductors
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> addConductor(c);
|
||||
foreach(Conductor *c, content.conductorsToMove) diagram -> addItem(c);
|
||||
|
||||
// paste the texts
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> addIndependentTextItem(t);
|
||||
foreach(IndependentTextItem *t, content.textFields) diagram -> addItem(t);
|
||||
|
||||
// paste the images
|
||||
foreach(DiagramImageItem *dii, content.images) diagram -> addDiagramImageItem(dii);
|
||||
// paste the images and shapes
|
||||
foreach(QGraphicsItem *qgi, content.items(DiagramContent::Images | DiagramContent::Shapes)) diagram -> addItem(qgi);
|
||||
}
|
||||
foreach(Element *e, content.elements) e -> setSelected(true);
|
||||
foreach(Conductor *c, content.conductorsToMove) c -> setSelected(true);
|
||||
foreach(IndependentTextItem *t, content.textFields) t -> setSelected(true);
|
||||
foreach(DiagramImageItem *dii, content.images) dii -> setSelected(true);
|
||||
foreach (QGraphicsItem *qgi, content.items()) qgi -> setSelected(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
#include "qet.h"
|
||||
#include "qetgraphicsitem/qetshapeitem.h"
|
||||
#include "conductorprofile.h"
|
||||
class Diagram;
|
||||
#include "diagram.h"
|
||||
|
||||
class DiagramTextItem;
|
||||
class Element;
|
||||
class ElementTextItem;
|
||||
@@ -34,136 +35,52 @@ class IndependentTextItem;
|
||||
class DiagramImageItem;
|
||||
|
||||
/**
|
||||
This command adds an element to a particular diagram.
|
||||
*/
|
||||
class AddElementCommand : public QUndoCommand {
|
||||
// constructors, destructor
|
||||
* @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:
|
||||
AddElementCommand(Diagram *, Element *, const QPointF &, QUndoCommand * = 0);
|
||||
virtual ~AddElementCommand();
|
||||
private:
|
||||
AddElementCommand(const AddElementCommand &);
|
||||
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);
|
||||
}
|
||||
|
||||
// methods
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
virtual ~AddItemCommand() {
|
||||
m_diagram -> qgiManager().release(m_item);
|
||||
}
|
||||
|
||||
virtual void undo() {
|
||||
m_diagram -> showMe();
|
||||
m_diagram -> removeItem(m_item);
|
||||
}
|
||||
|
||||
virtual void redo() {
|
||||
m_diagram -> showMe();
|
||||
m_diagram -> addItem(m_item);
|
||||
m_item -> setPos(m_pos);
|
||||
}
|
||||
|
||||
// attributes
|
||||
private:
|
||||
/// added element
|
||||
Element *element;
|
||||
/// diagram the element is added to
|
||||
Diagram *diagram;
|
||||
/// position of the element on the diagram
|
||||
QPointF position;
|
||||
QGI m_item;
|
||||
Diagram *m_diagram;
|
||||
QPointF m_pos;
|
||||
};
|
||||
|
||||
/**
|
||||
This command adds an independent (i.e. related to neither an element nor a
|
||||
conductor) text item to a particular diagram.
|
||||
*/
|
||||
class AddTextCommand : public QUndoCommand {
|
||||
// constructors, destructor
|
||||
public:
|
||||
AddTextCommand(Diagram *, IndependentTextItem *, const QPointF &, QUndoCommand * = 0);
|
||||
virtual ~AddTextCommand();
|
||||
private:
|
||||
AddTextCommand(const AddTextCommand &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
/// added text item
|
||||
IndependentTextItem *textitem;
|
||||
/// diagram the text item is added to
|
||||
Diagram *diagram;
|
||||
/// position of the text item on the diagram
|
||||
QPointF position;
|
||||
};
|
||||
|
||||
/**
|
||||
This command adds an image item to a particular diagram
|
||||
*/
|
||||
class AddImageCommand : public QUndoCommand {
|
||||
//constructors, destructor
|
||||
public:
|
||||
AddImageCommand (Diagram *, DiagramImageItem *, const QPointF &, QUndoCommand * = 0);
|
||||
virtual ~AddImageCommand();
|
||||
private:
|
||||
AddImageCommand(const AddImageCommand &);
|
||||
|
||||
//methods
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
/// added image item
|
||||
DiagramImageItem *imageitem;
|
||||
/// diagram the image item is added to
|
||||
Diagram *diagram;
|
||||
/// position of the image item on the diagram
|
||||
QPointF position;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This command adds an image item to a particular diagram
|
||||
*/
|
||||
class AddShapeCommand : public QUndoCommand {
|
||||
//constructors, destructor
|
||||
public:
|
||||
AddShapeCommand (Diagram *, QetShapeItem *, const QPointF &, QUndoCommand * = 0);
|
||||
virtual ~AddShapeCommand();
|
||||
private:
|
||||
AddShapeCommand(const AddShapeCommand &);
|
||||
|
||||
//methods
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
/// added shape item
|
||||
QetShapeItem *shapeitem;
|
||||
/// diagram the image item is added to
|
||||
Diagram *diagram;
|
||||
/// position of the image item on the diagram
|
||||
QPointF position;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
This command adds a conductor to a particular diagram.
|
||||
*/
|
||||
class AddConductorCommand : public QUndoCommand {
|
||||
// constructors, destructor
|
||||
public:
|
||||
AddConductorCommand(Diagram *, Conductor *, QUndoCommand * = 0);
|
||||
virtual ~AddConductorCommand();
|
||||
private:
|
||||
AddConductorCommand(const AddConductorCommand &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
/// added conductor
|
||||
Conductor *conductor;
|
||||
/// diagram the conductor is added to
|
||||
Diagram *diagram;
|
||||
};
|
||||
*Template function: return generique name of a QGraphicsItem.
|
||||
*/
|
||||
template <typename T>
|
||||
QString itemText(T item) {
|
||||
Q_UNUSED (item);
|
||||
return QObject::tr("un item");
|
||||
}
|
||||
|
||||
/**
|
||||
This command removes content from a particular diagram.
|
||||
|
||||
@@ -313,7 +313,7 @@ void DiagramView::handleTitleBlockDrop(QDropEvent *e) {
|
||||
*/
|
||||
void DiagramView::handleTextDrop(QDropEvent *e) {
|
||||
if (scene -> isReadOnly() || (e -> mimeData() -> hasText() == false) ) return;
|
||||
scene -> undoStack().push(new AddTextCommand(scene, new IndependentTextItem (e -> mimeData() -> text()), mapToScene(e->pos())));
|
||||
scene -> undoStack().push(new AddItemCommand<IndependentTextItem *>(new IndependentTextItem (e -> mimeData() -> text()), scene, mapToScene(e->pos())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -844,8 +844,8 @@ bool DiagramView::addElementAtPos(const ElementsLocation &location, const QPoint
|
||||
return(false);
|
||||
}
|
||||
|
||||
// pose de l'element sur le schema
|
||||
diagram() -> undoStack().push(new AddElementCommand(diagram(), el, mapToScene(pos)));
|
||||
//Add element to diagram
|
||||
diagram() -> undoStack().push (new AddItemCommand<Element *>(el, diagram(), mapToScene(pos)));
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,10 @@ DVEventAddImage::~DVEventAddImage() {
|
||||
*/
|
||||
bool DVEventAddImage::mousePressEvent(QMouseEvent *event) {
|
||||
if (m_image && event -> button() == Qt::LeftButton) {
|
||||
m_diagram -> undoStack().push(new AddImageCommand(m_diagram, m_image, m_dv->mapToScene(event->pos())));
|
||||
QPointF pos = m_dv -> mapToScene(event -> pos());
|
||||
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_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||
m_running = false;
|
||||
return true;
|
||||
|
||||
@@ -76,7 +76,7 @@ bool DVEventAddShape::mousePressEvent(QMouseEvent *event) {
|
||||
// Next left click finish all shape item except the polyline
|
||||
if (m_shape_type != QetShapeItem::Polyline && event->button() == Qt::LeftButton) {
|
||||
m_shape_item -> setP2 (pos);
|
||||
m_diagram -> undoStack().push (new AddShapeCommand(m_diagram, m_shape_item, pos));
|
||||
m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
|
||||
m_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||
m_running = false;
|
||||
return true;
|
||||
@@ -94,7 +94,7 @@ bool DVEventAddShape::mousePressEvent(QMouseEvent *event) {
|
||||
// m_running is set to false at the release of right button.
|
||||
if (m_shape_type == QetShapeItem::Polyline && event -> button() == Qt::RightButton) {
|
||||
m_shape_item -> setP2 (pos);
|
||||
m_diagram -> undoStack().push(new AddShapeCommand(m_diagram, m_shape_item, pos));
|
||||
m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ DVEventAddText::~DVEventAddText() {}
|
||||
|
||||
bool DVEventAddText::mousePressEvent(QMouseEvent *event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_diagram -> undoStack().push(new AddTextCommand(m_diagram,
|
||||
new IndependentTextItem("_"),
|
||||
m_diagram -> undoStack().push(new AddItemCommand<IndependentTextItem *>(new IndependentTextItem("_"),
|
||||
m_diagram,
|
||||
m_dv -> mapToScene(event -> pos())));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
||||
link_type_ = Simple;
|
||||
uuid_ = QUuid::createUuid();
|
||||
setZValue(10);
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -407,7 +407,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// autrement, on pose un conducteur
|
||||
Conductor *new_conductor = new Conductor(this, other_terminal);
|
||||
new_conductor -> setProperties(d -> defaultConductorProperties);
|
||||
d -> undoStack().push(new AddConductorCommand(d, new_conductor));
|
||||
d -> undoStack().push(new AddItemCommand<Conductor *>(new_conductor, d));
|
||||
new_conductor -> autoText();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user