mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Les editions de champs (conducteurs et elements) sont desormais annulables
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@138 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
5150cb38ad
commit
bc650ea347
@ -52,9 +52,9 @@ Conducer::Conducer(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *
|
|||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
|
|
||||||
// ajout du champ de texte editable
|
// ajout du champ de texte editable
|
||||||
text_item = new QGraphicsTextItem();
|
text_item = new DiagramTextItem();
|
||||||
text_item -> setPlainText("_");
|
text_item -> setPlainText("_");
|
||||||
text_item -> setTextInteractionFlags(Qt::TextEditorInteraction);
|
text_item -> previous_text = "_";
|
||||||
calculateTextItemPosition();
|
calculateTextItemPosition();
|
||||||
text_item -> setParentItem(this);
|
text_item -> setParentItem(this);
|
||||||
}
|
}
|
||||||
@ -781,6 +781,7 @@ bool Conducer::hasClickedOn(QPointF press_point, QPointF point) const {
|
|||||||
*/
|
*/
|
||||||
bool Conducer::fromXml(QDomElement &e) {
|
bool Conducer::fromXml(QDomElement &e) {
|
||||||
text_item -> setPlainText(e.attribute("num"));
|
text_item -> setPlainText(e.attribute("num"));
|
||||||
|
text_item -> previous_text = e.attribute("num");
|
||||||
|
|
||||||
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
||||||
// les segments non valides sont ignores
|
// les segments non valides sont ignores
|
||||||
|
11
conducer.h
11
conducer.h
@ -3,6 +3,7 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "conducerprofile.h"
|
#include "conducerprofile.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
class ConducerSegment;
|
class ConducerSegment;
|
||||||
class Element;
|
class Element;
|
||||||
/**
|
/**
|
||||||
@ -30,7 +31,7 @@ class Conducer : public QGraphicsPathItem {
|
|||||||
private:
|
private:
|
||||||
/// booleen indiquant si le fil est encore valide
|
/// booleen indiquant si le fil est encore valide
|
||||||
bool destroyed;
|
bool destroyed;
|
||||||
QGraphicsTextItem *text_item;
|
DiagramTextItem *text_item;
|
||||||
ConducerSegment *segments;
|
ConducerSegment *segments;
|
||||||
QPointF press_point;
|
QPointF press_point;
|
||||||
bool moving_point;
|
bool moving_point;
|
||||||
@ -64,10 +65,10 @@ class Conducer : public QGraphicsPathItem {
|
|||||||
const QList<ConducerSegment *> segmentsList() const;
|
const QList<ConducerSegment *> segmentsList() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void segmentsToPath();
|
void segmentsToPath();
|
||||||
|
@ -221,7 +221,12 @@ CutDiagramCommand::~CutDiagramCommand() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param
|
@param dia Schema sur lequel on deplace des elements
|
||||||
|
@param move_elements Elements a deplacer
|
||||||
|
@param move_conducers Conducteurs a deplacer
|
||||||
|
@param modify_conducers Conducteurs a mettre a jour
|
||||||
|
@param m translation subie par les elements
|
||||||
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
MoveElementsCommand::MoveElementsCommand(
|
MoveElementsCommand::MoveElementsCommand(
|
||||||
Diagram *dia,
|
Diagram *dia,
|
||||||
@ -262,7 +267,10 @@ void MoveElementsCommand::redo() {
|
|||||||
else move(movement);
|
else move(movement);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
/**
|
||||||
|
deplace les elements et conducteurs
|
||||||
|
@param actual_movement translation a effectuer sur les elements et conducteurs
|
||||||
|
*/
|
||||||
void MoveElementsCommand::move(const QPointF &actual_movement) {
|
void MoveElementsCommand::move(const QPointF &actual_movement) {
|
||||||
// deplace les elements
|
// deplace les elements
|
||||||
foreach(Element *element, elements_to_move) {
|
foreach(Element *element, elements_to_move) {
|
||||||
@ -279,3 +287,43 @@ void MoveElementsCommand::move(const QPointF &actual_movement) {
|
|||||||
conducer -> updateWithNewPos(QRectF(), conducers_to_update[conducer], conducers_to_update[conducer] -> amarrageConducer());
|
conducer -> updateWithNewPos(QRectF(), conducers_to_update[conducer], conducers_to_update[conducer] -> amarrageConducer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dti Champ de texte modifie
|
||||||
|
@param before texte avant
|
||||||
|
@param after texte apres
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
ChangeDiagramTextCommand::ChangeDiagramTextCommand(
|
||||||
|
DiagramTextItem *dti,
|
||||||
|
const QString &before,
|
||||||
|
const QString &after,
|
||||||
|
QUndoCommand *parent
|
||||||
|
) :
|
||||||
|
QUndoCommand(QObject::tr("modifier le texte"), parent),
|
||||||
|
text_item(dti),
|
||||||
|
text_before(before),
|
||||||
|
text_after(after),
|
||||||
|
first_redo(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// destructeur
|
||||||
|
ChangeDiagramTextCommand::~ChangeDiagramTextCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// annule la modification de texte
|
||||||
|
void ChangeDiagramTextCommand::undo() {
|
||||||
|
text_item -> setPlainText(text_before);
|
||||||
|
text_item -> previous_text = text_before;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// refait la modification de texte
|
||||||
|
void ChangeDiagramTextCommand::redo() {
|
||||||
|
if (first_redo) first_redo = false;
|
||||||
|
else {
|
||||||
|
text_item -> setPlainText(text_after);
|
||||||
|
text_item -> previous_text = text_after;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef DIAGRAM_COMMANDS_H
|
#ifndef DIAGRAM_COMMANDS_H
|
||||||
#define DIAGRAM_COMMANDS_H
|
#define DIAGRAM_COMMANDS_H
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "diagramtextitem.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
|
||||||
@ -153,4 +154,33 @@ class MoveElementsCommand : public QUndoCommand {
|
|||||||
/// booleen pour ne pas executer le premier redo()
|
/// booleen pour ne pas executer le premier redo()
|
||||||
bool first_redo;
|
bool first_redo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cette classe represente la modification d'un champ de texte
|
||||||
|
*/
|
||||||
|
class ChangeDiagramTextCommand : public QUndoCommand {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
ChangeDiagramTextCommand(DiagramTextItem *, const QString &before, const QString &after, QUndoCommand * = 0);
|
||||||
|
virtual ~ChangeDiagramTextCommand();
|
||||||
|
private:
|
||||||
|
ChangeDiagramTextCommand(const ChangeDiagramTextCommand &);
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public:
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
/// DiagramTextItem modifie
|
||||||
|
DiagramTextItem *text_item;
|
||||||
|
/// texte avant changement
|
||||||
|
QString text_before;
|
||||||
|
/// texte apres changement
|
||||||
|
QString text_after;
|
||||||
|
/// booleen pour ne pas executer le premier redo()
|
||||||
|
bool first_redo;
|
||||||
|
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
49
diagramtextitem.cpp
Normal file
49
diagramtextitem.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "diagramtextitem.h"
|
||||||
|
#include "diagramcommands.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param parent Le QGraphicsItem parent du champ de texte
|
||||||
|
@param scene La scene a laquelle appartient le champ de texte
|
||||||
|
*/
|
||||||
|
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
|
QGraphicsTextItem(parent, scene)
|
||||||
|
{
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param parent Le QGraphicsItem parent du champ de texte
|
||||||
|
@param scene La scene a laquelle appartient le champ de texte
|
||||||
|
@param text Le texte affiche par le champ de texte
|
||||||
|
*/
|
||||||
|
DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
|
QGraphicsTextItem(text, parent, scene),
|
||||||
|
previous_text(text)
|
||||||
|
{
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
DiagramTextItem::~DiagramTextItem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @return le Diagram auquel ce texte appartient, ou 0 si ce texte est independant
|
||||||
|
Diagram *DiagramTextItem::diagram() const {
|
||||||
|
return(qobject_cast<Diagram *>(scene()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
gere la perte de focus du champ de texte
|
||||||
|
*/
|
||||||
|
void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
||||||
|
QGraphicsTextItem::focusOutEvent(e);
|
||||||
|
// si le texte a ete modifie
|
||||||
|
if (toPlainText() != previous_text) {
|
||||||
|
if (Diagram *dia = diagram()) {
|
||||||
|
dia -> undoStack().push(new ChangeDiagramTextCommand(this, previous_text, toPlainText()));
|
||||||
|
previous_text = toPlainText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
diagramtextitem.h
Normal file
25
diagramtextitem.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef DIAGRAM_TEXT_ITEM_H
|
||||||
|
#define DIAGRAM_TEXT_ITEM_H
|
||||||
|
#include <QtGui>
|
||||||
|
#include "diagram.h"
|
||||||
|
class DiagramTextItem : public QGraphicsTextItem {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
DiagramTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
|
DiagramTextItem(const QString &, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
|
virtual ~DiagramTextItem();
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 1004 };
|
||||||
|
QString previous_text;
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public:
|
||||||
|
virtual int type() const { return Type; }
|
||||||
|
Diagram *diagram() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void focusOutEvent(QFocusEvent *);
|
||||||
|
};
|
||||||
|
#endif
|
@ -1,14 +1,16 @@
|
|||||||
#include "elementtextitem.h"
|
#include "elementtextitem.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "diagramcommands.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param parent Le QGraphicsItem parent du champ de texte
|
@param parent Le QGraphicsItem parent du champ de texte
|
||||||
@param scene La scene a laquelle appartient le champ de texte
|
@param scene La scene a laquelle appartient le champ de texte
|
||||||
*/
|
*/
|
||||||
ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(parent, scene) {
|
ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
follow_parent_rotations = false;
|
DiagramTextItem(parent, scene),
|
||||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
follow_parent_rotations(false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,11 +19,13 @@ ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
|||||||
@param scene La scene a laquelle appartient le champ de texte
|
@param scene La scene a laquelle appartient le champ de texte
|
||||||
@param text Le texte affiche par le champ de texte
|
@param text Le texte affiche par le champ de texte
|
||||||
*/
|
*/
|
||||||
ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(text, parent, scene) {
|
ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
follow_parent_rotations = false;
|
DiagramTextItem(text, parent, scene),
|
||||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
follow_parent_rotations(false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
ElementTextItem::~ElementTextItem() {
|
ElementTextItem::~ElementTextItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ ElementTextItem::~ElementTextItem() {
|
|||||||
void ElementTextItem::setPos(const QPointF &pos) {
|
void ElementTextItem::setPos(const QPointF &pos) {
|
||||||
QPointF actual_pos = pos;
|
QPointF actual_pos = pos;
|
||||||
actual_pos -= QPointF(0.0, boundingRect().height() / 2.0);
|
actual_pos -= QPointF(0.0, boundingRect().height() / 2.0);
|
||||||
QGraphicsItem::setPos(actual_pos);
|
DiagramTextItem::setPos(actual_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,7 +52,7 @@ void ElementTextItem::setPos(qreal x, qreal y) {
|
|||||||
@return La position (bidouillee) du champ de texte
|
@return La position (bidouillee) du champ de texte
|
||||||
*/
|
*/
|
||||||
QPointF ElementTextItem::pos() const {
|
QPointF ElementTextItem::pos() const {
|
||||||
QPointF actual_pos = QGraphicsTextItem::pos();
|
QPointF actual_pos = DiagramTextItem::pos();
|
||||||
actual_pos += QPointF(0.0, boundingRect().height() / 2.0);
|
actual_pos += QPointF(0.0, boundingRect().height() / 2.0);
|
||||||
return(actual_pos);
|
return(actual_pos);
|
||||||
}
|
}
|
||||||
@ -63,6 +67,7 @@ void ElementTextItem::fromXml(const QDomElement &e) {
|
|||||||
QPointF _pos = pos();
|
QPointF _pos = pos();
|
||||||
if (e.attribute("x").toDouble() == _pos.x() && e.attribute("y").toDouble() == _pos.y()) {
|
if (e.attribute("x").toDouble() == _pos.x() && e.attribute("y").toDouble() == _pos.y()) {
|
||||||
setPlainText(e.attribute("text"));
|
setPlainText(e.attribute("text"));
|
||||||
|
previous_text = e.attribute("text");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +82,3 @@ QDomElement ElementTextItem::toXml(QDomDocument &document) const {
|
|||||||
result.setAttribute("text", toPlainText());
|
result.setAttribute("text", toPlainText());
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return le Diagram auquel ce texte appartient, ou 0 si ce texte est independant
|
|
||||||
Diagram *ElementTextItem::diagram() const {
|
|
||||||
return(qobject_cast<Diagram *>(scene()));
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef ELEMENT_TEXT_ITEM_H
|
#ifndef ELEMENT_TEXT_ITEM_H
|
||||||
#define ELEMENT_TEXT_ITEM_H
|
#define ELEMENT_TEXT_ITEM_H
|
||||||
#include <QGraphicsTextItem>
|
#include "diagramtextitem.h"
|
||||||
#include <QtXml>
|
#include <QtXml>
|
||||||
class Diagram;
|
class Diagram;
|
||||||
/**
|
/**
|
||||||
@ -8,7 +8,7 @@ class Diagram;
|
|||||||
Il est possible pour ce champ de texte de rester dans le sens de la lecture
|
Il est possible pour ce champ de texte de rester dans le sens de la lecture
|
||||||
malgre les rotations de son element parent.
|
malgre les rotations de son element parent.
|
||||||
*/
|
*/
|
||||||
class ElementTextItem : public QGraphicsTextItem {
|
class ElementTextItem : public DiagramTextItem {
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
@ -32,7 +32,6 @@ class ElementTextItem : public QGraphicsTextItem {
|
|||||||
void setPos(const QPointF &);
|
void setPos(const QPointF &);
|
||||||
void setPos(qreal, qreal);
|
void setPos(qreal, qreal);
|
||||||
QPointF pos() const;
|
QPointF pos() const;
|
||||||
Diagram *diagram() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +64,9 @@ HEADERS += aboutqet.h \
|
|||||||
editor/terminaleditor.h \
|
editor/terminaleditor.h \
|
||||||
editor/texteditor.h \
|
editor/texteditor.h \
|
||||||
editor/textfieldeditor.h \
|
editor/textfieldeditor.h \
|
||||||
diagramcommands.h
|
diagramcommands.h \
|
||||||
|
diagramitem.h \
|
||||||
|
diagramtextitem.h
|
||||||
SOURCES += aboutqet.cpp \
|
SOURCES += aboutqet.cpp \
|
||||||
borderinset.cpp \
|
borderinset.cpp \
|
||||||
conducer.cpp \
|
conducer.cpp \
|
||||||
@ -121,7 +123,8 @@ SOURCES += aboutqet.cpp \
|
|||||||
editor/terminaleditor.cpp \
|
editor/terminaleditor.cpp \
|
||||||
editor/texteditor.cpp \
|
editor/texteditor.cpp \
|
||||||
editor/textfieldeditor.cpp \
|
editor/textfieldeditor.cpp \
|
||||||
diagramcommands.cpp
|
diagramcommands.cpp \
|
||||||
|
diagramtextitem.cpp
|
||||||
RESOURCES += qelectrotech.qrc
|
RESOURCES += qelectrotech.qrc
|
||||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||||
RC_FILE = ico/windows_icon/application_icon/qelectrotech.rc
|
RC_FILE = ico/windows_icon/application_icon/qelectrotech.rc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user