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

Class that represents view of Layer. More...

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

Public Slots

virtual void onChangedX ()
 
virtual void onChangedY ()
 
void onPropertyChange (const QString &propertyName)
 Propagates change of 'Thickness' dynamic property to screen thickness of ILayerView. More...
 

Signals

void aboutToBeDeleted ()
 

Public Member Functions

 LayerView (QGraphicsItem *parent=0)
 
virtual NodeEditorPortaddPort (const QString &name, NodeEditorPort::EPortDirection direction, NodeEditorPort::EPortType port_type)
 adds port to view More...
 
virtual void addView (IView *childView, int row=0)
 
virtual QRectF boundingRect () const
 
void connectInputPort (ConnectableView *other, int port_number)
 connects input port with given index with output port of other view More...
 
virtual QColor getColor () const
 
int getInputPortIndex (NodeEditorPort *port)
 
QList< NodeEditorPort * > getInputPorts ()
 
virtual SessionItemgetItem ()
 
virtual QString getLabel () const
 
virtual QString getName () const
 
QList< NodeEditorPort * > getOutputPorts ()
 
virtual QRectF getRectangle () const
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
virtual void setColor (const QColor &color)
 
virtual void setLabel (const QString &name)
 
virtual void setName (const QString &name)
 
virtual void setParameterizedItem (SessionItem *item)
 
virtual void setRectangle (QRectF rect)
 
virtual int type () const
 
void updateLabel ()
 

Protected Member Functions

virtual int getNumberOfInputPorts ()
 
virtual int getNumberOfOutputPorts ()
 
virtual int getNumberOfPorts ()
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 Detects movement of the ILayerView and sends possible drop areas to GraphicsScene for visualization. More...
 
void mousePressEvent (QGraphicsSceneMouseEvent *event)
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 Detects possible MultiLayerView's to drop given ILayerView and propagate request to SessionModel. More...
 
virtual void onSiblingsChange ()
 
virtual void setPortCoordinates ()
 
void update_appearance ()
 updates visual appearance of the item (color, icons, size etc) More...
 

Protected Attributes

QColor m_color
 
QList< NodeEditorPort * > m_input_ports
 
SessionItemm_item
 
QString m_label
 
double m_label_vspace
 
QString m_name
 
QList< NodeEditorPort * > m_output_ports
 
QRectF m_rect
 
int m_roundpar
 

Private Member Functions

MultiLayerCandidate getMultiLayerCandidate ()
 Finds candidate (another MultiLayer) into which we will move our ILayerView. More...
 
QString hyphenate (const QString &name) const
 
void updateColor ()
 
void updateHeight ()
 

Private Attributes

QPointF m_drag_start_position
 

Detailed Description

Class that represents view of Layer.

Definition at line 21 of file LayerView.h.

Constructor & Destructor Documentation

◆ LayerView()

LayerView::LayerView ( QGraphicsItem *  parent = 0)

Definition at line 24 of file LayerView.cpp.

