diff --git a/conducer.cpp b/conducer.cpp index 85ce495c3..db2a7f97f 100644 --- a/conducer.cpp +++ b/conducer.cpp @@ -65,7 +65,6 @@ Conducer::Conducer(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene * mais s'en detache */ Conducer::~Conducer() { -// qDebug() << "~Conducer()" << (void *)this; // se detache des bornes if (!isDestroyed()) destroy(); @@ -939,7 +938,7 @@ void Conducer::calculateTextItemPosition() { dans priv_modifieConducer. */ void Conducer::saveProfile() { - conducer_profile = ConducerProfile(this); + conducer_profile.fromConducer(this); } /** diff --git a/conducerprofile.cpp b/conducerprofile.cpp index 5cdae1d3b..c24162fb2 100644 --- a/conducerprofile.cpp +++ b/conducerprofile.cpp @@ -11,15 +11,14 @@ ConducerProfile::ConducerProfile() { @param Conducer conducteur dont il faut extraire le profil */ ConducerProfile::ConducerProfile(Conducer *conducer) { - foreach(ConducerSegment *conducer_segment, conducer -> segmentsList()) { - segments << new ConducerSegmentProfile(conducer_segment); - } - beginOrientation = conducer -> terminal1 -> orientation(); - endOrientation = conducer -> terminal2 -> orientation(); + fromConducer(conducer); } /// destructeur ConducerProfile::~ConducerProfile() { + foreach(ConducerSegmentProfile * s, segments) { + delete s; + } } /// @return true si le profil est nul @@ -77,6 +76,18 @@ QList ConducerProfile::verticalSegments() { return(segments_list); } +void ConducerProfile::fromConducer(Conducer *conducer) { + // supprime les segments precedents + foreach(ConducerSegmentProfile *csp, segments) delete csp; + segments.clear(); + + foreach(ConducerSegment *conducer_segment, conducer -> segmentsList()) { + segments << new ConducerSegmentProfile(conducer_segment); + } + beginOrientation = conducer -> terminal1 -> orientation(); + endOrientation = conducer -> terminal2 -> orientation(); +} + /** Permet de debugger un profil de conducteur @param d Object QDebug a utiliser pour l'affichage des informations de debug diff --git a/conducerprofile.h b/conducerprofile.h index 20364547e..0cd9a3deb 100644 --- a/conducerprofile.h +++ b/conducerprofile.h @@ -29,6 +29,7 @@ class ConducerProfile { uint nbSegments(QET::ConducerSegmentType) const; QList horizontalSegments(); QList verticalSegments(); + void fromConducer(Conducer *); }; QDebug &operator<<(QDebug d, ConducerProfile &); #endif diff --git a/diagramcommands.cpp b/diagramcommands.cpp index f17543c1d..575fea33d 100644 --- a/diagramcommands.cpp +++ b/diagramcommands.cpp @@ -327,3 +327,33 @@ void ChangeDiagramTextCommand::redo() { text_item -> previous_text = text_after; } } + +/** + Constructeur + @param elements Elements a pivoter associes a leur orientation d'origine + @param parent QUndoCommand parent +*/ +RotateElementsCommand::RotateElementsCommand(const QHash &elements, QUndoCommand *parent) : + QUndoCommand(QObject::tr("pivoter ") + QET::ElementsAndConducersSentence(elements.count(), 0), parent), + elements_to_rotate(elements) +{ +} + +/// Destructeur +RotateElementsCommand::~RotateElementsCommand() { +} + +/// defait le pivotement +void RotateElementsCommand::undo() { + foreach(Element *e, elements_to_rotate.keys()) { + e -> setOrientation(elements_to_rotate[e]); + } +} + +/// refait le pivotement +void RotateElementsCommand::redo() { + foreach(Element *e, elements_to_rotate.keys()) { + e -> setOrientation(e -> orientation().next()); + e -> update(); + } +} diff --git a/diagramcommands.h b/diagramcommands.h index beb840f98..c97cf1a3f 100644 --- a/diagramcommands.h +++ b/diagramcommands.h @@ -1,5 +1,6 @@ #ifndef DIAGRAM_COMMANDS_H #define DIAGRAM_COMMANDS_H +#include "qet.h" #include "diagram.h" #include "diagramtextitem.h" #include @@ -183,4 +184,26 @@ class ChangeDiagramTextCommand : public QUndoCommand { bool first_redo; }; + +/** + Cette classe represente l'action de pivoter plusieurs elements +*/ +class RotateElementsCommand : public QUndoCommand { + // constructeurs, destructeur + public: + RotateElementsCommand(const QHash &elements, QUndoCommand * = 0); + virtual ~RotateElementsCommand(); + private: + RotateElementsCommand(const RotateElementsCommand &); + + // methodes + public: + virtual void undo(); + virtual void redo(); + + // attributs + private: + /// texte avant changement + QHash elements_to_rotate; +}; #endif diff --git a/diagramview.cpp b/diagramview.cpp index 65949f83c..1acf48758 100644 --- a/diagramview.cpp +++ b/diagramview.cpp @@ -104,12 +104,13 @@ void DiagramView::supprimer() { */ void DiagramView::pivoter() { if (scene -> selectedItems().isEmpty()) return; + QHash elements_to_rotate; foreach (QGraphicsItem *item, scene -> selectedItems()) { - if (Element *elt = qgraphicsitem_cast(item)) { - elt -> setOrientation(elt -> orientation().next()); - elt -> update(); + if (Element *e = qgraphicsitem_cast(item)) { + elements_to_rotate.insert(e, e -> orientation().current()); } } + scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate)); } /**