diff --git a/editor/editorcommands.cpp b/editor/editorcommands.cpp index 0b4db7af5..1af1827ed 100644 --- a/editor/editorcommands.cpp +++ b/editor/editorcommands.cpp @@ -297,3 +297,38 @@ void ChangeNamesCommand::undo() { void ChangeNamesCommand::redo() { element -> setNames(names_after); } + +/** + Constructeur + @param element_scene Element edite + @param before Orientations avant changement + @param after Orientationss apres changement + @param parent QUndoCommand parent +*/ +ChangeOrientationsCommand::ChangeOrientationsCommand( + ElementScene *element_scene, + const OrientationSet &before, + const OrientationSet &after, + QUndoCommand *parent +) : + QUndoCommand(QObject::tr("modification orientations"), parent), + ori_before(before), + ori_after(after), + element(element_scene) +{ +} + +/// Destructeur +ChangeOrientationsCommand::~ChangeOrientationsCommand() { +} + +/// Annule le changement +void ChangeOrientationsCommand::undo() { + element -> setOrientations(ori_before); +} + +/// Refait le changement +void ChangeOrientationsCommand::redo() { + element -> setOrientations(ori_after); +} + diff --git a/editor/editorcommands.h b/editor/editorcommands.h index d5401af73..1a5a7ee82 100644 --- a/editor/editorcommands.h +++ b/editor/editorcommands.h @@ -190,7 +190,32 @@ class ChangeNamesCommand : public QUndoCommand { NamesList names_before; /// Liste des noms apres changement NamesList names_after; - /// scene sur laquelle se produisent les actions + /// Element edite auquel il faut appliquer les modifications + ElementScene *element; +}; + +/** + Cette classe represente l'action de changer les noms d'un element +*/ +class ChangeOrientationsCommand : public QUndoCommand { + // constructeurs, destructeur + public: + ChangeOrientationsCommand(ElementScene *, const OrientationSet &, const OrientationSet &, QUndoCommand * = 0); + virtual ~ChangeOrientationsCommand(); + private: + ChangeOrientationsCommand(const ChangeOrientationsCommand &); + + // methodes + virtual void undo(); + virtual void redo(); + + // attributs + private: + /// Orientations avant changement + OrientationSet ori_before; + /// Orientations apres changement + OrientationSet ori_after; + /// Element edite auquel il faut appliquer les modifications ElementScene *element; }; #endif diff --git a/editor/elementscene.cpp b/editor/elementscene.cpp index c517f89d0..d02a26e7d 100644 --- a/editor/elementscene.cpp +++ b/editor/elementscene.cpp @@ -487,7 +487,12 @@ void ElementScene::slot_editOrientations() { connect(dialog_buttons, SIGNAL(rejected()), &dialog_ori, SLOT(reject())); // lance le dialogue - if (dialog_ori.exec() == QDialog::Accepted) ori = ori_widget -> orientationSet(); + if (dialog_ori.exec() == QDialog::Accepted) { + OrientationSet new_ori = ori_widget -> orientationSet(); + if (new_ori != ori) { + undoStack().push(new ChangeOrientationsCommand(this, ori, new_ori)); + } + } } void ElementScene::slot_editNames() { diff --git a/orientationset.cpp b/orientationset.cpp index 4eb5c322a..aed5b7adf 100644 --- a/orientationset.cpp +++ b/orientationset.cpp @@ -131,6 +131,20 @@ const OrientationSet OrientationSet::operator--() { return(*this); } +bool OrientationSet::operator==(const OrientationSet &os) const { + if (north_ori != os.north_ori) return(false); + if (east_ori != os.east_ori) return(false); + if (south_ori != os.south_ori) return(false); + if (west_ori != os.west_ori) return(false); + if (default_ori != os.default_ori) return(false); + if (current_ori != os.current_ori) return(false); + return(true); +} + +bool OrientationSet::operator!=(const OrientationSet &os) const { + return(!(this -> operator==(os))); +} + bool OrientationSet::fromString(const QString &str) { QRegExp osv("^([dyn])([dyn])([dyn])([dyn])$"); // osv : Orientation String Validator if (osv.indexIn(str) == -1) return(false); diff --git a/orientationset.h b/orientationset.h index 94ddc43e6..5116c0d6f 100644 --- a/orientationset.h +++ b/orientationset.h @@ -40,6 +40,8 @@ class OrientationSet { const OrientationSet operator--(int); const OrientationSet operator++(); const OrientationSet operator--(); + bool operator==(const OrientationSet &) const; + bool operator!=(const OrientationSet &) const; bool fromString(const QString &); QString toString() const; };