24  : ILayerView(parent)
25 {
26  setColor(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
27  setName("Layer");
29  setAcceptDrops(false);
31 }
virtual void setColor(const QColor &color)
virtual void setRectangle(QRectF rect)
virtual NodeEditorPort * addPort(const QString &name, NodeEditorPort::EPortDirection direction, NodeEditorPort::EPortType port_type)
adds port to view
virtual void setName(const QString &name)
static QRectF getDefaultBoundingRect(const QString &name)
returns default bounding rectangle for given IvView name
ILayerView(QGraphicsItem *parent=0)
Definition: ILayerView.cpp:43

References ConnectableView::addPort(), DesignerHelper::getDefaultBoundingRect(), NodeEditorPort::INPUT, NodeEditorPort::PARTICLE_LAYOUT, ConnectableView::setColor(), ConnectableView::setName(), and ConnectableView::setRectangle().

Here is the call graph for this function:

Member Function Documentation

◆ aboutToBeDeleted

void IView::aboutToBeDeleted ( )
signalinherited

◆ addPort()

NodeEditorPort * ConnectableView::addPort ( const QString &  name,
NodeEditorPort::EPortDirection  direction,
NodeEditorPort::EPortType  port_type 
)
virtualinherited

adds port to view

Definition at line 68 of file ConnectableView.cpp.

71 {
72  NodeEditorPort* port = new NodeEditorPort(this, name, direction, port_type);
73  if (direction == NodeEditorPort::INPUT) {
74  m_input_ports.append(port);
75  } else if (direction == NodeEditorPort::OUTPUT) {
76  m_output_ports.append(port);
77  } else {
78  throw GUIHelpers::Error("ConnectableView::addPort() -> Unknown port type");
79  }
81  return port;
82 }
virtual void setPortCoordinates()
QList< NodeEditorPort * > m_input_ports
QList< NodeEditorPort * > m_output_ports
QString const & name(EShape k)
Definition: particles.cpp:21

References NodeEditorPort::INPUT, ConnectableView::m_input_ports, ConnectableView::m_output_ports, RealSpace::Particles::name(), NodeEditorPort::OUTPUT, and ConnectableView::setPortCoordinates().

Referenced by InterferenceFunction1DLatticeView::InterferenceFunction1DLatticeView(), InterferenceFunction2DLatticeView::InterferenceFunction2DLatticeView(), InterferenceFunction2DParaCrystalView::InterferenceFunction2DParaCrystalView(), InterferenceFunctionFinite2DLatticeView::InterferenceFunctionFinite2DLatticeView(), InterferenceFunctionHardDiskView::InterferenceFunctionHardDiskView(), InterferenceFunctionRadialParaCrystalView::InterferenceFunctionRadialParaCrystalView(), LayerView(), MesoCrystalView::MesoCrystalView(), ParticleCompositionView::ParticleCompositionView(), ParticleCoreShellView::ParticleCoreShellView(), ParticleDistributionView::ParticleDistributionView(), ParticleLayoutView::ParticleLayoutView(), ParticleView::ParticleView(), and TransformationView::TransformationView().

Here is the call graph for this function:

◆ addView()

void LayerView::addView ( IView childView,
int  row = 0 
)
virtual

Reimplemented from IView.

Definition at line 45 of file LayerView.cpp.

46 {
47  ParticleLayoutView* layout = dynamic_cast<ParticleLayoutView*>(childView);
48  ASSERT(layout);
49  connectInputPort(layout, 0);
50 }
#define ASSERT(condition)
Definition: Assert.h:31
void connectInputPort(ConnectableView *other, int port_number)
connects input port with given index with output port of other view

References ASSERT, and ConnectableView::connectInputPort().

Here is the call graph for this function:

◆ boundingRect()

virtual QRectF ConnectableView::boundingRect ( ) const
inlinevirtualinherited

Reimplemented in MultiLayerView.

Definition at line 34 of file ConnectableView.h.

34 { return getRectangle(); }
virtual QRectF getRectangle() const

References ConnectableView::getRectangle().

Referenced by ILayerView::getMultiLayerCandidate().

Here is the call graph for this function:

◆ connectInputPort()

void ConnectableView::connectInputPort ( ConnectableView other,
int  port_number 
)
inherited

connects input port with given index with output port of other view

Definition at line 90 of file ConnectableView.cpp.

91 {
92  ASSERT(other);
93 
94  if (port_number >= m_input_ports.size())
95  throw GUIHelpers::Error("ConnectableView::connectInputPort() -> Wrong input port number");
96 
97  if (other->getOutputPorts().size() != 1)
98  throw GUIHelpers::Error("ConnectableView::connectInputPort() -> Wrong output port number");
99 
100  if (port_number < 0)
101  return;
102 
103  NodeEditorPort* input = m_input_ports.at(port_number);
104  NodeEditorPort* output = other->getOutputPorts().at(0);
105 
106  if (!input->isConnected(output)) {
107  NodeEditorConnection* conn = new NodeEditorConnection(0, scene());
108  conn->setPort2(input);
109  conn->setPort1(output);
110  conn->updatePath();
111  }
112 }
QList< NodeEditorPort * > getOutputPorts()
void setPort2(NodeEditorPort *p)
void setPort1(NodeEditorPort *p)
bool isConnected(NodeEditorPort *)

References ASSERT, ConnectableView::getOutputPorts(), NodeEditorPort::isConnected(), ConnectableView::m_input_ports, NodeEditorConnection::setPort1(), NodeEditorConnection::setPort2(), and NodeEditorConnection::updatePath().

Referenced by addView(), MesoCrystalView::addView(), ParticleCompositionView::addView(), ParticleCoreShellView::addView(), ParticleDistributionView::addView(), ParticleLayoutView::addView(), and ParticleView::addView().

Here is the call graph for this function:

◆ getColor()

virtual QColor ConnectableView::getColor ( ) const
inlinevirtualinherited

Definition at line 38 of file ConnectableView.h.

38 { return m_color; }

References ConnectableView::m_color.

◆ getInputPortIndex()

int ConnectableView::getInputPortIndex ( NodeEditorPort port)
inherited

Definition at line 114 of file ConnectableView.cpp.

115 {
116  return m_input_ports.indexOf(port);
117 }

References ConnectableView::m_input_ports.

Referenced by DesignerScene::onEstablishedConnection().

◆ getInputPorts()

QList<NodeEditorPort*> ConnectableView::getInputPorts ( )
inlineinherited

Definition at line 51 of file ConnectableView.h.

51 { return m_input_ports; }

References ConnectableView::m_input_ports.

Referenced by ILayerView::updateLabel().

◆ getItem()

◆ getLabel()

virtual QString ILayerView::getLabel ( ) const
inlinevirtualinherited

Reimplemented from ConnectableView.

Definition at line 33 of file ILayerView.h.

33 { return ""; }

◆ getMultiLayerCandidate()

MultiLayerCandidate ILayerView::getMultiLayerCandidate ( )
privateinherited

Finds candidate (another MultiLayer) into which we will move our ILayerView.

To become the candidate, the bounding rectangles of MultiLayerView and given ILayerView should intersects and ILayerView center should be near appropriate drop area. If more than one candidate is found, they will be sorted according to the distance between drop area and ILayerVIew center

Definition at line 222 of file ILayerView.cpp.

223 {
224  QVector<MultiLayerCandidate> candidates;
225 
226  QRectF layerRect = mapRectToScene(boundingRect());
227  for (auto item : scene()->items()) {
228  if (item->type() == ViewTypes::MULTILAYER && item != this && !childItems().contains(item)) {
229  MultiLayerView* multilayer = qgraphicsitem_cast<MultiLayerView*>(item);
230  if (multilayer->mapRectToScene(multilayer->boundingRect()).intersects(layerRect)) {
231  MultiLayerCandidate candidate;
232 
233  // calculate row number to drop ILayerView and distance to the nearest droping area
234  int row = multilayer->getDropArea(multilayer->mapFromScene(layerRect.center()));
235  QRectF droparea = multilayer->mapRectToScene(multilayer->getDropAreaRectangle(row));
236  int distance =
237  std::abs(static_cast<int>(droparea.center().y() - layerRect.center().y()));
238 
239  candidate.multilayer = multilayer;
240  candidate.row = row;
241  candidate.distance = distance;
242  candidates.push_back(candidate);
243  }
244  }
245  }
246  // sorting MultiLayerView candidates to find one whose drop area is closer
247  if (!candidates.empty()) {
248  std::sort(candidates.begin(), candidates.end());
249  return candidates.back();
250  }
251  return MultiLayerCandidate();
252 }
virtual QRectF boundingRect() const
Class to hold MultiLayer candidate for dropping LayerView.
Definition: ILayerView.h:55
int row
requested row number to drop in
Definition: ILayerView.h:59
MultiLayerView * multilayer
pointer to the candidate
Definition: ILayerView.h:58
int distance
distance from given ILayerView and drop area
Definition: ILayerView.h:60
Class representing view of MultiLayer.
int getDropArea(QPointF pos)
Returns index of drop area for given coordinate.
QRectF boundingRect() const override
QRectF getDropAreaRectangle(int row)
Returns drop area rectangle corresponding to given row.
@ MULTILAYER
Definition: ViewTypes.h:29

References ConnectableView::boundingRect(), MultiLayerView::boundingRect(), MultiLayerCandidate::distance, MultiLayerView::getDropArea(), MultiLayerView::getDropAreaRectangle(), MultiLayerCandidate::multilayer, ViewTypes::MULTILAYER, and MultiLayerCandidate::row.

Referenced by ILayerView::itemChange(), and ILayerView::mouseReleaseEvent().

Here is the call graph for this function:

◆ getName()

virtual QString ConnectableView::getName ( ) const
inlinevirtualinherited

Definition at line 37 of file ConnectableView.h.

37 { return m_name; }

References ConnectableView::m_name.

◆ getNumberOfInputPorts()

int ConnectableView::getNumberOfInputPorts ( )
protectedvirtualinherited

Definition at line 168 of file ConnectableView.cpp.

169 {
170  return m_input_ports.size();
171 }

References ConnectableView::m_input_ports.

◆ getNumberOfOutputPorts()

int ConnectableView::getNumberOfOutputPorts ( )
protectedvirtualinherited

Definition at line 163 of file ConnectableView.cpp.

164 {
165  return m_output_ports.size();
166 }

References ConnectableView::m_output_ports.

Referenced by ConnectableView::setPortCoordinates().

◆ getNumberOfPorts()

int ConnectableView::getNumberOfPorts ( )
protectedvirtualinherited

Definition at line 158 of file ConnectableView.cpp.

159 {
160  return m_input_ports.size() + m_output_ports.size();
161 }

References ConnectableView::m_input_ports, and ConnectableView::m_output_ports.

Referenced by ConnectableView::setPortCoordinates().

◆ getOutputPorts()

QList<NodeEditorPort*> ConnectableView::getOutputPorts ( )
inlineinherited

Definition at line 52 of file ConnectableView.h.

52 { return m_output_ports; }

References ConnectableView::m_output_ports.

Referenced by ConnectableView::connectInputPort().

◆ getRectangle()

virtual QRectF ConnectableView::getRectangle ( ) const
inlinevirtualinherited

◆ hyphenate()

QString ConnectableView::hyphenate ( const QString &  name) const
privateinherited

Definition at line 179 of file ConnectableView.cpp.

180 {
181  QRegExp capital_letter("[A-Z]");
182  QRegExp number("[0-9]");
183  int next_capital = capital_letter.indexIn(name, 1);
184  int next_number = number.indexIn(name, 1);
185  if (next_capital > 0 && next_capital < name.size() - 2) {
186  int first_split_index =
187  (next_number > 0 && next_number < next_capital) ? next_number : next_capital;
188  QString result = name.left(first_split_index) + QString("\n")
189  + name.right(name.size() - first_split_index);
190  return result;
191  }
192  return name;
193 }

References RealSpace::Particles::name().

Referenced by ConnectableView::update_appearance().

Here is the call graph for this function:

◆ itemChange()

QVariant ILayerView::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
protectedinherited

Detects movement of the ILayerView and sends possible drop areas to GraphicsScene for visualization.

Definition at line 122 of file ILayerView.cpp.

123 {
124  if (change == ItemPositionChange && scene()) {
125 
126  MultiLayerCandidate multilayerCandidate = getMultiLayerCandidate();
127  if (multilayerCandidate) {
128  DesignerScene* designerScene = dynamic_cast<DesignerScene*>(scene());
129  designerScene->setLayerInterfaceLine(multilayerCandidate.getInterfaceToScene());
130  }
131  }
132  return QGraphicsItem::itemChange(change, value);
133 }
Main class which represents SessionModel on graphics scene.
Definition: DesignerScene.h:37
void setLayerInterfaceLine(const QLineF &line={})
Definition: DesignerScene.h:68
MultiLayerCandidate getMultiLayerCandidate()
Finds candidate (another MultiLayer) into which we will move our ILayerView.
Definition: ILayerView.cpp:222
QLineF getInterfaceToScene()
returns line representing interface of multilayer in scene coordinates
Definition: ILayerView.cpp:24

References MultiLayerCandidate::getInterfaceToScene(), ILayerView::getMultiLayerCandidate(), and DesignerScene::setLayerInterfaceLine().

Here is the call graph for this function:

◆ mousePressEvent()

void ILayerView::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protectedinherited

Definition at line 135 of file ILayerView.cpp.

136 {
137  if (event->button() == Qt::LeftButton) {
138  m_drag_start_position = pos();
139  }
140  QGraphicsItem::mousePressEvent(event);
141 }
QPointF m_drag_start_position
Definition: ILayerView.h:51

References ILayerView::m_drag_start_position.

◆ mouseReleaseEvent()

void ILayerView::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
protectedinherited

Detects possible MultiLayerView's to drop given ILayerView and propagate request to SessionModel.

Definition at line 145 of file ILayerView.cpp.

146 {
147  DesignerScene* designerScene = dynamic_cast<DesignerScene*>(scene());
148  ASSERT(designerScene);
149  designerScene->setLayerInterfaceLine(); // removing drop area hint from the scene
150 
151  if (QLineF(m_drag_start_position, pos()).length() == 0) {
152  QGraphicsItem::mouseReleaseEvent(event);
153  return;
154  }
155 
157  MultiLayerView* requested_parent = candidate.multilayer;
158  int requested_row = candidate.row;
159 
160  // Simple move of single layer on the scene
161  if (!requested_parent && !parentItem()) {
162  QGraphicsItem::mouseReleaseEvent(event);
163  return;
164  }
165 
166  // Layer was moved on top of MultiLayer but not in the right drop area:
167  // returning layer back to starting position.
168  if (requested_parent && requested_row == -1) {
169  setPos(m_drag_start_position);
170  QGraphicsItem::mouseReleaseEvent(event);
171  return;
172  }
173 
174  SampleModel* model = designerScene->getSampleModel();
175 
176  // Layer was moved only slightly, to the same row of his own MultiLayer: returning back.
177  if (requested_parent == parentItem()
178  && requested_row == getItem()->parent()->getItems().indexOf(getItem())) {
179  setPos(m_drag_start_position);
180  QGraphicsItem::mouseReleaseEvent(event);
181  return;
182  }
183 
184  // Layer was moved from MultiLayer it belongs to, to an empty place of
185  // the scene: changing ownership.
186  if (parentItem() && !requested_parent) {
187  QPointF newPos = mapToScene(event->pos()) - event->pos();
188  this->getItem()->setItemValue(SessionGraphicsItem::P_XPOS, newPos.x());
189  this->getItem()->setItemValue(SessionGraphicsItem::P_YPOS, newPos.y());
190 
191  model->moveItem(this->getItem(), nullptr);
192  QGraphicsItem::mouseReleaseEvent(event);
193  return;
194  }
195 
196  // Layer was moved either from one MultiLayer to another, or is moved inside
197  // one multilayer: changing ownership or row within same ownership.
198  if (requested_parent) {
199  model->moveItem(this->getItem(), requested_parent->getItem(), requested_row);
200  QGraphicsItem::mouseReleaseEvent(event);
201  return;
202  }
203 
204  // throw only happens when not all cases were considered previously
205  throw GUIHelpers::Error("LayerView::mouseReleaseEvent() -> Loggic error.");
206 }
SampleModel * getSampleModel()
Definition: DesignerScene.h:49
virtual SessionItem * getItem()
Definition: IView.h:59
Main model to hold sample items.
Definition: SampleModel.h:24
static const QString P_XPOS
static const QString P_YPOS
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
SessionItem * moveItem(SessionItem *item, SessionItem *new_parent=0, int row=-1, const QString &tag="")
Move given parameterized item to the new_parent at given row.

References ASSERT, IView::getItem(), ILayerView::getMultiLayerCandidate(), DesignerScene::getSampleModel(), ILayerView::m_drag_start_position, SessionModel::moveItem(), MultiLayerCandidate::multilayer, SessionGraphicsItem::P_XPOS, SessionGraphicsItem::P_YPOS, MultiLayerCandidate::row, SessionItem::setItemValue(), and DesignerScene::setLayerInterfaceLine().

Here is the call graph for this function:

◆ onChangedX

void IView::onChangedX ( )
virtualslotinherited

Definition at line 55 of file IView.cpp.

56 {
57  if (!m_item)
58  return;
60 }

References IView::m_item, SessionGraphicsItem::P_XPOS, and SessionItem::setItemValue().

Referenced by IView::IView().

Here is the call graph for this function:

◆ onChangedY

void IView::onChangedY ( )
virtualslotinherited

Definition at line 62 of file IView.cpp.

63 {
64  if (!m_item)
65  return;
67 }

References IView::m_item, SessionGraphicsItem::P_YPOS, and SessionItem::setItemValue().

Referenced by IView::IView().

Here is the call graph for this function:

◆ onPropertyChange

void ILayerView::onPropertyChange ( const QString &  propertyName)
slotinherited

Propagates change of 'Thickness' dynamic property to screen thickness of ILayerView.

Definition at line 51 of file ILayerView.cpp.

52 {
53  if (propertyName == LayerItem::P_THICKNESS) {
54  updateHeight();
55  } else if (propertyName == LayerItem::P_MATERIAL) {
56  updateColor();
57  updateLabel();
58  }
59 
60  IView::onPropertyChange(propertyName);
61 }
void updateColor()
Definition: ILayerView.cpp:74
void updateLabel()
Definition: ILayerView.cpp:88
void updateHeight()
Definition: ILayerView.cpp:63
virtual void onPropertyChange(const QString &propertyName)
Definition: IView.cpp:75
static const QString P_MATERIAL
Definition: LayerItem.h:24
static const QString P_THICKNESS
Definition: LayerItem.h:22

References IView::onPropertyChange(), LayerItem::P_MATERIAL, LayerItem::P_THICKNESS, ILayerView::updateColor(), ILayerView::updateHeight(), and ILayerView::updateLabel().

Here is the call graph for this function:

◆ onSiblingsChange()

void IView::onSiblingsChange ( )
protectedvirtualinherited

Definition at line 85 of file IView.cpp.

86 {
88 }
virtual void update_appearance()
updates visual appearance of the item (color, icons, size etc)
Definition: IView.cpp:70

References IView::update_appearance().

Referenced by IView::setParameterizedItem().

Here is the call graph for this function:

◆ paint()

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

Reimplemented from ConnectableView.

Definition at line 33 of file LayerView.cpp.

34 {
35  Q_UNUSED(widget);
36 
37  painter->setPen(Qt::black);
38  if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) {
39  painter->setPen(Qt::DashLine);
40  }
42  painter->drawRect(getRectangle());
43 }
static QGradient getLayerGradient(const QColor &color, const QRectF &rect)

