4242#include < cmath>
4343
4444Edge::Edge (NodeP sourceNode, NodeP targetNode, bool enableAnimations, bool enableLabel)
45- : m_sourceNode(sourceNode)
45+ : m_edgeModel(std::make_unique<EdgeModel>(SettingsProxy::instance().reversedEdgeDirection(), SettingsProxy::instance().edgeArrowMode()))
46+ , m_sourceNode(sourceNode)
4647 , m_targetNode(targetNode)
47- , m_reversed(SettingsProxy::instance().reversedEdgeDirection())
48- , m_arrowMode(SettingsProxy::instance().edgeArrowMode())
4948 , m_enableAnimations(enableAnimations)
5049 , m_enableLabel(enableLabel)
5150 , m_sourceDot(enableAnimations ? new EdgeDot(this ) : nullptr)
@@ -72,7 +71,7 @@ Edge::Edge(NodeP sourceNode, NodeP targetNode, bool enableAnimations, bool enabl
7271 m_label->setBackgroundColor (Constants::Edge::LABEL_COLOR);
7372 connect (m_label, &TextEdit::textChanged, this , [=](const QString & text) {
7473 updateLabel ();
75- m_text = text;
74+ m_edgeModel-> text = text;
7675 });
7776
7877 connect (m_label, &TextEdit::undoPointRequested, this , &Edge::undoPointRequested);
@@ -137,19 +136,17 @@ QPen Edge::buildPen(bool ignoreDashSetting) const
137136{
138137 QPen pen { QBrush { QColor { m_color.red (), m_color.green (), m_color.blue () } }, m_edgeWidth };
139138 pen.setCapStyle (Qt::PenCapStyle::RoundCap);
140- if (!ignoreDashSetting && m_dashedLine ) {
139+ if (!ignoreDashSetting && m_edgeModel-> dashedLine ) {
141140 pen.setDashPattern (Constants::Edge::DASH_PATTERN);
142141 }
143142 return pen;
144143}
145144
146145void Edge::copyData (EdgeCR other)
147146{
148- m_arrowMode = other.m_arrowMode ;
149- m_dashedLine = other.m_dashedLine ;
150- m_reversed = other.m_reversed ;
147+ *m_edgeModel = *other.m_edgeModel ;
151148
152- setText (other.m_text ); // Update text to the label component
149+ setText (other.m_edgeModel -> text ); // Update text to the label component
153150}
154151
155152void Edge::changeFont (const QFont & font)
@@ -167,7 +164,7 @@ void Edge::changeFont(const QFont & font)
167164
168165bool Edge::dashedLine () const
169166{
170- return m_dashedLine ;
167+ return m_edgeModel-> dashedLine ;
171168}
172169
173170void Edge::initDots ()
@@ -254,9 +251,9 @@ void Edge::setEdgeWidth(double edgeWidth)
254251 updateLine ();
255252}
256253
257- void Edge::setArrowMode (ArrowMode arrowMode)
254+ void Edge::setArrowMode (EdgeModel:: ArrowMode arrowMode)
258255{
259- m_arrowMode = arrowMode;
256+ m_edgeModel-> arrowMode = arrowMode;
260257 if (!TestMode::enabled ()) {
261258 updateLine ();
262259 } else {
@@ -280,7 +277,7 @@ void Edge::setColor(const QColor & color)
280277
281278void Edge::setDashedLine (bool enable)
282279{
283- m_dashedLine = enable;
280+ m_edgeModel-> dashedLine = enable;
284281 if (!TestMode::enabled ()) {
285282 updateLine ();
286283 } else {
@@ -290,7 +287,7 @@ void Edge::setDashedLine(bool enable)
290287
291288void Edge::setText (const QString & text)
292289{
293- m_text = text;
290+ m_edgeModel-> text = text;
294291 if (!TestMode::enabled ()) {
295292 if (m_enableLabel) {
296293 m_label->setText (text);
@@ -311,7 +308,7 @@ void Edge::setTextSize(int textSize)
311308
312309void Edge::setReversed (bool reversed)
313310{
314- m_reversed = reversed;
311+ m_edgeModel-> reversed = reversed;
315312
316313 updateArrowhead ();
317314}
@@ -349,18 +346,19 @@ void Edge::updateArrowhead()
349346{
350347 setArrowHeadPen (buildPen (true ));
351348
352- const auto point0 = m_reversed ? this ->line ().p1 () : this ->line ().p2 ();
353- const auto angle0 = m_reversed ? -this ->line ().angle () + 180 : -this ->line ().angle ();
354- const auto point1 = m_reversed ? this ->line ().p2 () : this ->line ().p1 ();
355- const auto angle1 = m_reversed ? -this ->line ().angle () : -this ->line ().angle () + 180 ;
349+ const auto reversed = m_edgeModel->reversed ;
350+ const auto point0 = reversed ? this ->line ().p1 () : this ->line ().p2 ();
351+ const auto angle0 = reversed ? -this ->line ().angle () + 180 : -this ->line ().angle ();
352+ const auto point1 = reversed ? this ->line ().p2 () : this ->line ().p1 ();
353+ const auto angle1 = reversed ? -this ->line ().angle () : -this ->line ().angle () + 180 ;
356354
357355 QLineF lineL0;
358356 QLineF lineR0;
359357 QLineF lineL1;
360358 QLineF lineR1;
361359
362- switch (m_arrowMode ) {
363- case ArrowMode::Single: {
360+ switch (m_edgeModel-> arrowMode ) {
361+ case EdgeModel:: ArrowMode::Single: {
364362 lineL0.setP1 (point0);
365363 const auto angleL = qDegreesToRadians (angle0 + Constants::Edge::ARROW_OPENING);
366364 lineL0.setP2 (point0 + QPointF (std::cos (angleL), std::sin (angleL)) * m_arrowSize);
@@ -375,7 +373,7 @@ void Edge::updateArrowhead()
375373 m_arrowheadR1->hide ();
376374 break ;
377375 }
378- case ArrowMode::Double: {
376+ case EdgeModel:: ArrowMode::Double: {
379377 lineL0.setP1 (point0);
380378 const auto angleL0 = qDegreesToRadians (angle0 + Constants::Edge::ARROW_OPENING);
381379 lineL0.setP2 (point0 + QPointF (std::cos (angleL0), std::sin (angleL0)) * m_arrowSize);
@@ -398,7 +396,7 @@ void Edge::updateArrowhead()
398396 m_arrowheadR1->show ();
399397 break ;
400398 }
401- case ArrowMode::Hidden:
399+ case EdgeModel:: ArrowMode::Hidden:
402400 m_arrowheadL0->hide ();
403401 m_arrowheadR0->hide ();
404402 m_arrowheadL1->hide ();
@@ -458,7 +456,7 @@ void Edge::setSourceNode(NodeR sourceNode)
458456
459457bool Edge::reversed () const
460458{
461- return m_reversed ;
459+ return m_edgeModel-> reversed ;
462460}
463461
464462void Edge::restoreLabelParent ()
@@ -468,14 +466,14 @@ void Edge::restoreLabelParent()
468466 }
469467}
470468
471- Edge ::ArrowMode Edge::arrowMode () const
469+ EdgeModel ::ArrowMode Edge::arrowMode () const
472470{
473- return m_arrowMode ;
471+ return m_edgeModel-> arrowMode ;
474472}
475473
476474QString Edge::text () const
477475{
478- return m_text ;
476+ return m_edgeModel-> text ;
479477}
480478
481479void Edge::updateLine ()
0 commit comments