mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02: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:
parent
27e8ced638
commit
2c184a46da
21
conducer.cpp
21
conducer.cpp
@ -4,6 +4,7 @@
|
||||
#include "conducersegmentprofile.h"
|
||||
#include "element.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramcommands.h"
|
||||
#define PR(x) qDebug() << #x " = " << x;
|
||||
|
||||
bool Conducer::pen_and_brush_initialized = false;
|
||||
@ -938,7 +939,11 @@ void Conducer::calculateTextItemPosition() {
|
||||
dans priv_modifieConducer.
|
||||
*/
|
||||
void Conducer::saveProfile() {
|
||||
ConducerProfile old_profile = conducer_profile;
|
||||
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) {
|
||||
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 &);
|
||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||
const QList<ConducerSegment *> segmentsList() const;
|
||||
void setProfile(const ConducerProfile &);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||
|
@ -14,11 +14,40 @@ ConducerProfile::ConducerProfile(Conducer *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
|
||||
ConducerProfile::~ConducerProfile() {
|
||||
foreach(ConducerSegmentProfile * s, segments) {
|
||||
delete s;
|
||||
}
|
||||
setNull();
|
||||
}
|
||||
|
||||
/// @return true si le profil est nul
|
||||
@ -26,6 +55,12 @@ bool ConducerProfile::isNull() const {
|
||||
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
|
||||
qreal ConducerProfile::width() const {
|
||||
qreal width = 0.0;
|
||||
@ -78,8 +113,7 @@ QList<ConducerSegmentProfile *> ConducerProfile::verticalSegments() {
|
||||
|
||||
void ConducerProfile::fromConducer(Conducer *conducer) {
|
||||
// supprime les segments precedents
|
||||
foreach(ConducerSegmentProfile *csp, segments) delete csp;
|
||||
segments.clear();
|
||||
setNull();
|
||||
|
||||
foreach(ConducerSegment *conducer_segment, conducer -> segmentsList()) {
|
||||
segments << new ConducerSegmentProfile(conducer_segment);
|
||||
|
@ -13,6 +13,8 @@ class ConducerProfile {
|
||||
// constructeurs, destructeur
|
||||
ConducerProfile();
|
||||
ConducerProfile(Conducer *conducer);
|
||||
ConducerProfile(const ConducerProfile &);
|
||||
ConducerProfile &operator=(const ConducerProfile &);
|
||||
virtual ~ConducerProfile();
|
||||
|
||||
// attributs
|
||||
@ -24,6 +26,7 @@ class ConducerProfile {
|
||||
// methodes
|
||||
public:
|
||||
bool isNull() const;
|
||||
void setNull();
|
||||
qreal width() const;
|
||||
qreal height() const;
|
||||
uint nbSegments(QET::ConducerSegmentType) const;
|
||||
|
@ -244,16 +244,10 @@ MoveElementsCommand::MoveElementsCommand(
|
||||
movement(m)
|
||||
{
|
||||
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
|
||||
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
|
||||
@ -357,3 +351,39 @@ void RotateElementsCommand::redo() {
|
||||
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 "diagram.h"
|
||||
#include "diagramtextitem.h"
|
||||
#include "conducer.h"
|
||||
#include <QtGui>
|
||||
/**
|
||||
Cette classe represente l'action d'ajouter un element au schema
|
||||
@ -182,7 +183,6 @@ class ChangeDiagramTextCommand : public QUndoCommand {
|
||||
QString text_after;
|
||||
/// booleen pour ne pas executer le premier redo()
|
||||
bool first_redo;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -206,4 +206,32 @@ class RotateElementsCommand : public QUndoCommand {
|
||||
/// texte avant changement
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user