diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 7a1fee999..b2be06b05 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -140,10 +140,13 @@ QRectF PartTerminal::boundingRect() const Definit l'orientation de la borne @param ori la nouvelle orientation de la borne */ -void PartTerminal::setOrientation(Qet::Orientation ori) { +void PartTerminal::setOrientation(Qet::Orientation ori) +{ + if (m_orientation == ori) return; prepareGeometryChange(); m_orientation = ori; updateSecondPoint(); + emit orientationChanged(); } /** diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index e1aaca8fb..97fd534f4 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -36,6 +36,9 @@ class PartTerminal : public CustomElementGraphicPart virtual ~PartTerminal(); private: PartTerminal(const PartTerminal &); + + signals: + void orientationChanged(); // attributes private: diff --git a/sources/editor/terminaleditor.cpp b/sources/editor/terminaleditor.cpp index 20bf3bcc3..7aef6663f 100644 --- a/sources/editor/terminaleditor.cpp +++ b/sources/editor/terminaleditor.cpp @@ -18,6 +18,7 @@ #include "terminaleditor.h" #include "partterminal.h" #include "qeticons.h" +#include "QPropertyUndoCommand/qpropertyundocommand.h" /** Constructeur @@ -27,7 +28,8 @@ */ TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) : ElementItemEditor(editor, parent), - part(term) + part(term), + m_locked(false) { qle_x = new QDoubleSpinBox(); qle_y = new QDoubleSpinBox(); @@ -75,18 +77,26 @@ TerminalEditor::~TerminalEditor() { @param new_part Nouvelle primitive a editer @return true si l'editeur a accepter d'editer la primitive, false sinon */ -bool TerminalEditor::setPart(CustomElementPart *new_part) { - if (!new_part) { +bool TerminalEditor::setPart(CustomElementPart *new_part) +{ + if (!new_part) + { + if (part) + disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); part = 0; return(true); } - if (PartTerminal *part_terminal = dynamic_cast(new_part)) { + if (PartTerminal *part_terminal = dynamic_cast(new_part)) + { + if(part == part_terminal) return true; + if (part) + disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); part = part_terminal; updateForm(); + connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); return(true); - } else { - return(false); } + return(false); } /** @@ -96,28 +106,35 @@ CustomElementPart *TerminalEditor::currentPart() const { return(part); } -/** - Met a jour la borne a partir des donnees du formulaire -*/ -void TerminalEditor::updateTerminal() { - if (!part) return; - part -> setPos(qle_x -> value(), qle_y -> value()); - part -> setOrientation( - static_cast( - orientation -> itemData( - orientation -> currentIndex() - ).toInt() - ) - ); +/// Met a jour l'orientation de la borne et cree un objet d'annulation +void TerminalEditor::updateTerminalO() +{ + if (m_locked) return; + m_locked = true; + QVariant var(orientation -> itemData(orientation -> currentIndex())); + if (var != part->property("orientation")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var); + undo->setText(tr("Modifier l'orientation d'une borne")); + undoStack().push(undo); + } + m_locked = false; } -/// WARNING!!!! on addChangePartCommand the prop accept only the simple string! (NOT /:;,?...) -/// Met a jour l'abscisse de la position de la borne et cree un objet d'annulation -void TerminalEditor::updateTerminalX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> value()); } -/// Met a jour l'ordonnee de la position de la borne et cree un objet d'annulation -void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonnée"), part, "y", qle_y -> value()); } -/// Met a jour l'orientation de la borne et cree un objet d'annulation -void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex())); } +void TerminalEditor::updatePos() +{ + if (m_locked) return; + m_locked = true; + QPointF new_pos(qle_x->value(), qle_y->value()); + if (new_pos != part->pos()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos); + undo->setText(tr("Déplacer une borne")); + undo->enableAnimation(); + undoStack().push(undo); + } + m_locked=false; +} /// update Number and name, create cancel object /** @@ -136,14 +153,18 @@ void TerminalEditor::updateForm() { Active ou desactive les connexionx signaux/slots entre les widgets internes. @param active true pour activer les connexions, false pour les desactiver */ -void TerminalEditor::activeConnections(bool active) { - if (active) { - connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); - connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); +void TerminalEditor::activeConnections(bool active) +{ + if (active) + { + connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos())); + connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos())); connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); - } else { - disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); - disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); + } + else + { + disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos())); + disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos())); disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); } } diff --git a/sources/editor/terminaleditor.h b/sources/editor/terminaleditor.h index a5cdd6799..bdee8e723 100644 --- a/sources/editor/terminaleditor.h +++ b/sources/editor/terminaleditor.h @@ -17,9 +17,13 @@ */ #ifndef TERMINAL_EDITOR_H #define TERMINAL_EDITOR_H -#include + #include "elementitemeditor.h" + class PartTerminal; +class QDoubleSpinBox; +class QComboBox; + /** This class provides a widget to edit terminals within the element editor. */ @@ -34,9 +38,10 @@ class TerminalEditor : public ElementItemEditor { // attributes private: - PartTerminal *part; - QDoubleSpinBox *qle_x, *qle_y; - QComboBox *orientation; + PartTerminal *part; + QDoubleSpinBox *qle_x, *qle_y; + QComboBox *orientation; + bool m_locked; // methods public: @@ -44,11 +49,9 @@ class TerminalEditor : public ElementItemEditor { virtual CustomElementPart *currentPart() const; public slots: - void updateTerminal(); - void updateTerminalX(); - void updateTerminalY(); - void updateTerminalO(); - void updateForm(); + void updateTerminalO(); + void updatePos(); + void updateForm(); private: void activeConnections(bool);