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

Public Types

enum  EPortDirection { INPUT , OUTPUT }
 port direction More...
 
enum  EPortType {
  DEFAULT , INTERFERENCE , PARTICLE_LAYOUT , FORM_FACTOR ,
  TRANSFORMATION
}
 type of ports, same type can be connected together More...
 

Public Member Functions

 NodeEditorPort (QGraphicsItem *parent=0, const QString &name="unnamed", EPortDirection direction=INPUT, EPortType port_type=DEFAULT)
 
virtual ~NodeEditorPort ()
 
void append (NodeEditorConnection *connection)
 
EPortType getPortType () const
 
bool isConnected ()
 
bool isConnected (NodeEditorPort *)
 
bool isInput ()
 
bool isOutput ()
 
const QString & portName () const
 
void remove (NodeEditorConnection *connection)
 
void setLabel (QString name)
 
virtual int type () const
 

Static Public Member Functions

static QColor getPortTypeColor (NodeEditorPort::EPortType port_type)
 

Protected Member Functions

QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 

Private Attributes

QColor m_color
 
QVector< NodeEditorConnection * > m_connections
 
EPortDirection m_direction
 
QGraphicsTextItem * m_label
 
int m_margin
 
QString m_name
 
EPortType m_port_type
 
int m_radius
 

Detailed Description

Definition at line 31 of file NodeEditorPort.h.

Member Enumeration Documentation

◆ EPortDirection

port direction

Enumerator
INPUT 
OUTPUT 

Definition at line 37 of file NodeEditorPort.h.

◆ EPortType

type of ports, same type can be connected together

Enumerator
DEFAULT 
INTERFERENCE 
PARTICLE_LAYOUT 
FORM_FACTOR 
TRANSFORMATION 

Definition at line 34 of file NodeEditorPort.h.

Constructor & Destructor Documentation

◆ NodeEditorPort()

NodeEditorPort::NodeEditorPort ( QGraphicsItem *  parent = 0,
const QString &  name = "unnamed",
NodeEditorPort::EPortDirection  direction = INPUT,
NodeEditorPort::EPortType  port_type = DEFAULT 
)

Definition at line 23 of file NodeEditorPort.cpp.

26  : QGraphicsPathItem(parent)
27  , m_name(name)
28  , m_direction(direction)
29  , m_port_type(port_type)
30  , m_radius(0)
31  , m_margin(0)
32  , m_label(nullptr)
33 {
34  m_radius = StyleUtils::SizeOfLetterM().width() * 0.4;
35  m_margin = m_radius * 0.5;
36  m_color = getPortTypeColor(port_type);
37 
38  QPainterPath p;
39  p.addEllipse(-m_radius, -m_radius, 2 * m_radius, 2 * m_radius);
40  setPath(p);
41 
42  setPen(QPen(m_color.darker(180)));
43  setBrush(m_color);
44 
45  setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
46 
47  if (!m_name.isEmpty()) {
49  }
50 }
EPortType m_port_type
EPortDirection m_direction
static QColor getPortTypeColor(NodeEditorPort::EPortType port_type)
void setLabel(QString name)
QGraphicsTextItem * m_label
QString const & name(EShape k)
Definition: particles.cpp:21
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110

References getPortTypeColor(), m_color, m_margin, m_name, m_radius, setLabel(), and StyleUtils::SizeOfLetterM().

Here is the call graph for this function:

◆ ~NodeEditorPort()

NodeEditorPort::~NodeEditorPort ( )
virtual

Definition at line 52 of file NodeEditorPort.cpp.

53 {
54  while (m_connections.size() > 0) {
55  auto conn = m_connections.last();
56  conn->setSelected(false);
57  delete conn;
58  }
59 }
QVector< NodeEditorConnection * > m_connections

References m_connections.

Member Function Documentation

◆ append()

void NodeEditorPort::append ( NodeEditorConnection connection)

Definition at line 77 of file NodeEditorPort.cpp.

78 {
79  m_connections.append(connection);
80 }

References m_connections.

Referenced by NodeEditorConnection::setPort1(), and NodeEditorConnection::setPort2().

◆ getPortType()

NodeEditorPort::EPortType NodeEditorPort::getPortType ( ) const
inline

Definition at line 93 of file NodeEditorPort.h.

94 {
95  return m_port_type;
96 }

References m_port_type.

Referenced by DesignerScene::onEstablishedConnection(), and NodeEditor::processMouseRelease().

◆ getPortTypeColor()

QColor NodeEditorPort::getPortTypeColor ( NodeEditorPort::EPortType  port_type)
static

Definition at line 91 of file NodeEditorPort.cpp.

92 {
93  switch (port_type) {
94  case DEFAULT:
95  return QColor(Qt::gray);
96  case INTERFERENCE:
97  return QColor(Qt::yellow);
98  case PARTICLE_LAYOUT:
99  return QColor(Qt::green);
100  case FORM_FACTOR:
101  return QColor(Qt::blue);
102  case TRANSFORMATION:
103  return QColor(Qt::magenta);
104  default:
105  return QColor(Qt::red);
106  }
107 }

