From 522e5337ee54dd95a48917da61ad7ece6ac648a5 Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 31 Jan 2023 23:13:05 +0100 Subject: [PATCH] Minor : improve first and last segment position of conducteur --- sources/qetgraphicsitem/conductor.cpp | 30 +++++++++++++++++---------- sources/qetgraphicsitem/conductor.h | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 16bbeffb3..4b93571b0 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -445,29 +445,37 @@ void Conductor::generateConductorPath(const QPointF &p1, Qet::Orientation o1, co } /** - Prolonge une borne. - @param terminal Le point correspondant a la borne - @param terminal_orientation L'orientation de la borne - @param ext_size la taille de la prolongation - @return le point correspondant a la borne apres prolongation -*/ -QPointF Conductor::extendTerminal(const QPointF &terminal, Qet::Orientation terminal_orientation, qreal ext_size) { + * @brief Conductor::extendTerminal + * @param terminal : point to extend (must be the docking point of a terminal) + * @param terminal_orientation : the orientation of the terminal + * @param ext_size : how many to extrend (10 by default) + * @return the point with an extension of @ext_size + * and rounded to nearest multiple of ten + * in order to be snapped to the grid of the diagram. + */ +QPointF Conductor::extendTerminal(const QPointF &terminal, Qet::Orientation terminal_orientation, qreal ext_size) +{ QPointF extended_terminal; switch(terminal_orientation) { case Qet::North: - extended_terminal = QPointF(terminal.x(), terminal.y() - ext_size); + extended_terminal = QPointF(terminal.x(), + std::round((terminal.y() - ext_size)/10)*10); break; case Qet::East: - extended_terminal = QPointF(terminal.x() + ext_size, terminal.y()); + extended_terminal = QPointF(std::round((terminal.x() + ext_size)/10)*10, + terminal.y()); break; case Qet::South: - extended_terminal = QPointF(terminal.x(), terminal.y() + ext_size); + extended_terminal = QPointF(terminal.x(), + std::round((terminal.y() + ext_size)/10)*10); break; case Qet::West: - extended_terminal = QPointF(terminal.x() - ext_size, terminal.y()); + extended_terminal = QPointF(std::round((terminal.x() - ext_size)/10)*10, + terminal.y()); break; default: extended_terminal = terminal; } + return(extended_terminal); } diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index 499356941..cb2e71405 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -227,7 +227,7 @@ class Conductor : public QGraphicsObject static int getCoeff(const qreal &, const qreal &); static int getSign(const qreal &); QHash shareOffsetBetweenSegments(const qreal &offset, const QList &, const qreal & = 0.01) const; - static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0); + static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 10); static Qt::Corner movementType(const QPointF &, const QPointF &); static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &); };