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
This commit is contained in:
xavierqet 2007-09-10 21:50:17 +00:00
parent b1ea7d6249
commit a2a65b78a8
5 changed files with 89 additions and 12 deletions

View File

@ -263,3 +263,37 @@ void ChangeHotspotCommand::applyOffset(const QPointF &o) {
qgi -> translate(o.x(), o.y()); 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);
}

View File

@ -168,4 +168,29 @@ class ChangeHotspotCommand : public QUndoCommand {
/// decalage a appliquer aux elements /// decalage a appliquer aux elements
QPoint offset; 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 #endif

View File

@ -449,17 +449,14 @@ void ElementScene::slot_editSizeHotSpot() {
connect(dialog_buttons, SIGNAL(rejected()), &dialog_sh, SLOT(reject())); connect(dialog_buttons, SIGNAL(rejected()), &dialog_sh, SLOT(reject()));
// lance le dialogue // lance le dialogue
if (dialog_sh.exec() == QDialog::Accepted) { if (dialog_sh.exec() != QDialog::Accepted) return;
undo_stack.push( QSize new_size(hotspot_editor -> elementSize());
new ChangeHotspotCommand( QSize old_size(width(), height());
this, QPoint new_hotspot(hotspot_editor -> hotspot());
QSize(width(), height()), QPoint old_hotspot(_hotspot);
hotspot_editor -> elementSize(),
_hotspot, if (new_size != old_size || new_hotspot != old_hotspot) {
hotspot_editor -> hotspot(), undo_stack.push(new ChangeHotspotCommand(this, old_size, new_size, old_hotspot, new_hotspot, hotspot_editor -> offsetParts()));
hotspot_editor -> mustTranslateParts() ? hotspot_editor -> offsetParts() : QPoint()
)
);
} }
} }
@ -521,6 +518,9 @@ void ElementScene::slot_editNames() {
connect(dialog_buttons, SIGNAL(rejected()), &dialog, SLOT(reject())); connect(dialog_buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
// lance le dialogue // 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));
}
} }

View File

@ -127,6 +127,22 @@ QDomElement NamesList::toXml(QDomDocument &xml_document) const {
return(names_elmt); 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 Retourne le nom approprie en fonction de la langue du systeme
Par ordre de preference, on prendra : Par ordre de preference, on prendra :

View File

@ -23,6 +23,8 @@ class NamesList {
int count() const; int count() const;
QString &operator[](const QString &); QString &operator[](const QString &);
const QString operator[](const QString &) const; const QString operator[](const QString &) const;
bool operator!=(const NamesList &) const;
bool operator==(const NamesList &) const;
const QString &name(const QString & = QString()) const; const QString &name(const QString & = QString()) const;
// methodes relatives a XML // methodes relatives a XML