References DesignerHelper::getLayerGradient(), ConnectableView::getRectangle(), and ConnectableView::m_color.

Here is the call graph for this function:

◆ setColor()

◆ setLabel()

void ConnectableView::setLabel ( const QString &  name)
virtualinherited

Definition at line 84 of file ConnectableView.cpp.

85 {
86  m_label = name;
88 }

References ConnectableView::m_label, RealSpace::Particles::name(), and ConnectableView::setPortCoordinates().

Referenced by ConnectableView::update_appearance().

Here is the call graph for this function:

◆ setName()

◆ setParameterizedItem()

void IView::setParameterizedItem ( SessionItem item)
virtualinherited

Definition at line 31 of file IView.cpp.

32 {
33  ASSERT(item);
34  ASSERT(m_item == nullptr);
35 
36  if (toolTip().isEmpty())
37  setToolTip(item->toolTip());
38 
39  m_item = item;
42 
43  m_item->mapper()->setOnPropertyChange([this](const QString& name) { onPropertyChange(name); },
44  this);
45 
46  m_item->mapper()->setOnSiblingsChange([this]() { onSiblingsChange(); }, this);
47 
48  m_item->mapper()->setOnItemDestroy([this](SessionItem*) { m_item = 0; }, this);
49 
51 }
virtual void onSiblingsChange()
Definition: IView.cpp:85
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=0)
Definition: ModelMapper.cpp:87
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=0)
Definition: ModelMapper.cpp:35
void setOnSiblingsChange(std::function< void(void)> f, const void *caller=0)
Definition: ModelMapper.cpp:73
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
QString toolTip() const

