From a2a65b78a81443b2d7d2da30976cbd6e02d0beab Mon Sep 17 00:00:00 2001 From: xavierqet Date: Mon, 10 Sep 2007 21:50:17 +0000 Subject: [PATCH] Dans l'editeur d'elements, les changements de noms sont desormais annulables git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@120 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- editor/editorcommands.cpp | 34 ++++++++++++++++++++++++++++++++++ editor/editorcommands.h | 25 +++++++++++++++++++++++++ editor/elementscene.cpp | 24 ++++++++++++------------ nameslist.cpp | 16 ++++++++++++++++ nameslist.h | 2 ++ 5 files changed, 89 insertions(+), 12 deletions(-) diff --git a/editor/editorcommands.cpp b/editor/editorcommands.cpp index 3eb1e9b90..0b4db7af5 100644 --- a/editor/editorcommands.cpp +++ b/editor/editorcommands.cpp @@ -263,3 +263,37 @@ void ChangeHotspotCommand::applyOffset(const QPointF &o) { qgi -> translate(o.x(), o.y()); } } + +/** + Constructeur + @param element_scene Element edite + @param before Listes des noms avant changement + @param after Listes des noms apres changement + @param parent QUndoCommand parent +*/ +ChangeNamesCommand::ChangeNamesCommand( + ElementScene *element_scene, + const NamesList &before, + const NamesList &after, + QUndoCommand *parent +) : + QUndoCommand(QObject::tr("modification noms"), parent), + names_before(before), + names_after(after), + element(element_scene) +{ +} + +/// Destructeur +ChangeNamesCommand::~ChangeNamesCommand() { +} + +/// Annule le changement +void ChangeNamesCommand::undo() { + element -> setNames(names_before); +} + +/// Refait le changement +void ChangeNamesCommand::redo() { + element -> setNames(names_after); +} diff --git a/editor/editorcommands.h b/editor/editorcommands.h index e200d96a6..d5401af73 100644 --- a/editor/editorcommands.h +++ b/editor/editorcommands.h @@ -168,4 +168,29 @@ class ChangeHotspotCommand : public QUndoCommand { /// decalage a appliquer aux elements QPoint offset; }; + +/** + Cette classe represente l'action de changer les noms d'un element +*/ +class ChangeNamesCommand : public QUndoCommand { + // constructeurs, destructeur + public: + ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand * = 0); + virtual ~ChangeNamesCommand(); + private: + ChangeNamesCommand(const ChangeNamesCommand &); + + // methodes + virtual void undo(); + virtual void redo(); + + // attributs + private: + /// Liste des noms avant changement + NamesList names_before; + /// Liste des noms apres changement + NamesList names_after; + /// scene sur laquelle se produisent les actions + ElementScene *element; +}; #endif diff --git a/editor/elementscene.cpp b/editor/elementscene.cpp index d5127dd9c..c517f89d0 100644 --- a/editor/elementscene.cpp +++ b/editor/elementscene.cpp @@ -449,17 +449,14 @@ void ElementScene::slot_editSizeHotSpot() { connect(dialog_buttons, SIGNAL(rejected()), &dialog_sh, SLOT(reject())); // lance le dialogue - if (dialog_sh.exec() == QDialog::Accepted) { - undo_stack.push( - new ChangeHotspotCommand( - this, - QSize(width(), height()), - hotspot_editor -> elementSize(), - _hotspot, - hotspot_editor -> hotspot(), - hotspot_editor -> mustTranslateParts() ? hotspot_editor -> offsetParts() : QPoint() - ) - ); + if (dialog_sh.exec() != QDialog::Accepted) return; + QSize new_size(hotspot_editor -> elementSize()); + QSize old_size(width(), height()); + QPoint new_hotspot(hotspot_editor -> hotspot()); + QPoint old_hotspot(_hotspot); + + if (new_size != old_size || new_hotspot != old_hotspot) { + undo_stack.push(new ChangeHotspotCommand(this, old_size, new_size, old_hotspot, new_hotspot, hotspot_editor -> offsetParts())); } } @@ -521,6 +518,9 @@ void ElementScene::slot_editNames() { connect(dialog_buttons, SIGNAL(rejected()), &dialog, SLOT(reject())); // lance le dialogue - if (dialog.exec() == QDialog::Accepted) _names = names_widget -> names(); + if (dialog.exec() == QDialog::Accepted) { + NamesList new_names(names_widget -> names()); + if (new_names != _names) undoStack().push(new ChangeNamesCommand(this, _names, new_names)); + } } diff --git a/nameslist.cpp b/nameslist.cpp index 096f63837..e234bbc0a 100644 --- a/nameslist.cpp +++ b/nameslist.cpp @@ -127,6 +127,22 @@ QDomElement NamesList::toXml(QDomDocument &xml_document) const { return(names_elmt); } +/** + @param nl une autre liste de noms + @return true si les listes de noms sont differentes, false sinon +*/ +bool NamesList::operator!=(const NamesList &nl) const { + return(hash_names != nl.hash_names); +} + +/** + @param nl une autre liste de noms + @return true si les listes de noms sont identiques, false sinon +*/ +bool NamesList::operator==(const NamesList &nl) const { + return(hash_names == nl.hash_names); +} + /** Retourne le nom approprie en fonction de la langue du systeme Par ordre de preference, on prendra : diff --git a/nameslist.h b/nameslist.h index 6d704e4d9..12b596cad 100644 --- a/nameslist.h +++ b/nameslist.h @@ -23,6 +23,8 @@ class NamesList { int count() const; QString &operator[](const QString &); const QString operator[](const QString &) const; + bool operator!=(const NamesList &) const; + bool operator==(const NamesList &) const; const QString &name(const QString & = QString()) const; // methodes relatives a XML