Dans l'editeur d'elements, les changements d'orientations sont desormais annulables

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@121 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-09-10 22:11:47 +00:00
parent a2a65b78a8
commit 55c79617e1
5 changed files with 83 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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() {

View File

@@ -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);

View File

@@ -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;
};