References ASSERT, SessionItem::getItemValue(), IView::m_item, SessionItem::mapper(), RealSpace::Particles::name(), IView::onPropertyChange(), IView::onSiblingsChange(), SessionGraphicsItem::P_XPOS, SessionGraphicsItem::P_YPOS, ModelMapper::setOnItemDestroy(), ModelMapper::setOnPropertyChange(), ModelMapper::setOnSiblingsChange(), SessionItem::toolTip(), and IView::update_appearance().

Referenced by DesignerScene::addViewForItem().

Here is the call graph for this function:

◆ setPortCoordinates()

void ConnectableView::setPortCoordinates ( )
protectedvirtualinherited

Definition at line 120 of file ConnectableView.cpp.

121 {
122  if (!getNumberOfPorts())
123  return;
124 
125  // without main label ports can be placed over all rectangle vertical space
126  double hspace = getRectangle().height();
127  if (!getLabel().isEmpty())
128  hspace -= m_label_vspace;
129 
130  double nintervals =
131  getNumberOfPorts() + 2; // one spare interval for margin between input/output ports
132 
133  double dy = hspace / double(nintervals);
134  double ypos = getRectangle().height() - hspace + dy;
135 
136  if (getNumberOfPorts() == 1) {
137  // if total number of ports is 1, place it in the middle
138  ypos = getRectangle().height() - hspace + hspace / 2;
139  }
140  int nOutPorts = getNumberOfOutputPorts();
141  int nport(0);
142  for (QGraphicsItem* item : childItems()) {
143  NodeEditorPort* port = dynamic_cast<NodeEditorPort*>(item);
144  if (!port)
145  continue;
146  if (port->isOutput()) {
147  port->setPos(getRectangle().width(), ypos);
148  } else {
149  if (nport == nOutPorts && nOutPorts != 0)
150  ypos += dy; // additional margin between output and input ports
151  port->setPos(0.0, ypos);
152  }
153  ypos += dy;
154  nport++;
155  }
156 }
virtual QString getLabel() const
virtual int getNumberOfPorts()
virtual int getNumberOfOutputPorts()

