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

Class representing view of MultiLayer. More...

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

Public Slots

virtual void onChangedX ()
 
virtual void onChangedY ()
 
void onLayerAboutToBeDeleted ()
 
void onPropertyChange (const QString &propertyName)
 Propagates change of 'Thickness' dynamic property to screen thickness of ILayerView. More...
 
void updateGeometry ()
 Updates geometry of MultiLayerView from current childs geometries. More...
 
void updateHeight ()
 Updates MultiLayer height, sets y-positions of children, defines new drop areas. More...
 
void updateWidth ()
 Updates MultiLayerView width, sets x-positions of children. More...
 

Signals

void aboutToBeDeleted ()
 

Public Member Functions

 MultiLayerView (QGraphicsItem *parent=0)
 
 ~MultiLayerView ()
 
virtual void addNewLayer (ILayerView *layer, int row)
 
virtual NodeEditorPortaddPort (const QString &name, NodeEditorPort::EPortDirection direction, NodeEditorPort::EPortType port_type)
 adds port to view More...
 
void addView (IView *childView, int row=0) override
 
QRectF boundingRect () const override
 
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 getDropArea (QPointF pos)
 Returns index of drop area for given coordinate. More...
 
QRectF getDropAreaRectangle (int row)
 Returns drop area rectangle corresponding to given row. More...
 
int getInputPortIndex (NodeEditorPort *port)
 
QList< NodeEditorPort * > getInputPorts ()
 
QLineF getInterfaceLine (int row)
 Returns line representing interface. More...
 
virtual SessionItemgetItem ()
 
virtual QString getLabel () const
 
virtual QString getName () const
 
QList< NodeEditorPort * > getOutputPorts ()
 
virtual QRectF getRectangle () const
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 
virtual void removeLayer (ILayerView *layer)
 
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)
 
int type () const override
 
void updateLabel ()
 

Protected Member Functions

const DesignerMimeDatacheckDragEvent (QGraphicsSceneDragDropEvent *event)
 
void dragMoveEvent (QGraphicsSceneDragDropEvent *event) override
 
void dropEvent (QGraphicsSceneDragDropEvent *event) override
 
virtual int getNumberOfInputPorts ()
 
virtual int getNumberOfOutputPorts ()
 
virtual int getNumberOfPorts ()
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 
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 ()
 

Private Attributes

QPointF m_drag_start_position
 
QList< QRectF > m_drop_areas
 
QList< QLineF > m_interfaces
 
QList< ILayerView * > m_layers
 

Detailed Description

Class representing view of MultiLayer.

Handles drop of other MultiLayer and Layer views on top of it

Definition at line 25 of file MultiLayerView.h.

Constructor & Destructor Documentation

◆ MultiLayerView()

MultiLayerView::MultiLayerView ( QGraphicsItem *  parent = 0)

Definition at line 25 of file MultiLayerView.cpp.

25  : ILayerView(parent)
26 {
27  setColor(QColor(Qt::blue));
28 
30  setAcceptHoverEvents(false);
31  setAcceptDrops(true);
33  connect(this, &MultiLayerView::childrenChanged, this, &MultiLayerView::updateHeight);
34 }
virtual void setColor(const QColor &color)
virtual void setRectangle(QRectF rect)
static QRectF getDefaultBoundingRect(const QString &name)
returns default bounding rectangle for given IvView name
ILayerView(QGraphicsItem *parent=0)
Definition: ILayerView.cpp:43
void updateGeometry()
Updates geometry of MultiLayerView from current childs geometries.
void updateHeight()
Updates MultiLayer height, sets y-positions of children, defines new drop areas.

References DesignerHelper::getDefaultBoundingRect(), ConnectableView::setColor(), ConnectableView::setRectangle(), updateGeometry(), and updateHeight().

Here is the call graph for this function:

◆ ~MultiLayerView()

MultiLayerView::~MultiLayerView ( )

Definition at line 36 of file MultiLayerView.cpp.

37 {
38  // to prevent call on LayerView destruction on final scene shutdown
39  disconnect(this, &MultiLayerView::childrenChanged, this, &MultiLayerView::updateHeight);
40 }

References updateHeight().

Here is the call graph for this function:

Member Function Documentation

◆ aboutToBeDeleted

void IView::aboutToBeDeleted ( )
signalinherited

◆ addNewLayer()

void MultiLayerView::addNewLayer ( ILayerView layer,
int  row 
)
virtual

Definition at line 86 of file MultiLayerView.cpp.

