mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Les classes Conductor et Element heritent desormais de QObject.
Correction du bug #16 : Mauvaise gestion des modifications du texte d'un conducteur git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@346 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
9c6f602439
commit
f4b828a3cd
@ -37,6 +37,7 @@ QBrush Conductor::square_brush = QBrush(Qt::darkGreen);
|
|||||||
@param scene QGraphicsScene a laquelle appartient le conducteur
|
@param scene QGraphicsScene a laquelle appartient le conducteur
|
||||||
*/
|
*/
|
||||||
Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) :
|
Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) :
|
||||||
|
QObject(),
|
||||||
QGraphicsPathItem(parent, scene),
|
QGraphicsPathItem(parent, scene),
|
||||||
terminal1(p1),
|
terminal1(p1),
|
||||||
terminal2(p2),
|
terminal2(p2),
|
||||||
@ -86,6 +87,12 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene
|
|||||||
text_item -> previous_text = properties_.text;
|
text_item -> previous_text = properties_.text;
|
||||||
calculateTextItemPosition();
|
calculateTextItemPosition();
|
||||||
text_item -> setParentItem(this);
|
text_item -> setParentItem(this);
|
||||||
|
connect(
|
||||||
|
text_item,
|
||||||
|
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||||
|
this,
|
||||||
|
SLOT(displayedTextChanged())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1083,6 +1090,25 @@ void Conductor::readProperties() {
|
|||||||
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Met a jour les proprietes du conducteur apres modification du champ de texte affiche
|
||||||
|
*/
|
||||||
|
void Conductor::displayedTextChanged() {
|
||||||
|
// verifie que le texte a reellement change
|
||||||
|
if (text_item -> toPlainText() == properties_.text) return;
|
||||||
|
|
||||||
|
// initialise l'objet UndoCommand correspondant
|
||||||
|
if (Diagram *my_diagram = diagram()) {
|
||||||
|
ConductorProperties new_properties(properties_);
|
||||||
|
new_properties.text = text_item -> toPlainText();
|
||||||
|
|
||||||
|
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(this);
|
||||||
|
ccpc -> setOldSettings(properties_);
|
||||||
|
ccpc -> setNewSettings(new_properties);
|
||||||
|
my_diagram -> undoStack().push(ccpc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return les conducteurs avec lesquels ce conducteur partage des bornes
|
@return les conducteurs avec lesquels ce conducteur partage des bornes
|
||||||
communes
|
communes
|
||||||
|
@ -29,7 +29,9 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
|||||||
/**
|
/**
|
||||||
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
||||||
*/
|
*/
|
||||||
class Conductor : public QGraphicsPathItem {
|
class Conductor : public QObject, public QGraphicsPathItem {
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
@ -81,6 +83,9 @@ class Conductor : public QGraphicsPathItem {
|
|||||||
ConductorProfilesGroup profiles() const;
|
ConductorProfilesGroup profiles() const;
|
||||||
void readProperties();
|
void readProperties();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void displayedTextChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
11
diagram.cpp
11
diagram.cpp
@ -461,6 +461,17 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere le fait qu'un texte du schema ait ete modifie
|
||||||
|
@param text_item Texte modifie
|
||||||
|
@param old_text Ancien texte
|
||||||
|
@param new_text Nouveau texte
|
||||||
|
*/
|
||||||
|
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
|
||||||
|
if (!text_item) return;
|
||||||
|
undo_stack.push(new ChangeDiagramTextCommand(text_item, old_text, new_text));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Verifie si la selection est passe d'un etat ou elle est vide a un etat ou
|
Verifie si la selection est passe d'un etat ou elle est vide a un etat ou
|
||||||
elle ne l'est pas, et inversement. Si c'est le cas, le signal
|
elle ne l'est pas, et inversement. Si c'est le cas, le signal
|
||||||
|
@ -126,6 +126,9 @@ class Diagram : public QGraphicsScene {
|
|||||||
QUndoStack &undoStack();
|
QUndoStack &undoStack();
|
||||||
QGIManager &qgiManager();
|
QGIManager &qgiManager();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slot_checkSelectionEmptinessChange();
|
void slot_checkSelectionEmptinessChange();
|
||||||
|
|
||||||
|
@ -81,11 +81,23 @@ AddTextCommand::~AddTextCommand() {
|
|||||||
|
|
||||||
/// Annule l'ajout
|
/// Annule l'ajout
|
||||||
void AddTextCommand::undo() {
|
void AddTextCommand::undo() {
|
||||||
|
QObject::disconnect(
|
||||||
|
textitem,
|
||||||
|
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||||
|
diagram,
|
||||||
|
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||||
|
);
|
||||||
diagram -> removeItem(textitem);
|
diagram -> removeItem(textitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refait l'ajour
|
/// Refait l'ajour
|
||||||
void AddTextCommand::redo() {
|
void AddTextCommand::redo() {
|
||||||
|
QObject::connect(
|
||||||
|
textitem,
|
||||||
|
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
||||||
|
diagram,
|
||||||
|
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
||||||
|
);
|
||||||
diagram -> addItem(textitem);
|
diagram -> addItem(textitem);
|
||||||
textitem -> setPos(position);
|
textitem -> setPos(position);
|
||||||
}
|
}
|
||||||
|
@ -121,10 +121,13 @@ QString DiagramContent::sentence(int filter) const {
|
|||||||
*/
|
*/
|
||||||
QDebug &operator<<(QDebug d, DiagramContent &c) {
|
QDebug &operator<<(QDebug d, DiagramContent &c) {
|
||||||
d << "DiagramContent {" << "\n";
|
d << "DiagramContent {" << "\n";
|
||||||
|
/*
|
||||||
|
FIXME Le double-heritage QObject / QGraphicsItem a casse cet operateur
|
||||||
d << " elements :" << c.elements << "\n";
|
d << " elements :" << c.elements << "\n";
|
||||||
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
||||||
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
||||||
d << " otherConductors :" << c.otherConductors << "\n";
|
d << " otherConductors :" << c.otherConductors << "\n";
|
||||||
d << "}";
|
d << "}";
|
||||||
|
*/
|
||||||
return(d.space());
|
return(d.space());
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,11 @@ Diagram *DiagramTextItem::diagram() const {
|
|||||||
*/
|
*/
|
||||||
void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
||||||
QGraphicsTextItem::focusOutEvent(e);
|
QGraphicsTextItem::focusOutEvent(e);
|
||||||
// si le texte a ete modifie
|
// signale la modification du texte si besoin
|
||||||
if (toPlainText() != previous_text) {
|
if (toPlainText() != previous_text) {
|
||||||
if (Diagram *dia = diagram()) {
|
emit(diagramTextChanged(this, previous_text, toPlainText()));
|
||||||
dia -> undoStack().push(new ChangeDiagramTextCommand(this, previous_text, toPlainText()));
|
|
||||||
previous_text = toPlainText();
|
previous_text = toPlainText();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// deselectionne le texte
|
// deselectionne le texte
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
|
@ -59,6 +59,8 @@ class DiagramTextItem : public QGraphicsTextItem {
|
|||||||
signals:
|
signals:
|
||||||
/// signal emis lorsque le champ de texte perd le focus
|
/// signal emis lorsque le champ de texte perd le focus
|
||||||
void lostFocus();
|
void lostFocus();
|
||||||
|
/// signal emis lorsque le champ de texte a ete modifie
|
||||||
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -259,20 +259,17 @@ void DiagramView::pasteHere() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
gere les clics et plus particulierement le clic du milieu (= coller pour X11)
|
Gere les clics et plus particulierement :
|
||||||
|
* le clic du milieu (= coller pour X11)
|
||||||
|
* le clic pour ajouter un champ de texte independant
|
||||||
*/
|
*/
|
||||||
void DiagramView::mousePressEvent(QMouseEvent *e) {
|
void DiagramView::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e -> buttons() == Qt::MidButton) {
|
if (e -> buttons() == Qt::MidButton) {
|
||||||
paste(mapToScene(e -> pos()), QClipboard::Selection);
|
paste(mapToScene(e -> pos()), QClipboard::Selection);
|
||||||
} else {
|
} else {
|
||||||
if (is_adding_text && e -> buttons() == Qt::LeftButton) {
|
if (is_adding_text && e -> buttons() == Qt::LeftButton) {
|
||||||
DiagramTextItem *dti = new DiagramTextItem();
|
addDiagramTextAtPos(mapToScene(e -> pos()));
|
||||||
dti -> setPlainText("_");
|
|
||||||
dti -> previous_text = "_";
|
|
||||||
scene -> undoStack().push(new AddTextCommand(scene, dti, mapToScene(e -> pos())));
|
|
||||||
adjustSceneRect();
|
|
||||||
is_adding_text = false;
|
is_adding_text = false;
|
||||||
emit(textAdded(false));
|
|
||||||
}
|
}
|
||||||
QGraphicsView::mousePressEvent(e);
|
QGraphicsView::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
@ -859,6 +856,28 @@ void DiagramView::addText() {
|
|||||||
is_adding_text = true;
|
is_adding_text = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cree un nouveau champ de texte et le place a la position pos
|
||||||
|
en gerant l'annulation ; enfin, le signal textAdded est emis.
|
||||||
|
@param pos Position du champ de texte ajoute
|
||||||
|
@return le champ de texte ajoute
|
||||||
|
*/
|
||||||
|
DiagramTextItem *DiagramView::addDiagramTextAtPos(const QPointF &pos) {
|
||||||
|
// cree un nouveau champ de texte
|
||||||
|
DiagramTextItem *dti = new DiagramTextItem();
|
||||||
|
dti -> setPlainText("_");
|
||||||
|
dti -> previous_text = "_";
|
||||||
|
|
||||||
|
// le place a la position pos en gerant l'annulation
|
||||||
|
scene -> undoStack().push(new AddTextCommand(scene, dti, pos));
|
||||||
|
adjustSceneRect();
|
||||||
|
|
||||||
|
// emet le signal textAdded
|
||||||
|
emit(textAdded(false));
|
||||||
|
|
||||||
|
return(dti);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere le menu contextuel
|
Gere le menu contextuel
|
||||||
@param e Evenement decrivant la demande de menu contextuel
|
@param e Evenement decrivant la demande de menu contextuel
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define DIAGRAMVIEW_H
|
#define DIAGRAMVIEW_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
class Diagram;
|
class Diagram;
|
||||||
|
class DiagramTextItem;
|
||||||
class QETDiagramEditor;
|
class QETDiagramEditor;
|
||||||
class Conductor;
|
class Conductor;
|
||||||
/**
|
/**
|
||||||
@ -65,6 +66,7 @@ class DiagramView : public QGraphicsView {
|
|||||||
QETDiagramEditor *diagramEditor() const;
|
QETDiagramEditor *diagramEditor() const;
|
||||||
bool hasSelectedItems();
|
bool hasSelectedItems();
|
||||||
void addText();
|
void addText();
|
||||||
|
DiagramTextItem *addDiagramTextAtPos(const QPointF &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
||||||
|
11
element.cpp
11
element.cpp
@ -27,6 +27,7 @@
|
|||||||
Constructeur pour un element sans scene ni parent
|
Constructeur pour un element sans scene ni parent
|
||||||
*/
|
*/
|
||||||
Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
||||||
|
QObject(),
|
||||||
QGraphicsItem(parent, scene),
|
QGraphicsItem(parent, scene),
|
||||||
internal_connections(false)
|
internal_connections(false)
|
||||||
{
|
{
|
||||||
@ -155,7 +156,7 @@ bool Element::setOrientation(QET::Orientation o) {
|
|||||||
rotate(rotation_value);
|
rotate(rotation_value);
|
||||||
ori.setCurrent(o);
|
ori.setCurrent(o);
|
||||||
update();
|
update();
|
||||||
foreach(QGraphicsItem *qgi, children()) {
|
foreach(QGraphicsItem *qgi, childItems()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConductor();
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConductor();
|
||||||
else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
||||||
// applique une rotation contraire si besoin
|
// applique une rotation contraire si besoin
|
||||||
@ -354,7 +355,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
|||||||
|
|
||||||
QHash<int, Terminal *> priv_id_adr;
|
QHash<int, Terminal *> priv_id_adr;
|
||||||
int terminals_non_trouvees = 0;
|
int terminals_non_trouvees = 0;
|
||||||
foreach(QGraphicsItem *qgi, children()) {
|
foreach(QGraphicsItem *qgi, childItems()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
||||||
bool terminal_trouvee = false;
|
bool terminal_trouvee = false;
|
||||||
foreach(QDomElement qde, liste_terminals) {
|
foreach(QDomElement qde, liste_terminals) {
|
||||||
@ -386,7 +387,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
|||||||
|
|
||||||
// importe les valeurs des champs de texte
|
// importe les valeurs des champs de texte
|
||||||
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
||||||
foreach(QGraphicsItem *qgi, children()) {
|
foreach(QGraphicsItem *qgi, childItems()) {
|
||||||
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
||||||
foreach(QDomElement input, inputs) eti -> fromXml(input);
|
foreach(QDomElement input, inputs) eti -> fromXml(input);
|
||||||
}
|
}
|
||||||
@ -438,7 +439,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
// enregistrement des bornes de l'appareil
|
// enregistrement des bornes de l'appareil
|
||||||
QDomElement terminals = document.createElement("terminals");
|
QDomElement terminals = document.createElement("terminals");
|
||||||
// pour chaque enfant de l'element
|
// pour chaque enfant de l'element
|
||||||
foreach(QGraphicsItem *child, children()) {
|
foreach(QGraphicsItem *child, childItems()) {
|
||||||
// si cet enfant est une borne
|
// si cet enfant est une borne
|
||||||
if (Terminal *t = qgraphicsitem_cast<Terminal *>(child)) {
|
if (Terminal *t = qgraphicsitem_cast<Terminal *>(child)) {
|
||||||
// alors on enregistre la borne
|
// alors on enregistre la borne
|
||||||
@ -453,7 +454,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
// enregistrement des champ de texte de l'appareil
|
// enregistrement des champ de texte de l'appareil
|
||||||
QDomElement inputs = document.createElement("inputs");
|
QDomElement inputs = document.createElement("inputs");
|
||||||
// pour chaque enfant de l'element
|
// pour chaque enfant de l'element
|
||||||
foreach(QGraphicsItem *child, children()) {
|
foreach(QGraphicsItem *child, childItems()) {
|
||||||
// si cet enfant est un champ de texte
|
// si cet enfant est un champ de texte
|
||||||
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(child)) {
|
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(child)) {
|
||||||
// alors on enregistre le champ de texte
|
// alors on enregistre le champ de texte
|
||||||
|
@ -24,7 +24,9 @@ class Diagram;
|
|||||||
/**
|
/**
|
||||||
Cette classe abstraite represente un element electrique.
|
Cette classe abstraite represente un element electrique.
|
||||||
*/
|
*/
|
||||||
class Element : public QGraphicsItem {
|
class Element : public QObject, public QGraphicsItem {
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user