mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Support (basique) des numeros sur les conducteurs
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@75 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
52
conducer.cpp
52
conducer.cpp
@@ -42,6 +42,12 @@ Conducer::Conducer(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *
|
|||||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsSelectable);
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
previous_z_value = zValue();
|
previous_z_value = zValue();
|
||||||
|
|
||||||
|
// ajout du champ de texte editable
|
||||||
|
text_item = new QGraphicsTextItem(this, scene);
|
||||||
|
text_item -> setPlainText("_");
|
||||||
|
text_item -> setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
calculateTextItemPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +64,7 @@ void Conducer::update(const QRectF &rect) {
|
|||||||
terminal1 -> amarrageConducer(), terminal1 -> orientation(),
|
terminal1 -> amarrageConducer(), terminal1 -> orientation(),
|
||||||
terminal2 -> amarrageConducer(), terminal2 -> orientation()
|
terminal2 -> amarrageConducer(), terminal2 -> orientation()
|
||||||
);
|
);
|
||||||
|
calculateTextItemPosition();
|
||||||
QGraphicsPathItem::update(rect);
|
QGraphicsPathItem::update(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +91,7 @@ void Conducer::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPo
|
|||||||
priv_modifieConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
priv_modifieConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||||
else
|
else
|
||||||
priv_calculeConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
priv_calculeConducer(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||||
|
calculateTextItemPosition();
|
||||||
QGraphicsPathItem::update(rect);
|
QGraphicsPathItem::update(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,6 +488,7 @@ void Conducer::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
modified_path = true;
|
modified_path = true;
|
||||||
updatePoints();
|
updatePoints();
|
||||||
segmentsToPath();
|
segmentsToPath();
|
||||||
|
calculateTextItemPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QGraphicsPathItem::mouseMoveEvent(e);
|
QGraphicsPathItem::mouseMoveEvent(e);
|
||||||
@@ -495,6 +504,7 @@ void Conducer::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
moving_segment = false;
|
moving_segment = false;
|
||||||
setZValue(previous_z_value);
|
setZValue(previous_z_value);
|
||||||
QGraphicsPathItem::mouseReleaseEvent(e);
|
QGraphicsPathItem::mouseReleaseEvent(e);
|
||||||
|
calculateTextItemPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Conducer::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
void Conducer::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
||||||
@@ -671,6 +681,8 @@ bool Conducer::hasClickedOn(QPointF press_point, QPointF point) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Conducer::fromXml(QDomElement &e) {
|
bool Conducer::fromXml(QDomElement &e) {
|
||||||
|
text_item -> setPlainText(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
|
||||||
QList<qreal> segments_x, segments_y;
|
QList<qreal> segments_x, segments_y;
|
||||||
@@ -743,6 +755,7 @@ QDomElement Conducer::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_i
|
|||||||
QDomElement e = d.createElement("conducteur");
|
QDomElement e = d.createElement("conducteur");
|
||||||
e.setAttribute("borne1", table_adr_id.value(terminal1));
|
e.setAttribute("borne1", table_adr_id.value(terminal1));
|
||||||
e.setAttribute("borne2", table_adr_id.value(terminal2));
|
e.setAttribute("borne2", table_adr_id.value(terminal2));
|
||||||
|
e.setAttribute("num", text_item -> toPlainText());
|
||||||
|
|
||||||
// on n'exporte les segments du conducteur que si ceux-ci ont
|
// on n'exporte les segments du conducteur que si ceux-ci ont
|
||||||
// ete modifies par l'utilisateur
|
// ete modifies par l'utilisateur
|
||||||
@@ -764,3 +777,42 @@ QDomElement Conducer::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_i
|
|||||||
e.appendChild(current_segment);
|
e.appendChild(current_segment);
|
||||||
return(e);
|
return(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return La longueur totale du conducteur
|
||||||
|
*/
|
||||||
|
qreal Conducer::length() {
|
||||||
|
qreal length = 0.0;
|
||||||
|
|
||||||
|
ConducerSegment *s = segments;
|
||||||
|
while (s -> hasNextSegment()) {
|
||||||
|
length += qAbs(s -> length());
|
||||||
|
s = s -> nextSegment();
|
||||||
|
}
|
||||||
|
|
||||||
|
return(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return Le segment qui contient le point au milieu du conducteur
|
||||||
|
*/
|
||||||
|
ConducerSegment *Conducer::middleSegment() {
|
||||||
|
if (segments == NULL) return(NULL);
|
||||||
|
|
||||||
|
qreal half_length = length() / 2.0;
|
||||||
|
|
||||||
|
ConducerSegment *s = segments;
|
||||||
|
qreal l = 0;
|
||||||
|
|
||||||
|
while (s -> hasNextSegment()) {
|
||||||
|
l += qAbs(s -> length());
|
||||||
|
if (l >= half_length) break;
|
||||||
|
s = s -> nextSegment();
|
||||||
|
}
|
||||||
|
// s est le segment qui contient le point au milieu du conducteur
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Conducer::calculateTextItemPosition() {
|
||||||
|
text_item -> setPos(middleSegment() -> middle());
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
virtual QPainterPath shape() const;
|
virtual QPainterPath shape() const;
|
||||||
|
qreal length();
|
||||||
|
ConducerSegment *middleSegment();
|
||||||
static bool valideXml(QDomElement &);
|
static bool valideXml(QDomElement &);
|
||||||
bool fromXml(QDomElement &);
|
bool fromXml(QDomElement &);
|
||||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||||
@@ -39,6 +41,7 @@
|
|||||||
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;
|
||||||
ConducerSegment *segments;
|
ConducerSegment *segments;
|
||||||
QList<qreal> moves_x;
|
QList<qreal> moves_x;
|
||||||
QList<qreal> moves_y;
|
QList<qreal> moves_y;
|
||||||
@@ -65,6 +68,7 @@
|
|||||||
QList<QPointF> segmentsToPoints() const;
|
QList<QPointF> segmentsToPoints() const;
|
||||||
void pointsToSegments(QList<QPointF>);
|
void pointsToSegments(QList<QPointF>);
|
||||||
bool hasClickedOn(QPointF, QPointF);
|
bool hasClickedOn(QPointF, QPointF);
|
||||||
|
void calculateTextItemPosition();
|
||||||
static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0);
|
static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0);
|
||||||
static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation);
|
static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation);
|
||||||
static bool estHorizontale(Terminal::Orientation a);
|
static bool estHorizontale(Terminal::Orientation a);
|
||||||
|
|||||||
Reference in New Issue
Block a user