87 {
88  m_layers.insert(row, layer);
89  connect(layer, &ILayerView::heightChanged, this, &MultiLayerView::updateHeight,
90  Qt::UniqueConnection);
92  Qt::UniqueConnection);
93  layer->setParentItem(this);
94 }
void aboutToBeDeleted()
void onLayerAboutToBeDeleted()
QList< ILayerView * > m_layers

References IView::aboutToBeDeleted(), m_layers, onLayerAboutToBeDeleted(), and updateHeight().

Referenced by addView().

Here is the call graph for this function:

◆ 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::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 MultiLayerView::addView ( IView childView,
int  row = 0 
)
overridevirtual

Reimplemented from IView.

Definition at line 66 of file MultiLayerView.cpp.

67 {
68  ILayerView* layer = dynamic_cast<ILayerView*>(childView);
69  ASSERT(layer);
70 
71  if (!childItems().contains(layer)) {
72  addNewLayer(layer, row);
73  } else {
74  int previous_row = m_layers.indexOf(layer);
75  if (previous_row != row) {
76 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
77  m_layers.swapItemsAt(previous_row, row);
78 #else
79  m_layers.swap(previous_row, row);
80 #endif
81  }
82  }
84 }
#define ASSERT(condition)
Definition: Assert.h:31
Base class for LayerView and MultiLayerView Provides functionality for moving view on top of MultiLay...
Definition: ILayerView.h:25
virtual void addNewLayer(ILayerView *layer, int row)

References addNewLayer(), ASSERT, m_layers, and updateGeometry().

Here is the call graph for this function:

◆ boundingRect()

QRectF MultiLayerView::boundingRect ( ) const
overridevirtual

Reimplemented from ConnectableView.

Definition at line 42 of file MultiLayerView.cpp.

43 {
44  QRectF result = m_rect;
45  if (!m_layers.empty()) {
46  qreal toplayer_height = m_layers.front()->boundingRect().height();
47  qreal bottomlayer_height = m_layers.back()->boundingRect().height();
48  result.setTop(-toplayer_height / 2.);
49  result.setHeight(m_rect.height() + (toplayer_height + bottomlayer_height) / 2.);
50  }
51  return result;
52 }

References m_layers, and ConnectableView::m_rect.

Referenced by ILayerView::getMultiLayerCandidate(), updateHeight(), and updateWidth().

◆ checkDragEvent()

const DesignerMimeData * MultiLayerView::checkDragEvent ( QGraphicsSceneDragDropEvent *  event)
protected

Definition at line 233 of file MultiLayerView.cpp.

234 {
235  const DesignerMimeData* mimeData = qobject_cast<const DesignerMimeData*>(event->mimeData());
236  if (!mimeData) {
237  event->ignore();
238  return 0;
239  }
240  int row = getDropArea(event->pos());
241  if (mimeData->hasFormat("bornagain/widget")
242  && getItem()->acceptsAsDefaultItem(mimeData->getClassName()) && row != -1) {
243 
244  event->setAccepted(true);
245  } else {
246  event->setAccepted(false);
247  }
248  return mimeData;
249 }
Mime data for use with SampleDesigner drag and drop operations.
QString getClassName() const
virtual SessionItem * getItem()
Definition: IView.h:59
int getDropArea(QPointF pos)
Returns index of drop area for given coordinate.

References DesignerMimeData::getClassName(), getDropArea(), and IView::getItem().

Referenced by dragMoveEvent(), and dropEvent().

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 LayerView::addView(), MesoCrystalView::addView(), ParticleCompositionView::addView(), ParticleCoreShellView::addView(), ParticleDistributionView::addView(), ParticleLayoutView::addView(), and ParticleView::addView().

Here is the call graph for this function:

◆ dragMoveEvent()

void MultiLayerView::dragMoveEvent ( QGraphicsSceneDragDropEvent *  event)
overrideprotected

Definition at line 213 of file MultiLayerView.cpp.

214 {
215  if (!checkDragEvent(event))
216  QGraphicsItem::dragMoveEvent(event);
217 }
const DesignerMimeData * checkDragEvent(QGraphicsSceneDragDropEvent *event)

References checkDragEvent().

Here is the call graph for this function:

◆ dropEvent()

void MultiLayerView::dropEvent ( QGraphicsSceneDragDropEvent *  event)
overrideprotected

Definition at line 219 of file MultiLayerView.cpp.