References ConnectableView::getLabel(), ConnectableView::getNumberOfOutputPorts(), ConnectableView::getNumberOfPorts(), ConnectableView::getRectangle(), NodeEditorPort::isOutput(), and ConnectableView::m_label_vspace.

Referenced by ConnectableView::addPort(), ConnectableView::setLabel(), and ILayerView::updateHeight().

Here is the call graph for this function:

◆ setRectangle()

◆ type()

virtual int LayerView::type ( ) const
inlinevirtual

Definition at line 26 of file LayerView.h.

26 { return ViewTypes::LAYER; }

References ViewTypes::LAYER.

◆ update_appearance()

void ILayerView::update_appearance ( )
protectedvirtualinherited

updates visual appearance of the item (color, icons, size etc)

Reimplemented from ConnectableView.

Definition at line 208 of file ILayerView.cpp.

209 {
210  updateHeight();
211  updateColor();
212  updateLabel();
214 }
virtual void update_appearance()
updates visual appearance of the item (color, icons, size etc)

References ConnectableView::update_appearance(), ILayerView::updateColor(), ILayerView::updateHeight(), and ILayerView::updateLabel().

Here is the call graph for this function:

◆ updateColor()

void ILayerView::updateColor ( )
privateinherited

Definition at line 74 of file ILayerView.cpp.

