BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
NodeEditorConnection Class Reference
Inheritance diagram for NodeEditorConnection:
[legend]
Collaboration diagram for NodeEditorConnection:
[legend]

Public Member Functions

 NodeEditorConnection (QGraphicsItem *parent=0, QGraphicsScene *scene=0)
 
virtual ~NodeEditorConnection ()
 
ConnectableView * getChildView ()
 returns child view, i.e. the view which owns output port of given connection More...
 
ConnectableView * getParentView ()
 returns parent view, i.e. the view which owns input port of given connection More...
 
NodeEditorPort * inputPort ()
 
NodeEditorPort * outputPort ()
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
NodeEditorPort * port1 () const
 
NodeEditorPort * port2 () const
 
void setPort1 (NodeEditorPort *p)
 
void setPort2 (NodeEditorPort *p)
 
void setPos1 (const QPointF &p)
 
void setPos2 (const QPointF &p)
 
int type () const
 
void updatePath ()
 
void updatePosFromPorts ()
 

Private Attributes

NodeEditorPort * m_port1
 
NodeEditorPort * m_port2
 
QPointF pos1
 
QPointF pos2
 

Detailed Description

Definition at line 30 of file NodeEditorConnection.h.

Constructor & Destructor Documentation

◆ NodeEditorConnection()

NodeEditorConnection::NodeEditorConnection ( QGraphicsItem *  parent = 0,
QGraphicsScene *  scene = 0 
)

Definition at line 23 of file NodeEditorConnection.cpp.

24  : QGraphicsPathItem(parent), m_port1(0), m_port2(0)
25 {
26  setFlag(QGraphicsItem::ItemIsSelectable, true);
27  setPen(QPen(Qt::darkGray, 2));
28  setBrush(Qt::NoBrush);
29  setZValue(-1);
30  if (scene)
31  scene->addItem(this);
32 }
NodeEditorPort * m_port2
NodeEditorPort * m_port1

◆ ~NodeEditorConnection()

NodeEditorConnection::~NodeEditorConnection ( )
virtual

Definition at line 34 of file NodeEditorConnection.cpp.

35 {
36  if (m_port1)
37  m_port1->remove(this);
38 
39  if (m_port2)
40  m_port2->remove(this);
41 }
void remove(NodeEditorConnection *connection)

References m_port1, m_port2, and NodeEditorPort::remove().

Here is the call graph for this function:

Member Function Documentation

◆ getChildView()

ConnectableView * NodeEditorConnection::getChildView ( )

returns child view, i.e. the view which owns output port of given connection

Definition at line 131 of file NodeEditorConnection.cpp.

132 {
133  ASSERT(inputPort() != outputPort());
134  ConnectableView* result = dynamic_cast<ConnectableView*>(outputPort()->parentItem());
135  ASSERT(result);
136  return result;
137 }
#define ASSERT(condition)
Definition: Assert.h:31
view of ISampleNode's with rectangular shape and node functionality
NodeEditorPort * inputPort()
NodeEditorPort * outputPort()

References ASSERT, inputPort(), and outputPort().

Referenced by DesignerScene::onEstablishedConnection().

Here is the call graph for this function:

◆ getParentView()

ConnectableView * NodeEditorConnection::getParentView ( )

returns parent view, i.e. the view which owns input port of given connection

Definition at line 123 of file NodeEditorConnection.cpp.

124 {
125  ASSERT(inputPort() != outputPort());
126  ConnectableView* result = dynamic_cast<ConnectableView*>(inputPort()->parentItem());
127  ASSERT(result);
128  return result;
129 }

References ASSERT, inputPort(), and outputPort().

Referenced by DesignerScene::onEstablishedConnection().

Here is the call graph for this function:

◆ inputPort()

NodeEditorPort * NodeEditorConnection::inputPort ( )

Definition at line 95 of file NodeEditorConnection.cpp.

96 {
98  return (m_port1->isInput() ? m_port1 : m_port2);
99 }

References ASSERT, NodeEditorPort::isInput(), m_port1, and m_port2.

Referenced by getChildView(), getParentView(), and DesignerScene::onEstablishedConnection().

Here is the call graph for this function:

◆ outputPort()

NodeEditorPort * NodeEditorConnection::outputPort ( )

Definition at line 101 of file NodeEditorConnection.cpp.

102 {
103  ASSERT(m_port1 && m_port2);
104  return (m_port1->isOutput() ? m_port1 : m_port2);
105 }

References ASSERT, NodeEditorPort::isOutput(), m_port1, and m_port2.