220 {
221  const DesignerMimeData* mimeData = checkDragEvent(event);
222  if (mimeData) {
223  DesignerScene* designerScene = dynamic_cast<DesignerScene*>(scene());
224  if (designerScene) {
225  SampleModel* sampleModel = designerScene->getSampleModel();
226 
227  sampleModel->insertNewItem(mimeData->getClassName(), this->getItem(),
228  getDropArea(event->pos()));
229  }
230  }
231 }
Main class which represents SessionModel on graphics scene.
Definition: DesignerScene.h:37
SampleModel * getSampleModel()
Definition: DesignerScene.h:49
Main model to hold sample items.
Definition: SampleModel.h:24
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")

References checkDragEvent(), DesignerMimeData::getClassName(), getDropArea(), IView::getItem(), DesignerScene::getSampleModel(), and SessionModel::insertNewItem().

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.

◆ getDropArea()

int MultiLayerView::getDropArea ( QPointF  pos)

Returns index of drop area for given coordinate.

Definition at line 181 of file MultiLayerView.cpp.

182 {
183  int area(-1);
184  for (int i = 0; i < m_drop_areas.size(); ++i) {
185  if (m_drop_areas.at(i).contains(pos)) {
186  area = i;
187  break;
188  }
189  }
190  return area;
191 }
QList< QRectF > m_drop_areas

References m_drop_areas.

Referenced by checkDragEvent(), dropEvent(), and ILayerView::getMultiLayerCandidate().

◆ getDropAreaRectangle()

QRectF MultiLayerView::getDropAreaRectangle ( int  row)

Returns drop area rectangle corresponding to given row.

Definition at line 194 of file MultiLayerView.cpp.

195 {
196  if (row >= 0 && row < m_drop_areas.size()) {
197  return m_drop_areas[row];
198  } else {
199  return QRectF();
200  }
201 }

References m_drop_areas.

Referenced by ILayerView::getMultiLayerCandidate().

◆ 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().

◆ getInterfaceLine()

QLineF MultiLayerView::getInterfaceLine ( int  row)

Returns line representing interface.

Definition at line 204 of file MultiLayerView.cpp.

205 {
206  if (row >= 0 && row < m_interfaces.size()) {
207  return m_interfaces[row];
208  } else {
209  return QLineF();
210  }
211 }
QList< QLineF > m_interfaces

References m_interfaces.

Referenced by MultiLayerCandidate::getInterfaceToScene().

◆ 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.
QRectF boundingRect() const override
QRectF getDropAreaRectangle(int row)
Returns drop area rectangle corresponding to given row.
@ MULTILAYER
Definition: ViewTypes.h:29

References ConnectableView::boundingRect(), boundingRect(), MultiLayerCandidate::distance, getDropArea(), 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 MultiLayerView::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
overrideprotected

Definition at line 251 of file MultiLayerView.cpp.

252 {
253  return QGraphicsItem::itemChange(change, value);
254 }

◆ 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 }
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
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:

◆ onLayerAboutToBeDeleted

void MultiLayerView::onLayerAboutToBeDeleted ( )
slot

Definition at line 96 of file MultiLayerView.cpp.

97 {
98  ILayerView* layer = qobject_cast<ILayerView*>(sender());
99  ASSERT(layer);
100  removeLayer(layer);
101 }
virtual void removeLayer(ILayerView *layer)

References ASSERT, and removeLayer().

Referenced by addNewLayer(), and removeLayer().

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 MultiLayerView::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
overridevirtual

Reimplemented from ConnectableView.

Definition at line 54 of file MultiLayerView.cpp.

56 {
57  Q_UNUSED(widget);
58  painter->setPen(m_color);
59  if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) {
60  painter->setPen(Qt::DashLine);
61  }
63  painter->drawRect(getRectangle());
64 }
virtual QRectF getRectangle() const
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:

◆ removeLayer()

void MultiLayerView::removeLayer ( ILayerView layer)
virtual

Definition at line 103 of file MultiLayerView.cpp.

