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