Referenced by getChildView(), getParentView(), and DesignerScene::removeConnection().

Here is the call graph for this function:

◆ paint()

void NodeEditorConnection::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)

Definition at line 107 of file NodeEditorConnection.cpp.

109 {
110  Q_UNUSED(option)
111  Q_UNUSED(widget)
112 
113  painter->setPen(QPen(Qt::darkGray, 2));
114  painter->setBrush(Qt::NoBrush);
115 
116  if (isSelected()) {
117  painter->setPen(Qt::DashLine);
118  }
119 
120  painter->drawPath(path());
121 }

◆ port1()

NodeEditorPort * NodeEditorConnection::port1 ( ) const

Definition at line 85 of file NodeEditorConnection.cpp.

86 {
87  return m_port1;
88 }

References m_port1.

Referenced by NodeEditor::processMouseRelease().

◆ port2()

NodeEditorPort * NodeEditorConnection::port2 ( ) const

Definition at line 90 of file NodeEditorConnection.cpp.

91 {
92  return m_port2;
93 }

References m_port2.

◆ setPort1()

void NodeEditorConnection::setPort1 ( NodeEditorPort *  p)

Definition at line 53 of file NodeEditorConnection.cpp.

54 {
55  m_port1 = p;
56  m_port1->append(this);
57  setPos1(p->scenePos());
58 }
void setPos1(const QPointF &p)
void append(NodeEditorConnection *connection)

References NodeEditorPort::append(), m_port1, and setPos1().

Referenced by ConnectableView::connectInputPort(), and NodeEditor::processMousePress().

Here is the call graph for this function:

◆ setPort2()

void NodeEditorConnection::setPort2 ( NodeEditorPort *  p)

Definition at line 60 of file NodeEditorConnection.cpp.

61 {
62  m_port2 = p;
63  m_port2->append(this);
64  setPos2(p->scenePos());
65 }
void setPos2(const QPointF &p)

References NodeEditorPort::append(), m_port2, and setPos2().

Referenced by ConnectableView::connectInputPort(), and NodeEditor::processMouseRelease().

Here is the call graph for this function:

◆ setPos1()

void NodeEditorConnection::setPos1 ( const QPointF &  p)

Definition at line 43 of file NodeEditorConnection.cpp.

44 {
45  pos1 = p;
46 }

References pos1.

Referenced by NodeEditor::processMousePress(), and setPort1().

◆ setPos2()

void NodeEditorConnection::setPos2 ( const QPointF &  p)

◆ type()

int NodeEditorConnection::type ( ) const
inline

Definition at line 48 of file NodeEditorConnection.h.

@ NODE_EDITOR_CONNECTION
Definition: ViewTypes.h:28

References ViewTypes::NODE_EDITOR_CONNECTION.

◆ updatePath()

void NodeEditorConnection::updatePath ( )

Definition at line 73 of file NodeEditorConnection.cpp.

74 {
75  QPainterPath p;
76  p.moveTo(pos1);
77  qreal dx = pos2.x() - pos1.x();
78  dx = qMax(dx, 200.);
79  QPointF ctr1(pos1.x() + dx * 0.25, pos1.y());
80  QPointF ctr2(pos2.x() - dx * 0.25, pos2.y());
81  p.cubicTo(ctr1, ctr2, pos2);
82  setPath(p);
83 }

References pos1, and pos2.

Referenced by ConnectableView::connectInputPort(), NodeEditor::processMouseMove(), NodeEditor::processMousePress(), and NodeEditor::processMouseRelease().

◆ updatePosFromPorts()

void NodeEditorConnection::updatePosFromPorts ( )

Definition at line 67 of file NodeEditorConnection.cpp.

68 {
69  pos1 = m_port1->scenePos();
70  pos2 = m_port2->scenePos();
71 }

References m_port1, m_port2, pos1, and pos2.

Member Data Documentation

◆ m_port1

NodeEditorPort* NodeEditorConnection::m_port1
private

◆ m_port2

NodeEditorPort* NodeEditorConnection::m_port2
private

◆ pos1

QPointF NodeEditorConnection::pos1
private

Definition at line 59 of file NodeEditorConnection.h.

Referenced by setPos1(), updatePath(), and updatePosFromPorts().

◆ pos2

QPointF NodeEditorConnection::pos2
private

Definition at line 60 of file NodeEditorConnection.h.

Referenced by setPos2(), updatePath(), and updatePosFromPorts().


The documentation for this class was generated from the following files: