mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Les modifications de conducteur sont desormais annulables
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@140 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
21
conducer.cpp
21
conducer.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "conducersegmentprofile.h"
|
#include "conducersegmentprofile.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "diagramcommands.h"
|
||||||
#define PR(x) qDebug() << #x " = " << x;
|
#define PR(x) qDebug() << #x " = " << x;
|
||||||
|
|
||||||
bool Conducer::pen_and_brush_initialized = false;
|
bool Conducer::pen_and_brush_initialized = false;
|
||||||
@@ -938,7 +939,11 @@ void Conducer::calculateTextItemPosition() {
|
|||||||
dans priv_modifieConducer.
|
dans priv_modifieConducer.
|
||||||
*/
|
*/
|
||||||
void Conducer::saveProfile() {
|
void Conducer::saveProfile() {
|
||||||
|
ConducerProfile old_profile = conducer_profile;
|
||||||
conducer_profile.fromConducer(this);
|
conducer_profile.fromConducer(this);
|
||||||
|
if (Diagram *dia = diagram()) {
|
||||||
|
dia -> undoStack().push(new ChangeConducerCommand(this, old_profile, conducer_profile));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -957,3 +962,19 @@ int Conducer::getCoeff(const qreal &value1, const qreal &value2) {
|
|||||||
int Conducer::getSign(const qreal &value) {
|
int Conducer::getSign(const qreal &value) {
|
||||||
return(value < 0 ? -1 : 1);
|
return(value < 0 ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Applique un nouveau profil a ce conducteur
|
||||||
|
@param cp Profil a appliquer a ce conducteur
|
||||||
|
*/
|
||||||
|
void Conducer::setProfile(const ConducerProfile &cp) {
|
||||||
|
conducer_profile = cp;
|
||||||
|
if (conducer_profile.isNull()) {
|
||||||
|
priv_calculeConducer(terminal1 -> amarrageConducer(), terminal1 -> orientation(), terminal2 -> amarrageConducer(), terminal2 -> orientation());
|
||||||
|
modified_path = false;
|
||||||
|
} else {
|
||||||
|
priv_modifieConducer(terminal1 -> amarrageConducer(), terminal1 -> orientation(), terminal2 -> amarrageConducer(), terminal2 -> orientation());
|
||||||
|
modified_path = true;
|
||||||
|
}
|
||||||
|
calculateTextItemPosition();
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class Conducer : public QGraphicsPathItem {
|
|||||||
bool fromXml(QDomElement &);
|
bool fromXml(QDomElement &);
|
||||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||||
const QList<ConducerSegment *> segmentsList() const;
|
const QList<ConducerSegment *> segmentsList() const;
|
||||||
|
void setProfile(const ConducerProfile &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
|||||||
@@ -14,11 +14,40 @@ ConducerProfile::ConducerProfile(Conducer *conducer) {
|
|||||||
fromConducer(conducer);
|
fromConducer(conducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur de copie
|
||||||
|
@param c autre conducteur
|
||||||
|
*/
|
||||||
|
ConducerProfile::ConducerProfile(const ConducerProfile &c) {
|
||||||
|
beginOrientation = c.beginOrientation;
|
||||||
|
endOrientation = c.endOrientation;
|
||||||
|
foreach(ConducerSegmentProfile *csp, c.segments) {
|
||||||
|
segments << new ConducerSegmentProfile(*csp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Operateur =
|
||||||
|
@param c autre conducteur
|
||||||
|
*/
|
||||||
|
ConducerProfile &ConducerProfile::operator=(const ConducerProfile &c) {
|
||||||
|
if (&c == this) return(*this);
|
||||||
|
|
||||||
|
// supprime ses informations
|
||||||
|
setNull();
|
||||||
|
|
||||||
|
// copie les informations de l'autre profil de conducteur
|
||||||
|
beginOrientation = c.beginOrientation;
|
||||||
|
endOrientation = c.endOrientation;
|
||||||
|
foreach(ConducerSegmentProfile *csp, c.segments) {
|
||||||
|
segments << new ConducerSegmentProfile(*csp);
|
||||||
|
}
|
||||||
|
return(*this);
|
||||||
|
}
|
||||||
|
|
||||||
/// destructeur
|
/// destructeur
|
||||||
ConducerProfile::~ConducerProfile() {
|
ConducerProfile::~ConducerProfile() {
|
||||||
foreach(ConducerSegmentProfile * s, segments) {
|
setNull();
|
||||||
delete s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return true si le profil est nul
|
/// @return true si le profil est nul
|
||||||
@@ -26,6 +55,12 @@ bool ConducerProfile::isNull() const {
|
|||||||
return(segments.isEmpty());
|
return(segments.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// supprime les segments du profil de conducteur
|
||||||
|
void ConducerProfile::setNull() {
|
||||||
|
foreach(ConducerSegmentProfile *csp, segments) delete csp;
|
||||||
|
segments.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// @return la largeur occupee par le conducteur
|
/// @return la largeur occupee par le conducteur
|
||||||
qreal ConducerProfile::width() const {
|
qreal ConducerProfile::width() const {
|
||||||
qreal width = 0.0;
|
qreal width = 0.0;
|
||||||
@@ -78,8 +113,7 @@ QList<ConducerSegmentProfile *> ConducerProfile::verticalSegments() {
|
|||||||
|
|
||||||
void ConducerProfile::fromConducer(Conducer *conducer) {
|
void ConducerProfile::fromConducer(Conducer *conducer) {
|
||||||
// supprime les segments precedents
|
// supprime les segments precedents
|
||||||
foreach(ConducerSegmentProfile *csp, segments) delete csp;
|
setNull();
|
||||||
segments.clear();
|
|
||||||
|
|
||||||
foreach(ConducerSegment *conducer_segment, conducer -> segmentsList()) {
|
foreach(ConducerSegment *conducer_segment, conducer -> segmentsList()) {
|
||||||
segments << new ConducerSegmentProfile(conducer_segment);
|
segments << new ConducerSegmentProfile(conducer_segment);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class ConducerProfile {
|
|||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
ConducerProfile();
|
ConducerProfile();
|
||||||
ConducerProfile(Conducer *conducer);
|
ConducerProfile(Conducer *conducer);
|
||||||
|
ConducerProfile(const ConducerProfile &);
|
||||||
|
ConducerProfile &operator=(const ConducerProfile &);
|
||||||
virtual ~ConducerProfile();
|
virtual ~ConducerProfile();
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
@@ -24,6 +26,7 @@ class ConducerProfile {
|
|||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
|
void setNull();
|
||||||
qreal width() const;
|
qreal width() const;
|
||||||
qreal height() const;
|
qreal height() const;
|
||||||
uint nbSegments(QET::ConducerSegmentType) const;
|
uint nbSegments(QET::ConducerSegmentType) const;
|
||||||
|
|||||||
@@ -244,16 +244,10 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
movement(m)
|
movement(m)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("d\351placer ") + QET::ElementsAndConducersSentence(elements_to_move.count(), conducers_to_move.count()));
|
setText(QObject::tr("d\351placer ") + QET::ElementsAndConducersSentence(elements_to_move.count(), conducers_to_move.count()));
|
||||||
foreach(QGraphicsItem *qgi, elements_to_move) diagram -> qgiManager().manage(qgi);
|
|
||||||
foreach(QGraphicsItem *qgi, conducers_to_move) diagram -> qgiManager().manage(qgi);
|
|
||||||
foreach(QGraphicsItem *qgi, conducers_to_update) diagram -> qgiManager().manage(qgi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
MoveElementsCommand::~MoveElementsCommand() {
|
MoveElementsCommand::~MoveElementsCommand() {
|
||||||
foreach(QGraphicsItem *qgi, elements_to_move) diagram -> qgiManager().release(qgi);
|
|
||||||
foreach(QGraphicsItem *qgi, conducers_to_move) diagram -> qgiManager().release(qgi);
|
|
||||||
foreach(QGraphicsItem *qgi, conducers_to_update) diagram -> qgiManager().release(qgi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// annule le deplacement
|
/// annule le deplacement
|
||||||
@@ -357,3 +351,39 @@ void RotateElementsCommand::redo() {
|
|||||||
e -> update();
|
e -> update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param c Conducteur modifie
|
||||||
|
@param old_p ancien profil du conducteur
|
||||||
|
@param new_p nouveau profil du conducteur
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
ChangeConducerCommand::ChangeConducerCommand(
|
||||||
|
Conducer *c,
|
||||||
|
const ConducerProfile &old_p,
|
||||||
|
const ConducerProfile &new_p,
|
||||||
|
QUndoCommand *parent
|
||||||
|
) :
|
||||||
|
QUndoCommand(QObject::tr("modifier un conducteur"), parent),
|
||||||
|
conducer(c),
|
||||||
|
old_profile(old_p),
|
||||||
|
new_profile(new_p),
|
||||||
|
first_redo(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
ChangeConducerCommand::~ChangeConducerCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Annule la modification du conducteur
|
||||||
|
void ChangeConducerCommand::undo() {
|
||||||
|
conducer -> setProfile(old_profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Refait la modification du conducteur
|
||||||
|
void ChangeConducerCommand::redo() {
|
||||||
|
if (first_redo) first_redo = false;
|
||||||
|
else conducer -> setProfile(new_profile);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
|
#include "conducer.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'action d'ajouter un element au schema
|
Cette classe represente l'action d'ajouter un element au schema
|
||||||
@@ -182,7 +183,6 @@ class ChangeDiagramTextCommand : public QUndoCommand {
|
|||||||
QString text_after;
|
QString text_after;
|
||||||
/// booleen pour ne pas executer le premier redo()
|
/// booleen pour ne pas executer le premier redo()
|
||||||
bool first_redo;
|
bool first_redo;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,4 +206,32 @@ class RotateElementsCommand : public QUndoCommand {
|
|||||||
/// texte avant changement
|
/// texte avant changement
|
||||||
QHash<Element *, QET::Orientation> elements_to_rotate;
|
QHash<Element *, QET::Orientation> elements_to_rotate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cette classe represente l'action de modifier un conducteur
|
||||||
|
*/
|
||||||
|
class ChangeConducerCommand : public QUndoCommand {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
ChangeConducerCommand(Conducer *, const ConducerProfile &, const ConducerProfile &, QUndoCommand * = 0);
|
||||||
|
virtual ~ChangeConducerCommand();
|
||||||
|
private:
|
||||||
|
ChangeConducerCommand(const ChangeConducerCommand &);
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public:
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
/// DiagramTextItem modifie
|
||||||
|
Conducer *conducer;
|
||||||
|
/// texte avant changement
|
||||||
|
ConducerProfile old_profile;
|
||||||
|
/// texte apres changement
|
||||||
|
ConducerProfile new_profile;
|
||||||
|
/// booleen pour ne pas executer le premier redo()
|
||||||
|
bool first_redo;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user