diff --git a/editor/editorcommands.cpp b/editor/editorcommands.cpp index 6f40b5a57..c667a7a95 100644 --- a/editor/editorcommands.cpp +++ b/editor/editorcommands.cpp @@ -162,3 +162,27 @@ void ChangePartCommand::undo() { void ChangePartCommand::redo() { cep -> setProperty(property, new_value); } + +ChangePolygonPointsCommand::ChangePolygonPointsCommand( + PartPolygon *p, + const QVector &o_points, + const QVector &n_points, + QUndoCommand *parent +) : + QUndoCommand(QObject::tr("modification points polygone"), parent), + polygon(p), + old_points(o_points), + new_points(n_points) +{ +} + +ChangePolygonPointsCommand::~ChangePolygonPointsCommand() { +} + +void ChangePolygonPointsCommand::undo() { + polygon -> setPolygon(old_points); +} + +void ChangePolygonPointsCommand::redo() { + polygon -> setPolygon(new_points); +} diff --git a/editor/editorcommands.h b/editor/editorcommands.h index c09e28db6..fce2510ad 100644 --- a/editor/editorcommands.h +++ b/editor/editorcommands.h @@ -1,6 +1,7 @@ #ifndef EDITOR_COMMANDS_H #define EDITOR_COMMANDS_H #include "customelementpart.h" +#include "partpolygon.h" #include "elementscene.h" #include "qgimanager.h" #include @@ -109,4 +110,28 @@ class ChangePartCommand : public QUndoCommand { /// nouvelle valeur QVariant new_value; }; + +/** + Cette classe represente l'action de modifier les points composants un polygone +*/ +class ChangePolygonPointsCommand : public QUndoCommand { + // constructeurs, destructeur + public: + ChangePolygonPointsCommand(PartPolygon *, const QVector &, const QVector &, QUndoCommand * = 0); + virtual ~ChangePolygonPointsCommand(); + private: + ChangePolygonPointsCommand(const ChangePolygonPointsCommand &); + + // methodes + virtual void undo(); + virtual void redo(); + + // attributs + /// Polygone modifie + PartPolygon *polygon; + /// anciens points + QVector old_points; + /// nouveaux points + QVector new_points; +}; #endif diff --git a/editor/polygoneditor.cpp b/editor/polygoneditor.cpp index 614eaf1e5..6adaf4892 100644 --- a/editor/polygoneditor.cpp +++ b/editor/polygoneditor.cpp @@ -48,7 +48,7 @@ void PolygonEditor::updatePolygonPoints() { ); return; } - part -> setPolygon(points); + undoStack().push(new ChangePolygonPointsCommand(part, part -> polygon(), points)); } void PolygonEditor::updatePolygonClosedState() { @@ -61,7 +61,6 @@ void PolygonEditor::updatePolygonClosedState() { QVariant(close_polygon.isChecked()) ) ); -// part -> setClosed(close_polygon.isChecked()); } void PolygonEditor::updateForm() {