BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
NodeEditor Class Reference

The NodeEditor class implement for QGraphicsScene an editable schematic of the dependency graph, displaying nodes and the connections between their attributes. More...

Inheritance diagram for NodeEditor:
[legend]
Collaboration diagram for NodeEditor:
[legend]

Signals

void connectionIsEstablished (NodeEditorConnection *)
 
void selectionModeChangeRequest (int)
 

Public Member Functions

 NodeEditor (QObject *parent=0)
 
bool eventFilter (QObject *object, QEvent *event)
 
void install (QGraphicsScene *scene)
 

Private Member Functions

QGraphicsItem * itemAt (const QPointF &)
 
bool processMouseMove (QGraphicsSceneMouseEvent *event)
 
bool processMousePress (QGraphicsSceneMouseEvent *event)
 
bool processMouseRelease (QGraphicsSceneMouseEvent *event)
 

Private Attributes

NodeEditorConnectionm_conn
 
QGraphicsScene * m_scene
 

Detailed Description

The NodeEditor class implement for QGraphicsScene an editable schematic of the dependency graph, displaying nodes and the connections between their attributes.

Definition at line 35 of file NodeEditor.h.

Constructor & Destructor Documentation

◆ NodeEditor()

NodeEditor::NodeEditor ( QObject *  parent = 0)
explicit

Definition at line 23 of file NodeEditor.cpp.

23 : QObject(parent), m_scene(0), m_conn(0) {}
NodeEditorConnection * m_conn
Definition: NodeEditor.h:58
QGraphicsScene * m_scene
Definition: NodeEditor.h:57

Member Function Documentation

◆ connectionIsEstablished

void NodeEditor::connectionIsEstablished ( NodeEditorConnection )
signal

◆ eventFilter()

bool NodeEditor::eventFilter ( QObject *  object,
QEvent *  event 
)

Definition at line 42 of file NodeEditor.cpp.

43 {
44  QGraphicsSceneMouseEvent* mouseEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
45  if (!mouseEvent)
46  return QObject::eventFilter(object, event);
47 
48  bool isProcessedEvent(false);
49 
50  if (event->type() == QEvent::GraphicsSceneMousePress) {
51  isProcessedEvent = processMousePress(mouseEvent);
52  } else if (event->type() == QEvent::GraphicsSceneMouseMove) {
53  isProcessedEvent = processMouseMove(mouseEvent);
54  } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
55  isProcessedEvent = processMouseRelease(mouseEvent);
56  }
57  return isProcessedEvent ? isProcessedEvent : QObject::eventFilter(object, event);
58 }
bool processMousePress(QGraphicsSceneMouseEvent *event)
Definition: NodeEditor.cpp:60
bool processMouseRelease(QGraphicsSceneMouseEvent *event)
Definition: NodeEditor.cpp:92
bool processMouseMove(QGraphicsSceneMouseEvent *event)
Definition: NodeEditor.cpp:80

References processMouseMove(), processMousePress(), and processMouseRelease().

Here is the call graph for this function:

◆ install()

void NodeEditor::install ( QGraphicsScene *  scene)

Definition at line 25 of file NodeEditor.cpp.

26 {
27  scene->installEventFilter(this);
28  m_scene = scene;
29 }

References m_scene.

Referenced by DesignerScene::DesignerScene().

◆ itemAt()

QGraphicsItem * NodeEditor::itemAt ( const QPointF &  pos)
private

Definition at line 31 of file NodeEditor.cpp.

32 {
33  QList<QGraphicsItem*> items = m_scene->items(QRectF(pos - QPointF(1, 1), QSize(3, 3)));
34 
35  for (QGraphicsItem* item : items)
36  if (item->type() > QGraphicsItem::UserType)
37  return item;
38 
39  return nullptr;
40 }

References m_scene.

Referenced by processMousePress(), and processMouseRelease().

◆ processMouseMove()

bool NodeEditor::processMouseMove ( QGraphicsSceneMouseEvent *  event)
private

Definition at line 80 of file NodeEditor.cpp.

