diff --git a/conducer.cpp b/conducer.cpp index 5531f9258..4acffba28 100644 --- a/conducer.cpp +++ b/conducer.cpp @@ -91,7 +91,7 @@ void Conducer::update(const QRectF &rect) { a pour position pos @param rect Rectangle a mettre a jour @param b Borne - @param pos position de la borne b + @param newpos position de la borne b */ void Conducer::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPointF &newpos) { QPointF p1, p2; diff --git a/customelement.cpp b/customelement.cpp index db0f99717..ad8233e55 100644 --- a/customelement.cpp +++ b/customelement.cpp @@ -23,7 +23,6 @@ */ CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram *s, int *etat) : FixedElement(qgi, s) { nomfichier = nom_fichier; - nb_terminals = 0; // pessimisme inside : par defaut, ca foire elmt_etat = -1; @@ -108,7 +107,7 @@ CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram * for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) { QDomElement qde = n.toElement(); if (qde.isNull()) continue; - if (parseElement(qde, qp, s)) ++ nb_elements_parses; + if (parseElement(qde, qp)) ++ nb_elements_parses; else { if (etat != NULL) *etat = 7; elmt_etat = 7; @@ -141,11 +140,21 @@ CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram * CustomElement::~CustomElement() { } +QList CustomElement::terminals() const { + return(list_terminals); +} + +QList CustomElement::conducers() const { + QList conducers; + foreach(Terminal *t, list_terminals) conducers << t -> conducers(); + return(conducers); +} + /** @return Le nombre de bornes que l'element possede */ int CustomElement::nbTerminals() const { - return(nb_terminals); + return(list_terminals.size()); } /** @@ -170,15 +179,15 @@ void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *) { @param s Le schema sur lequel sera affiche l'element perso @return true si l'analyse reussit, false sinon */ -bool CustomElement::parseElement(QDomElement &e, QPainter &qp, Diagram *s) { - if (e.tagName() == "terminal") return(parseTerminal(e, s)); +bool CustomElement::parseElement(QDomElement &e, QPainter &qp) { + if (e.tagName() == "terminal") return(parseTerminal(e)); else if (e.tagName() == "line") return(parseLine(e, qp)); else if (e.tagName() == "ellipse") return(parseEllipse(e, qp)); else if (e.tagName() == "circle") return(parseCircle(e, qp)); else if (e.tagName() == "arc") return(parseArc(e, qp)); else if (e.tagName() == "polygon") return(parsePolygon(e, qp)); else if (e.tagName() == "text") return(parseText(e, qp)); - else if (e.tagName() == "input") return(parseInput(e, s)); + else if (e.tagName() == "input") return(parseInput(e)); else return(true); // on n'est pas chiant, on ignore l'element inconnu } @@ -372,7 +381,7 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) { @param s Le schema sur lequel l'element perso sera affiche @return true si l'analyse reussit, false sinon */ -bool CustomElement::parseInput(QDomElement &e, Diagram *s) { +bool CustomElement::parseInput(QDomElement &e) { qreal pos_x, pos_y; int size; if ( @@ -381,7 +390,7 @@ bool CustomElement::parseInput(QDomElement &e, Diagram *s) { !QET::attributeIsAnInteger(e, "size", &size) ) return(false); - ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this, s); + ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this); eti -> setFont(QFont("Sans Serif", size)); eti -> setPos(pos_x, pos_y); if (e.attribute("rotate") == "true") eti -> setFollowParentRotations(true); @@ -399,7 +408,7 @@ bool CustomElement::parseInput(QDomElement &e, Diagram *s) { @param s Le schema sur lequel l'element perso sera affiche @return true si l'analyse reussit, false sinon */ -bool CustomElement::parseTerminal(QDomElement &e, Diagram *s) { +bool CustomElement::parseTerminal(QDomElement &e) { // verifie la presence et la validite des attributs obligatoires double terminalx, terminaly; QET::Orientation terminalo; @@ -411,8 +420,7 @@ bool CustomElement::parseTerminal(QDomElement &e, Diagram *s) { else if (e.attribute("orientation") == "e") terminalo = QET::East; else if (e.attribute("orientation") == "w") terminalo = QET::West; else return(false); - new Terminal(terminalx, terminaly, terminalo, this, s); - ++ nb_terminals; + list_terminals << new Terminal(terminalx, terminaly, terminalo, this); return(true); } diff --git a/customelement.h b/customelement.h index 789c7eed5..40f9f1fe1 100644 --- a/customelement.h +++ b/customelement.h @@ -29,10 +29,12 @@ class CustomElement : public FixedElement { NamesList names; QString nomfichier; QPicture dessin; - int nb_terminals; + QList list_terminals; // methodes public: + virtual QList terminals() const; + virtual QList conducers() const; virtual int nbTerminals() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); QString typeId() const; @@ -42,15 +44,15 @@ class CustomElement : public FixedElement { QString nom() const; private: - bool parseElement(QDomElement &, QPainter &, Diagram *); + bool parseElement(QDomElement &, QPainter &); bool parseLine(QDomElement &, QPainter &); bool parseEllipse(QDomElement &, QPainter &); bool parseCircle(QDomElement &, QPainter &); bool parseArc(QDomElement &, QPainter &); bool parsePolygon(QDomElement &, QPainter &); bool parseText(QDomElement &, QPainter &); - bool parseInput(QDomElement &, Diagram *); - bool parseTerminal(QDomElement &, Diagram *); + bool parseInput(QDomElement &); + bool parseTerminal(QDomElement &); void setQPainterAntiAliasing(QPainter &, bool); bool validOrientationAttribute(QDomElement &); void setPainterStyle(QDomElement &, QPainter &); diff --git a/diagram.cpp b/diagram.cpp index b00d04a0b..1eae21c28 100644 --- a/diagram.cpp +++ b/diagram.cpp @@ -20,7 +20,7 @@ Diagram::Diagram(QObject *parent) : QGraphicsScene(parent) { conducer_setter -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0))); draw_grid = true; use_border = true; - connect(this, SIGNAL(changed(const QList &)), this, SLOT(slot_checkSelectionEmptinessChange())); + connect(this, SIGNAL(selectionChanged()), this, SLOT(slot_checkSelectionEmptinessChange())); } /** @@ -351,17 +351,6 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in return(true); } -/** - Verifie si la liste des elements selectionnes a change. Si oui, le signal - selectionChanged() est emis. -*/ -void Diagram::slot_checkSelectionChange() { - static QList cache_selecteditems = QList(); - QList selecteditems = selectedItems(); - if (cache_selecteditems != selecteditems) emit(selectionChanged()); - cache_selecteditems = selecteditems; -} - /** 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 @@ -389,3 +378,4 @@ QRectF Diagram::border() const { ) ); } + diff --git a/diagram.h b/diagram.h index 2dac8eb1f..fbd57e77b 100644 --- a/diagram.h +++ b/diagram.h @@ -56,11 +56,9 @@ class Diagram : public QGraphicsScene { QSize imageSize() const; private slots: - void slot_checkSelectionChange(); void slot_checkSelectionEmptinessChange(); signals: - void selectionChanged(); void selectionEmptinessChanged(); }; diff --git a/element.cpp b/element.cpp index a03ed8133..ed13bd4dc 100644 --- a/element.cpp +++ b/element.cpp @@ -110,7 +110,7 @@ QPixmap Element::pixmap() { @return la valeur du changement d'etat */ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemPositionChange) { + if (change == QGraphicsItem::ItemPositionHasChanged) { foreach(QGraphicsItem *qgi, children()) { if (Terminal *p = qgraphicsitem_cast(qgi)) p -> updateConducer(value.toPointF()); } diff --git a/element.h b/element.h index 5a7f0a87a..ff225866a 100644 --- a/element.h +++ b/element.h @@ -35,6 +35,8 @@ class Element : public QGraphicsItem { virtual int type() const { return Type; } // methodes virtuelles pures a definir dans les classes enfants + virtual QList terminals() const = 0; + virtual QList conducers() const = 0; virtual int nbTerminals() const = 0; virtual int nbTerminalsMin() const = 0; virtual int nbTerminalsMax() const = 0;