References DEFAULT, FORM_FACTOR, INTERFERENCE, PARTICLE_LAYOUT, and TRANSFORMATION.

Referenced by NodeEditorPort().

◆ isConnected() [1/2]

bool NodeEditorPort::isConnected ( )
inline

Definition at line 88 of file NodeEditorPort.h.

89 {
90  return m_connections.size();
91 }

References m_connections.

◆ isConnected() [2/2]

bool NodeEditorPort::isConnected ( NodeEditorPort other)

Definition at line 82 of file NodeEditorPort.cpp.

83 {
84  for (auto conn : m_connections)
85  if (conn->port1() == other || conn->port2() == other)
86  return true;
87 
88  return false;
89 }

References m_connections.

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

◆ isInput()

bool NodeEditorPort::isInput ( )

Definition at line 66 of file NodeEditorPort.cpp.

67 {
68  return !isOutput();
69 }

References isOutput().

Referenced by NodeEditorConnection::inputPort().

Here is the call graph for this function:

◆ isOutput()

bool NodeEditorPort::isOutput ( )

◆ itemChange()

QVariant NodeEditorPort::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
protected

Definition at line 109 of file NodeEditorPort.cpp.

110 {
111  if (change == ItemScenePositionHasChanged) {
112  for (auto conn : m_connections) {
113  conn->updatePosFromPorts();
114  conn->updatePath();
115  }
116  }
117  return value;
118 }

References m_connections.

◆ portName()

const QString & NodeEditorPort::portName ( ) const
inline

Definition at line 78 of file NodeEditorPort.h.

79 {
80  return m_name;
81 }

References m_name.

◆ remove()

void NodeEditorPort::remove ( NodeEditorConnection connection)

Definition at line 71 of file NodeEditorPort.cpp.

72 {
73  if (m_connections.contains(connection))
74  m_connections.remove(m_connections.indexOf(connection));
75 }

References m_connections.

Referenced by NodeEditorConnection::~NodeEditorConnection().

◆ setLabel()

void NodeEditorPort::setLabel ( QString  name)

Definition at line 120 of file NodeEditorPort.cpp.

121 {
122  if (!m_label)
123  m_label = new QGraphicsTextItem(this);
124  m_label->setPlainText(name);
125  QFont serifFont("Monospace", DesignerHelper::getPortFontSize(), QFont::Normal);
126  m_label->setFont(serifFont);
127 
128  if (isOutput()) {
129  m_label->setPos(-m_radius - m_margin - m_label->boundingRect().width(),
130  -m_label->boundingRect().height() / 2);
131  } else {
132  m_label->setPos(m_radius + m_margin, -m_label->boundingRect().height() / 2);
133  }
134 }
static int getPortFontSize()

References DesignerHelper::getPortFontSize(), isOutput(), m_label, m_margin, m_radius, and RealSpace::Particles::name().

Referenced by NodeEditorPort(), and ILayerView::updateLabel().

Here is the call graph for this function:

◆ type()

int NodeEditorPort::type ( ) const
inlinevirtual

Definition at line 83 of file NodeEditorPort.h.

84 {
86 }
@ NODE_EDITOR_PORT
Definition: ViewTypes.h:27

References ViewTypes::NODE_EDITOR_PORT.

Member Data Documentation

◆ m_color

QColor NodeEditorPort::m_color
private

Definition at line 71 of file NodeEditorPort.h.

Referenced by NodeEditorPort().

◆ m_connections

QVector<NodeEditorConnection*> NodeEditorPort::m_connections
private

Definition at line 74 of file NodeEditorPort.h.

Referenced by ~NodeEditorPort(), append(), isConnected(), itemChange(), and remove().

◆ m_direction

EPortDirection NodeEditorPort::m_direction
private

Definition at line 69 of file NodeEditorPort.h.

Referenced by isOutput().

◆ m_label

QGraphicsTextItem* NodeEditorPort::m_label
private

Definition at line 75 of file NodeEditorPort.h.

Referenced by setLabel().

◆ m_margin

int NodeEditorPort::m_margin
private

Definition at line 73 of file NodeEditorPort.h.

Referenced by NodeEditorPort(), and setLabel().

◆ m_name

QString NodeEditorPort::m_name
private

Definition at line 68 of file NodeEditorPort.h.

Referenced by NodeEditorPort(), and portName().

◆ m_port_type

EPortType NodeEditorPort::m_port_type
private

Definition at line 70 of file NodeEditorPort.h.

Referenced by getPortType().

◆ m_radius

int NodeEditorPort::m_radius
private

Definition at line 72 of file NodeEditorPort.h.

Referenced by NodeEditorPort(), and setLabel().


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