75 {
78  if (v.isValid()) {
79  ExternalProperty mp = v.value<ExternalProperty>();
80  setColor(mp.color());
81  update();
82  } else {
83  ASSERT(0);
84  }
85  }
86 }
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QColor color() const
bool isTag(const QString &name) const
Returns true if tag is available.

References ASSERT, ExternalProperty::color(), SessionItem::getItemValue(), SessionItem::isTag(), IView::m_item, LayerItem::P_MATERIAL, and ConnectableView::setColor().

Referenced by ILayerView::onPropertyChange(), and ILayerView::update_appearance().

Here is the call graph for this function:

◆ updateHeight()

void ILayerView::updateHeight ( )
privateinherited

Definition at line 63 of file ILayerView.cpp.

64 {
69  update();
70  emit heightChanged();
71  }
72 }
static int nanometerToScreen(double nanometer)
non-linear conversion of layer's thickness in nanometers to screen size to have reasonable graphics r...

References SessionItem::getItemValue(), SessionItem::isTag(), IView::m_item, ConnectableView::m_rect, DesignerHelper::nanometerToScreen(), LayerItem::P_THICKNESS, and ConnectableView::setPortCoordinates().

Referenced by ILayerView::onPropertyChange(), and ILayerView::update_appearance().

Here is the call graph for this function:

