move initialization to header, so it must not be done in every constructor

This commit is contained in:
Martin Marmsoler
2020-05-26 16:20:30 +02:00
committed by Laurent Trinques
parent dd377eeb73
commit bb24e121eb
2 changed files with 10 additions and 25 deletions

View File

@@ -42,6 +42,7 @@ const qreal Terminal::Z = 1000;
*/ */
void Terminal::init(QString number, QString name, bool hiddenName) { void Terminal::init(QString number, QString name, bool hiddenName) {
hovered_color_ = Terminal::neutralColor;
m_uuid = QUuid::createUuid(); m_uuid = QUuid::createUuid();
// calcul de la position du point d'amarrage a l'element // calcul de la position du point d'amarrage a l'element
@@ -102,11 +103,7 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) : Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
QGraphicsObject(e), QGraphicsObject(e),
d(new TerminalData(this)), d(new TerminalData(this)),
m_draw_help_line(false), parent_element_ (e)
m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e),
hovered_color_ (Terminal::neutralColor)
{ {
init(pf, o, "_", "_", false); init(pf, o, "_", "_", false);
} }
@@ -121,12 +118,8 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
*/ */
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) : Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
QGraphicsObject(e), QGraphicsObject(e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
d(new TerminalData(this)), d(new TerminalData(this)),
parent_element_ (e), parent_element_ (e)
hovered_color_ (Terminal::neutralColor)
{ {
init(QPointF(pf_x, pf_y), o, "_", "_", false); init(QPointF(pf_x, pf_y), o, "_", "_", false);
} }
@@ -143,24 +136,16 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
*/ */
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) : Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
QGraphicsObject (e), QGraphicsObject (e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
d(new TerminalData(this)), d(new TerminalData(this)),
parent_element_ (e), parent_element_ (e)
hovered_color_ (Terminal::neutralColor)
{ {
init(pf, o, std::move(num), std::move(name), hiddenName); init(pf, o, std::move(num), std::move(name), hiddenName);
} }
Terminal::Terminal(TerminalData* data, Element* e) : Terminal::Terminal(TerminalData* data, Element* e) :
QGraphicsObject(e), QGraphicsObject(e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
d(data), d(data),
parent_element_(e), parent_element_(e)
hovered_color_ (Terminal::neutralColor)
{ {
// TODO: what is when multiple parents exist. So the other relation is lost. // TODO: what is when multiple parents exist. So the other relation is lost.
d->setParent(this); d->setParent(this);

View File

@@ -110,15 +110,15 @@ class Terminal : public QGraphicsObject
static QColor forbiddenColor; static QColor forbiddenColor;
private: private:
bool m_draw_help_line; bool m_draw_help_line{false};
QGraphicsLineItem *m_help_line; QGraphicsLineItem *m_help_line{nullptr};
QGraphicsLineItem *m_help_line_a; QGraphicsLineItem *m_help_line_a{nullptr};
TerminalData* d; TerminalData* d;
/// Parent electrical element /// Parent electrical element
Element *parent_element_; Element *parent_element_{nullptr};
/// docking point for parent element /// docking point for parent element
QPointF dock_elmt_; QPointF dock_elmt_;
/// List of conductors attached to the terminal /// List of conductors attached to the terminal
@@ -126,7 +126,7 @@ class Terminal : public QGraphicsObject
/// Pointer to a rectangle representing the terminal bounding rect; /// Pointer to a rectangle representing the terminal bounding rect;
/// used to calculate the bounding rect once only; /// used to calculate the bounding rect once only;
/// used a pointer because boundingRect() is supposed to be const. /// used a pointer because boundingRect() is supposed to be const.
QRectF *br_; QRectF *br_{nullptr};
/// Last terminal seen through an attached conductor /// Last terminal seen through an attached conductor
Terminal *previous_terminal_; Terminal *previous_terminal_;
/// Whether the mouse pointer is hovering the terminal /// Whether the mouse pointer is hovering the terminal