terminal editor : use QPropertyUndoCommand instead of ChangePartCommand

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4071 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-07-24 12:08:03 +00:00
parent 99c867d6d6
commit d56e6e60b1
4 changed files with 73 additions and 43 deletions

View File

@@ -140,10 +140,13 @@ QRectF PartTerminal::boundingRect() const
Definit l'orientation de la borne Definit l'orientation de la borne
@param ori la nouvelle 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(); prepareGeometryChange();
m_orientation = ori; m_orientation = ori;
updateSecondPoint(); updateSecondPoint();
emit orientationChanged();
} }
/** /**

View File

@@ -36,6 +36,9 @@ class PartTerminal : public CustomElementGraphicPart
virtual ~PartTerminal(); virtual ~PartTerminal();
private: private:
PartTerminal(const PartTerminal &); PartTerminal(const PartTerminal &);
signals:
void orientationChanged();
// attributes // attributes
private: private:

View File

@@ -18,6 +18,7 @@
#include "terminaleditor.h" #include "terminaleditor.h"
#include "partterminal.h" #include "partterminal.h"
#include "qeticons.h" #include "qeticons.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
/** /**
Constructeur Constructeur
@@ -27,7 +28,8 @@
*/ */
TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) : TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
ElementItemEditor(editor, parent), ElementItemEditor(editor, parent),
part(term) part(term),
m_locked(false)
{ {
qle_x = new QDoubleSpinBox(); qle_x = new QDoubleSpinBox();
qle_y = new QDoubleSpinBox(); qle_y = new QDoubleSpinBox();
@@ -75,18 +77,26 @@ TerminalEditor::~TerminalEditor() {
@param new_part Nouvelle primitive a editer @param new_part Nouvelle primitive a editer
@return true si l'editeur a accepter d'editer la primitive, false sinon @return true si l'editeur a accepter d'editer la primitive, false sinon
*/ */
bool TerminalEditor::setPart(CustomElementPart *new_part) { bool TerminalEditor::setPart(CustomElementPart *new_part)
if (!new_part) { {
if (!new_part)
{
if (part)
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
part = 0; part = 0;
return(true); return(true);
} }
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part)) { if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
{
if(part == part_terminal) return true;
if (part)
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
part = part_terminal; part = part_terminal;
updateForm(); updateForm();
connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
return(true); return(true);
} else {
return(false);
} }
return(false);
} }
/** /**
@@ -96,28 +106,35 @@ CustomElementPart *TerminalEditor::currentPart() const {
return(part); return(part);
} }
/** /// Met a jour l'orientation de la borne et cree un objet d'annulation
Met a jour la borne a partir des donnees du formulaire void TerminalEditor::updateTerminalO()
*/ {
void TerminalEditor::updateTerminal() { if (m_locked) return;
if (!part) return; m_locked = true;
part -> setPos(qle_x -> value(), qle_y -> value()); QVariant var(orientation -> itemData(orientation -> currentIndex()));
part -> setOrientation( if (var != part->property("orientation"))
static_cast<Qet::Orientation>( {
orientation -> itemData( QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
orientation -> currentIndex() undo->setText(tr("Modifier l'orientation d'une borne"));
).toInt() undoStack().push(undo);
) }
); m_locked = false;
} }
/// WARNING!!!! on addChangePartCommand the prop accept only the simple string! (NOT /:;,?...) void TerminalEditor::updatePos()
/// 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()); } if (m_locked) return;
/// Met a jour l'ordonnee de la position de la borne et cree un objet d'annulation m_locked = true;
void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonnée"), part, "y", qle_y -> value()); } QPointF new_pos(qle_x->value(), qle_y->value());
/// Met a jour l'orientation de la borne et cree un objet d'annulation if (new_pos != part->pos())
void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex())); } {
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 /// 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. Active ou desactive les connexionx signaux/slots entre les widgets internes.
@param active true pour activer les connexions, false pour les desactiver @param active true pour activer les connexions, false pour les desactiver
*/ */
void TerminalEditor::activeConnections(bool active) { void TerminalEditor::activeConnections(bool active)
if (active) { {
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); if (active)
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); {
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
} else { }
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); else
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); {
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
} }
} }

View File

@@ -17,9 +17,13 @@
*/ */
#ifndef TERMINAL_EDITOR_H #ifndef TERMINAL_EDITOR_H
#define TERMINAL_EDITOR_H #define TERMINAL_EDITOR_H
#include <QtWidgets>
#include "elementitemeditor.h" #include "elementitemeditor.h"
class PartTerminal; class PartTerminal;
class QDoubleSpinBox;
class QComboBox;
/** /**
This class provides a widget to edit terminals within the element editor. This class provides a widget to edit terminals within the element editor.
*/ */
@@ -34,9 +38,10 @@ class TerminalEditor : public ElementItemEditor {
// attributes // attributes
private: private:
PartTerminal *part; PartTerminal *part;
QDoubleSpinBox *qle_x, *qle_y; QDoubleSpinBox *qle_x, *qle_y;
QComboBox *orientation; QComboBox *orientation;
bool m_locked;
// methods // methods
public: public:
@@ -44,11 +49,9 @@ class TerminalEditor : public ElementItemEditor {
virtual CustomElementPart *currentPart() const; virtual CustomElementPart *currentPart() const;
public slots: public slots:
void updateTerminal(); void updateTerminalO();
void updateTerminalX(); void updatePos();
void updateTerminalY(); void updateForm();
void updateTerminalO();
void updateForm();
private: private:
void activeConnections(bool); void activeConnections(bool);