81 {
82  bool result(false);
83 
84  if (m_conn) {
85  m_conn->setPos2(event->scenePos());
86  m_conn->updatePath();
87  result = true;
88  }
89  return result;
90 }
void setPos2(const QPointF &p)

References m_conn, NodeEditorConnection::setPos2(), and NodeEditorConnection::updatePath().

Referenced by eventFilter().

Here is the call graph for this function:

◆ processMousePress()

bool NodeEditor::processMousePress ( QGraphicsSceneMouseEvent *  event)
private

Definition at line 60 of file NodeEditor.cpp.

61 {
62  bool result(false);
63 
64  if (m_conn == 0 && event->button() == Qt::LeftButton) {
65  QGraphicsItem* item = itemAt(event->scenePos());
66  if (item && item->type() == ViewTypes::NODE_EDITOR_PORT) {
70  m_conn->setPos1(item->scenePos());
71  m_conn->setPos2(event->scenePos());
72  m_conn->updatePath();
73 
74  result = true;
75  }
76  }
77  return result;
78 }
void setPos1(const QPointF &p)
void setPort1(NodeEditorPort *p)
QGraphicsItem * itemAt(const QPointF &)
Definition: NodeEditor.cpp:31
void selectionModeChangeRequest(int)
@ NODE_EDITOR_PORT
Definition: ViewTypes.h:27

References itemAt(), m_conn, m_scene, ViewTypes::NODE_EDITOR_PORT, selectionModeChangeRequest(), NodeEditorConnection::setPort1(), NodeEditorConnection::setPos1(), NodeEditorConnection::setPos2(), DesignerView::SIMPLE_SELECTION, and NodeEditorConnection::updatePath().

Referenced by eventFilter().

Here is the call graph for this function:

◆ processMouseRelease()

bool NodeEditor::processMouseRelease ( QGraphicsSceneMouseEvent *  event)
private

Definition at line 92 of file NodeEditor.cpp.

93 {
94  bool result(false);
95 
96  if (m_conn && event->button() == Qt::LeftButton) {
98 
99  QGraphicsItem* item = itemAt(event->scenePos());
100  if (item && item->type() == ViewTypes::NODE_EDITOR_PORT) {
101  NodeEditorPort* port1 = m_conn->port1();
102  NodeEditorPort* port2 = (NodeEditorPort*)item;
103 
104  if (port1->parentItem() != port2->parentItem() && port1->isOutput() != port2->isOutput()
105  && !port1->isConnected(port2) && port1->getPortType() == port2->getPortType()) {
106  m_conn->setPos2(port2->scenePos());
107  m_conn->setPort2(port2);
108  m_conn->updatePath();
110  m_conn = 0;
111  return true;
112  }
113  }
114  delete m_conn;
115  m_conn = 0;
116  result = true;
117  }
118  return result;
119 }
void setPort2(NodeEditorPort *p)
NodeEditorPort * port1() const
bool isConnected(NodeEditorPort *)
EPortType getPortType() const
void connectionIsEstablished(NodeEditorConnection *)

References connectionIsEstablished(), NodeEditorPort::getPortType(), NodeEditorPort::isConnected(), NodeEditorPort::isOutput(), itemAt(), m_conn, ViewTypes::NODE_EDITOR_PORT, NodeEditorConnection::port1(), DesignerView::RUBBER_SELECTION, selectionModeChangeRequest(), NodeEditorConnection::setPort2(), NodeEditorConnection::setPos2(), and NodeEditorConnection::updatePath().

Referenced by eventFilter().

Here is the call graph for this function:

◆ selectionModeChangeRequest

void NodeEditor::selectionModeChangeRequest ( int  )
signal

Member Data Documentation

◆ m_conn

NodeEditorConnection* NodeEditor::m_conn
private

Definition at line 58 of file NodeEditor.h.

Referenced by processMouseMove(), processMousePress(), and processMouseRelease().

◆ m_scene

QGraphicsScene* NodeEditor::m_scene
private

Definition at line 57 of file NodeEditor.h.

Referenced by install(), itemAt(), and processMousePress().


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