BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ConnectableView.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SampleDesigner/ConnectableView.h
6 //! @brief Defines class ConnectableView
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_SAMPLEDESIGNER_CONNECTABLEVIEW_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_SAMPLEDESIGNER_CONNECTABLEVIEW_H
17 
20 
21 class QPainter;
22 class QStyleOptionGraphicsItem;
23 class QWidget;
24 class NodeEditorPort;
25 
26 //! view of ISampleNode's with rectangular shape and node functionality
27 class ConnectableView : public IView {
28  Q_OBJECT
29 public:
30  ConnectableView(QGraphicsItem* parent = 0, QRectF rect = {0, 0, 50, 50});
31  virtual ~ConnectableView() {}
32  int type() const { return ViewTypes::ISAMPLE_RECT; }
33 
34  virtual QRectF boundingRect() const { return getRectangle(); }
35  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
36 
37  virtual QString getName() const { return m_name; }
38  virtual QColor getColor() const { return m_color; }
39  virtual QRectF getRectangle() const { return m_rect; }
40  virtual void setRectangle(QRectF rect) { m_rect = rect; }
41  virtual QString getLabel() const { return m_label; }
42  virtual void setLabel(const QString& name);
43 
44  //! adds port to view
45  virtual NodeEditorPort* addPort(const QString& name, NodeEditorPort::EPortDirection direction,
46  NodeEditorPort::EPortType port_type);
47 
48  //! connects input port with given index with output port of other view
49  void connectInputPort(ConnectableView* other, int port_number);
50 
51  QList<NodeEditorPort*> getInputPorts() { return m_input_ports; }
52  QList<NodeEditorPort*> getOutputPorts() { return m_output_ports; }
53 
55 
56  virtual void setName(const QString& name) { m_name = name; }
57  virtual void setColor(const QColor& color) { m_color = color; }
58 
59 protected:
60  virtual void setPortCoordinates();
61  virtual int getNumberOfPorts();
62  virtual int getNumberOfOutputPorts();
63  virtual int getNumberOfInputPorts();
64  virtual void update_appearance();
65 
66  QString m_name;
67  QColor m_color;
68  QRectF m_rect;
70  double m_label_vspace; // vertical space occupied by the label
71  QString m_label;
72  QList<NodeEditorPort*> m_input_ports;
73  QList<NodeEditorPort*> m_output_ports;
74 
75 private:
76  QString hyphenate(const QString& name) const;
77 };
78 
79 //! default view of unimplemented ISampleNode's
80 // class ISampleNodeDefaultView : public ConnectableView
81 //{
82 // public:
83 // ISampleNodeDefaultView(QGraphicsItem *parent = 0) : ConnectableView(parent){}
84 // //! сalls the ISampleNodeViewVisitor's visit method
85 //};
86 
87 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_SAMPLEDESIGNER_CONNECTABLEVIEW_H
Defines interface IView.
Defines class NodeEditorPort.
view of ISampleNode's with rectangular shape and node functionality
virtual QString getLabel() const
QString hyphenate(const QString &name) const
ConnectableView(QGraphicsItem *parent=0, QRectF rect={0, 0, 50, 50})
QList< NodeEditorPort * > getOutputPorts()
QList< NodeEditorPort * > getInputPorts()
void connectInputPort(ConnectableView *other, int port_number)
connects input port with given index with output port of other view
virtual QRectF boundingRect() const
int getInputPortIndex(NodeEditorPort *port)
virtual void update_appearance()
updates visual appearance of the item (color, icons, size etc)
virtual int getNumberOfPorts()
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void setColor(const QColor &color)
virtual QColor getColor() const
virtual QString getName() const
virtual void setLabel(const QString &name)
virtual int getNumberOfOutputPorts()
virtual void setPortCoordinates()
virtual void setRectangle(QRectF rect)
virtual QRectF getRectangle() const
virtual int getNumberOfInputPorts()
QList< NodeEditorPort * > m_input_ports
virtual NodeEditorPort * addPort(const QString &name, NodeEditorPort::EPortDirection direction, NodeEditorPort::EPortType port_type)
adds port to view
virtual ~ConnectableView()
int type() const
QList< NodeEditorPort * > m_output_ports
virtual void setName(const QString &name)
parent class for graphic representation of all ISampleNode's
Definition: IView.h:25
EPortType
type of ports, same type can be connected together
EPortDirection
port direction
QString const & name(EShape k)
Definition: particles.cpp:21
@ ISAMPLE_RECT
Definition: ViewTypes.h:26