104 {
105  ASSERT(m_layers.contains(layer));
106  disconnect(layer, &ILayerView::heightChanged, this, &MultiLayerView::updateHeight);
107  disconnect(layer, &ILayerView::aboutToBeDeleted, this,
109  m_layers.removeOne(layer);
110  updateGeometry();
111 }

References IView::aboutToBeDeleted(), ASSERT, m_layers, onLayerAboutToBeDeleted(), updateGeometry(), and updateHeight().

Referenced by onLayerAboutToBeDeleted().

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()

int MultiLayerView::type ( ) const
inlineoverride

Definition at line 32 of file MultiLayerView.h.

32 { return ViewTypes::MULTILAYER; }

References ViewTypes::MULTILAYER.

◆ 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:

◆ updateGeometry

void MultiLayerView::updateGeometry ( )
slot

Updates geometry of MultiLayerView from current childs geometries.

Definition at line 114 of file MultiLayerView.cpp.

115 {
116  updateHeight();
117  updateWidth();
118 }
void updateWidth()
Updates MultiLayerView width, sets x-positions of children.

References updateHeight(), and updateWidth().

Referenced by MultiLayerView(), addView(), and removeLayer().

Here is the call graph for this function:

◆ updateHeight

void MultiLayerView::updateHeight ( )
slot

Updates MultiLayer height, sets y-positions of children, defines new drop areas.

Definition at line 121 of file MultiLayerView.cpp.

122 {
123  // drop areas are rectangles covering the area of layer interfaces
124  m_drop_areas.clear();
125  m_interfaces.clear();
126 
127  int total_height = 0;
128  if (!m_layers.empty()) {
129  for (ILayerView* layer : m_layers) {
130  layer->setY(total_height);
131  layer->update();
132  qreal drop_area_height = layer->boundingRect().height();
133  qreal drop_area_ypos = total_height - drop_area_height / 2.;
134  m_drop_areas.append(
135  QRectF(0, drop_area_ypos, boundingRect().width(), drop_area_height));
136  m_interfaces.append(QLineF(m_rect.left(), total_height, m_rect.right(), total_height));
137  total_height += layer->boundingRect().height();
138  }
139  qreal drop_area_height = m_layers.back()->boundingRect().height();
140  qreal drop_area_ypos = total_height - drop_area_height / 2.;
141  m_drop_areas.append(QRectF(0, drop_area_ypos, boundingRect().width(), drop_area_height));
142  m_interfaces.append(QLineF(m_rect.left(), total_height, m_rect.right(), total_height));
143  } else {
144  total_height = DesignerHelper::getDefaultMultiLayerRect().height();
145  m_drop_areas.append(boundingRect());
146  m_interfaces.append(
147  QLineF(m_rect.left(), m_rect.center().y(), m_rect.right(), m_rect.center().y()));
148  }
149  m_rect.setHeight(total_height);
150  update();
151  emit heightChanged();
152 }
static QRectF getDefaultMultiLayerRect()

References boundingRect(), DesignerHelper::getDefaultMultiLayerRect(), m_drop_areas, m_interfaces, m_layers, and ConnectableView::m_rect.

Referenced by MultiLayerView(), ~MultiLayerView(), addNewLayer(), removeLayer(), and updateGeometry().

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:

◆ updateWidth

void MultiLayerView::updateWidth ( )
slot

Updates MultiLayerView width, sets x-positions of children.

If list of children contains another MultiLayer, then width of given MultiLayer will be increased by 12%

Definition at line 157 of file MultiLayerView.cpp.

158 {
159  const double wider_than_children(1.15);
160  double max_width(0);
161  for (ILayerView* layer : m_layers) {
162  if (layer->boundingRect().width() > max_width)
163  max_width = layer->boundingRect().width();
164  }
165  max_width *= wider_than_children;
166  if (max_width == 0) {
167  max_width = DesignerHelper::getDefaultMultiLayerRect().width();
168  }
169  m_rect.setWidth(max_width);
170  update();
171 
172  for (ILayerView* layer : m_layers) {
173  int xpos = ((boundingRect().width() - layer->boundingRect().width())) / 2.;
174  layer->setX(xpos);
175  layer->update();
176  }
177  emit widthChanged();
178 }

References boundingRect(), DesignerHelper::getDefaultMultiLayerRect(), m_layers, and ConnectableView::m_rect.

Referenced by updateGeometry().

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_drop_areas

QList<QRectF> MultiLayerView::m_drop_areas
private

Definition at line 61 of file MultiLayerView.h.

Referenced by getDropArea(), getDropAreaRectangle(), and updateHeight().

◆ m_input_ports

◆ m_interfaces

QList<QLineF> MultiLayerView::m_interfaces
private

Definition at line 62 of file MultiLayerView.h.

Referenced by getInterfaceLine(), and updateHeight().

◆ m_item

◆ m_label

QString ConnectableView::m_label
protectedinherited

◆ m_label_vspace

◆ m_layers

QList<ILayerView*> MultiLayerView::m_layers
private

◆ 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

QRectF ConnectableView::m_rect
protectedinherited

◆ m_roundpar


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