◆ updateLabel()

void ILayerView::updateLabel ( )
inherited

Definition at line 88 of file ILayerView.cpp.

89 {
90  if (getInputPorts().size() < 1)
91  return;
92 
93  NodeEditorPort* port = getInputPorts()[0];
94 
95  QString material = "";
98  if (v.isValid()) {
99  ExternalProperty mp = v.value<ExternalProperty>();
100  material = mp.text();
101  }
102  }
103 
104  /* Thickness and roughness can be added, but the length of the string
105  * becomes prohibitive.
106  QString thickness = "" ;
107  if(m_item->isTag(LayerItem::P_THICKNESS))
108  thickness = m_item->getItemValue(LayerItem::P_THICKNESS).toString();
109 
110  QString roughness = "" ;
111  if(m_item->isTag(LayerItem::P_ROUGHNESS)){
112  QVariant x = m_item->getItemValue(LayerItem::P_ROUGHNESS);
113  {...}
114  }
115  */
116  QString infoToDisplay = material;
117  port->setLabel(infoToDisplay);
118 }
QList< NodeEditorPort * > getInputPorts()
QString text() const
void setLabel(QString name)

References ConnectableView::getInputPorts(), SessionItem::getItemValue(), SessionItem::isTag(), IView::m_item, LayerItem::P_MATERIAL, NodeEditorPort::setLabel(), and ExternalProperty::text().

Referenced by ILayerView::onPropertyChange(), and ILayerView::update_appearance().

Here is the call graph for this function:

Member Data Documentation

◆ m_color

QColor ConnectableView::m_color
protectedinherited

◆ m_drag_start_position

QPointF ILayerView::m_drag_start_position
privateinherited

Definition at line 51 of file ILayerView.h.

Referenced by ILayerView::mousePressEvent(), and ILayerView::mouseReleaseEvent().

◆ m_input_ports

◆ m_item

◆ m_label

QString ConnectableView::m_label
protectedinherited

◆ m_label_vspace

◆ m_name

QString ConnectableView::m_name
protectedinherited

Definition at line 66 of file ConnectableView.h.

Referenced by ConnectableView::getName(), and ConnectableView::setName().

◆ m_output_ports

QList<NodeEditorPort*> ConnectableView::m_output_ports
protectedinherited

◆ m_rect

◆ m_roundpar


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