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

Main class which represents SessionModel on graphics scene. More...

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

Public Slots

void deleteSelectedItems ()
 propagates deletion of views on the scene to the model More...
 
void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 handles drag event LayerView can be dragged only over MultiLayerView MultiLayerView can be dragged both, over the scene and over another MultiLayerView More...
 
void dropEvent (QGraphicsSceneDragDropEvent *event)
 Hadles drop event LayerView can be dropped on MultiLayerView only MultiLayerView can be droped on the scene or another MultiLayerView. More...
 
void onEstablishedConnection (NodeEditorConnection *)
 propagates connection established by NodeEditor to the model More...
 
void onRowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void onRowsInserted (const QModelIndex &parent, int first, int last)
 
void onRowsRemoved (const QModelIndex &parent, int first, int last)
 
void onSceneSelectionChanged ()
 propagate selection from scene to model More...
 
void onSessionSelectionChanged (const QItemSelection &, const QItemSelection &)
 propagate selection from model to scene More...
 
void onSmartAlign ()
 
void removeConnection (NodeEditorConnection *)
 propagates break of connection between views on scene to the model More...
 
void resetScene ()
 
void setLayerInterfaceLine (const QLineF &line={})
 
void updateScene ()
 

Signals

void selectionModeChangeRequest (int)
 

Public Member Functions

 DesignerScene (QObject *parent=0)
 
virtual ~DesignerScene ()
 
NodeEditorgetNodeEditor ()
 
SampleModelgetSampleModel ()
 
IViewgetViewForItem (SessionItem *item)
 
void setInstrumentModel (InstrumentModel *instrumentModel)
 
void setMaterialModel (MaterialModel *materialModel)
 
void setSampleModel (SampleModel *sampleModel)
 
void setSelectionModel (QItemSelectionModel *model, FilterPropertyProxy *proxy)
 

Protected Member Functions

const DesignerMimeDatacheckDragEvent (QGraphicsSceneDragDropEvent *event)
 returns proper MimeData if the object can be hadled by graphics scene More...
 
void drawForeground (QPainter *painter, const QRectF &rect)
 shows appropriate layer interface to drop while moving ILayerView More...
 
void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 

Private Member Functions

IViewaddViewForItem (SessionItem *item)
 adds view for item, if it doesn't exists More...
 
void adjustSceneRect ()
 
void alignViews ()
 aligns SampleView's on graphical canvas More...
 
void deleteViews (const QModelIndex &parentIndex)
 runs recursively through model's item and schedules view removal More...
 
bool isAcceptedByMultiLayer (const DesignerMimeData *mimeData, QGraphicsSceneDragDropEvent *event)
 
bool isLayerDragged () const
 
bool isMultiLayerNearby (QGraphicsSceneDragDropEvent *event)
 Returns true if there is MultiLayerView nearby during drag event. More...
 
void removeItemViewFromScene (SessionItem *item)
 removes view from scene corresponding to given item More...
 
void updateViews (const QModelIndex &parentIndex={}, IView *parentView=0)
 runs through all items recursively and updates corresponding views More...
 

Private Attributes

SampleViewAlignerm_aligner
 
bool m_block_selection
 
InstrumentModelm_instrumentModel
 
QMap< SessionItem *, IView * > m_ItemToView
 Correspondance of model's item and scene's view. More...
 
QLineF m_layer_interface_line
 Foreground line representing appropriate interface during layer's movement. More...
 
MaterialModelm_materialModel
 
NodeEditorm_nodeEditor
 
FilterPropertyProxym_proxy
 
SampleModelm_sampleModel
 
QItemSelectionModel * m_selectionModel
 

Detailed Description

Main class which represents SessionModel on graphics scene.

Definition at line 37 of file DesignerScene.h.

Constructor & Destructor Documentation

◆ DesignerScene()

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

Definition at line 37 of file DesignerScene.cpp.

38  : QGraphicsScene(parent)
39  , m_sampleModel(0)
41  , m_materialModel(0)
42  , m_selectionModel(0)
43  , m_proxy(0)
44  , m_block_selection(false)
45  , m_aligner(new SampleViewAligner(this))
46 {
47  setSceneRect(QRectF(-1600, 0, 3200, 3200));
48  setBackgroundBrush(DesignerHelper::getSceneBackground());
49 
50  m_nodeEditor = new NodeEditor(parent);
51  m_nodeEditor->install(this);
56  connect(this, &DesignerScene::selectionChanged, this, &DesignerScene::onSceneSelectionChanged);
57 }
static QPixmap getSceneBackground()
bool m_block_selection
void selectionModeChangeRequest(int)
SampleModel * m_sampleModel
QItemSelectionModel * m_selectionModel
SampleViewAligner * m_aligner
void onSceneSelectionChanged()
propagate selection from scene to model
FilterPropertyProxy * m_proxy
NodeEditor * m_nodeEditor
InstrumentModel * m_instrumentModel
void onEstablishedConnection(NodeEditorConnection *)
propagates connection established by NodeEditor to the model
MaterialModel * m_materialModel
The NodeEditor class implement for QGraphicsScene an editable schematic of the dependency graph,...
Definition: NodeEditor.h:35
void connectionIsEstablished(NodeEditorConnection *)
void install(QGraphicsScene *scene)
Definition: NodeEditor.cpp:25
void selectionModeChangeRequest(int)
Makes alignment of sample droped on graphics scene.

References NodeEditor::connectionIsEstablished(), DesignerHelper::getSceneBackground(), NodeEditor::install(), m_nodeEditor, onEstablishedConnection(), onSceneSelectionChanged(), selectionModeChangeRequest(), and NodeEditor::selectionModeChangeRequest().

Here is the call graph for this function:

◆ ~DesignerScene()

DesignerScene::~DesignerScene ( )
virtual

Definition at line 59 of file DesignerScene.cpp.

60 {
61  delete m_aligner;
62 }

References m_aligner.

Member Function Documentation

◆ addViewForItem()

IView * DesignerScene::addViewForItem ( SessionItem item)
private

adds view for item, if it doesn't exists

Definition at line 243 of file DesignerScene.cpp.

244 {
245  ASSERT(item);
246 
247  IView* view = getViewForItem(item);
248 
249  if (!view) {
251  if (view) {
252  m_ItemToView[item] = view;
253  view->setParameterizedItem(item);
254  addItem(view);
255  return view;
256  }
257  } else {
258  // view for item exists
259  }
260  return view;
261 }
#define ASSERT(condition)
Definition: Assert.h:31
IView * getViewForItem(SessionItem *item)
QMap< SessionItem *, IView * > m_ItemToView
Correspondance of model's item and scene's view.
parent class for graphic representation of all ISampleNode's
Definition: IView.h:25
virtual void setParameterizedItem(SessionItem *item)
Definition: IView.cpp:31
static IView * createSampleView(const QString &name)
QString modelType() const
Get model type.

References ASSERT, SampleViewFactory::createSampleView(), getViewForItem(), m_ItemToView, SessionItem::modelType(), and IView::setParameterizedItem().

Referenced by updateViews().

Here is the call graph for this function:

◆ adjustSceneRect()

void DesignerScene::adjustSceneRect ( )
private

Definition at line 477 of file DesignerScene.cpp.

478 {
479  QRectF boundingRect = itemsBoundingRect();
480  if (sceneRect().contains(boundingRect))
481  return;
482 
483  boundingRect.adjust(20.0, 20.0, 20.0, 20.0);
484  setSceneRect(sceneRect().united(boundingRect));
485 }

Referenced by dropEvent().

◆ alignViews()

void DesignerScene::alignViews ( )
private

aligns SampleView's on graphical canvas

Definition at line 264 of file DesignerScene.cpp.

265 {
266  m_aligner->alignSample(QModelIndex(), QPointF(200, 800));
267 }
void alignSample(SessionItem *item, QPointF reference={}, bool force_alignment=false)
Aligns sample starting from.

References SampleViewAligner::alignSample(), and m_aligner.

Referenced by updateScene().

Here is the call graph for this function:

◆ checkDragEvent()

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

returns proper MimeData if the object can be hadled by graphics scene

Definition at line 446 of file DesignerScene.cpp.

447 {
448  const DesignerMimeData* mimeData = qobject_cast<const DesignerMimeData*>(event->mimeData());
449  if (!mimeData) {
450  event->ignore();
451  return 0;
452  }
453  event->setAccepted(true);
454  return mimeData;
455 }
Mime data for use with SampleDesigner drag and drop operations.

Referenced by dragMoveEvent(), and dropEvent().

◆ deleteSelectedItems

void DesignerScene::deleteSelectedItems ( )
slot

propagates deletion of views on the scene to the model

Definition at line 307 of file DesignerScene.cpp.

308 {
309  QModelIndexList indexes = m_selectionModel->selectedIndexes();
310 
311  QList<IView*> views_which_will_be_deleted;
312  for (auto index : indexes) {
313  views_which_will_be_deleted.append(
314  m_ItemToView[m_sampleModel->itemForIndex(m_proxy->mapToSource(index))]);
315  }
316  // deleting selected items on model side, corresponding views will be deleted automatically
317  // Since we don't know the order of items and their parent/child relationship, we need this
318  while (indexes.size()) {
319  QModelIndex current = m_proxy->mapToSource(indexes.back());
320  m_sampleModel->removeRows(current.row(), 1, current.parent());
321  indexes = m_selectionModel->selectedIndexes();
322  }
323  // Connections will be deleted automatically if one of connected views has been deleted.
324  // For the moment, we have to delete connections which are: 1) were selected 2) Do not connect
325  // views scheduled for deletion.
326  for (auto graphicsItem : selectedItems()) {
327  if (NodeEditorConnection* connection = dynamic_cast<NodeEditorConnection*>(graphicsItem)) {
328  if (views_which_will_be_deleted.contains(connection->getParentView())
329  || views_which_will_be_deleted.contains(connection->getChildView()))
330  continue;
331  removeConnection(connection);
332  }
333  }
334 }
void removeConnection(NodeEditorConnection *)
propagates break of connection between views on scene to the model
SessionItem * itemForIndex(const QModelIndex &index) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)

References SessionModel::itemForIndex(), m_ItemToView, m_proxy, m_sampleModel, m_selectionModel, removeConnection(), and SessionModel::removeRows().

Referenced by DesignerView::deleteSelectedItems().

Here is the call graph for this function:

◆ deleteViews()

void DesignerScene::deleteViews ( const QModelIndex &  parentIndex)
private

runs recursively through model's item and schedules view removal

Definition at line 270 of file DesignerScene.cpp.

271 {
272  for (int i_row = 0; i_row < m_sampleModel->rowCount(viewIndex); ++i_row) {
273  QModelIndex itemIndex = m_sampleModel->index(i_row, 0, viewIndex);
274 
275  if (SessionItem* item = m_sampleModel->itemForIndex(itemIndex)) {
277 
278  } else {
279  // not a parameterized graphics item
280  }
281  deleteViews(itemIndex);
282  }
283  removeItemViewFromScene(m_sampleModel->itemForIndex(viewIndex)); // deleting view itself
284 }
void deleteViews(const QModelIndex &parentIndex)
runs recursively through model's item and schedules view removal
void removeItemViewFromScene(SessionItem *item)
removes view from scene corresponding to given item
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const

References SessionModel::index(), SessionModel::itemForIndex(), m_sampleModel, removeItemViewFromScene(), and SessionModel::rowCount().

Referenced by onRowsAboutToBeRemoved().

Here is the call graph for this function:

◆ dragMoveEvent

void DesignerScene::dragMoveEvent ( QGraphicsSceneDragDropEvent *  event)
slot

handles drag event LayerView can be dragged only over MultiLayerView MultiLayerView can be dragged both, over the scene and over another MultiLayerView

Definition at line 385 of file DesignerScene.cpp.

386 {
387  const DesignerMimeData* mimeData = checkDragEvent(event);
388  if (isAcceptedByMultiLayer(mimeData, event)) {
389  QGraphicsScene::dragMoveEvent(event);
390  }
391 }
const DesignerMimeData * checkDragEvent(QGraphicsSceneDragDropEvent *event)
returns proper MimeData if the object can be hadled by graphics scene
bool isAcceptedByMultiLayer(const DesignerMimeData *mimeData, QGraphicsSceneDragDropEvent *event)

References checkDragEvent(), and isAcceptedByMultiLayer().

Here is the call graph for this function:

◆ drawForeground()

void DesignerScene::drawForeground ( QPainter *  painter,
const QRectF &  rect 
)
protected

shows appropriate layer interface to drop while moving ILayerView

Definition at line 337 of file DesignerScene.cpp.

338 {
339  if (isLayerDragged()) {
340  painter->setPen(QPen(Qt::darkBlue, 2, Qt::DashLine));
341  painter->drawLine(m_layer_interface_line);
342  }
343 }
QLineF m_layer_interface_line
Foreground line representing appropriate interface during layer's movement.
bool isLayerDragged() const

References isLayerDragged(), and m_layer_interface_line.

Here is the call graph for this function:

◆ dropEvent

void DesignerScene::dropEvent ( QGraphicsSceneDragDropEvent *  event)
slot

Hadles drop event LayerView can be dropped on MultiLayerView only MultiLayerView can be droped on the scene or another MultiLayerView.

Definition at line 396 of file DesignerScene.cpp.

397 {
398  const DesignerMimeData* mimeData = checkDragEvent(event);
399  if (mimeData) {
400 
401  // to have possibility to drop MultiLayer on another MultiLayer
402  // * edit function DesignerScene::isAcceptedByMultiLayer
403  // * edit MultiLayerItem for addToValidChildren
404  // * remove method MultiLayerView::itemChange
405 
406  if (isAcceptedByMultiLayer(mimeData, event)) {
407  // certain views can be dropped on MultiLayer and so will be processed there
408  QGraphicsScene::dropEvent(event);
409 
410  } else {
411  // other views can be dropped on canvas anywhere
412  if (SampleViewFactory::isValidType(mimeData->getClassName())) {
413 
414  SessionItem* new_item(0);
415  if (mimeData->getClassName().startsWith("FormFactor")) {
416  new_item = m_sampleModel->insertItem<ParticleItem>();
417  QString ffName = mimeData->getClassName();
418  ffName.remove("FormFactor");
419  new_item->setGroupProperty(ParticleItem::P_FORM_FACTOR, ffName);
420 
421  } else {
422  new_item = m_sampleModel->insertNewItem(mimeData->getClassName());
423  }
424 
425  // propagating drop coordinates to SessionItem
426  QRectF boundingRect = DesignerHelper::getDefaultBoundingRect(new_item->modelType());
427  new_item->setItemValue(SessionGraphicsItem::P_XPOS,
428  event->scenePos().x() - boundingRect.width() / 2);
429  new_item->setItemValue(SessionGraphicsItem::P_YPOS,
430  event->scenePos().y() - boundingRect.height() / 2);
431 
432  } else if (GUIExamplesFactory::isValidExampleName(mimeData->getClassName())) {
435  QRectF boundingRect = DesignerHelper::getDefaultBoundingRect(topItem->modelType());
436  QPointF reference(event->scenePos().x() - boundingRect.width() / 2,
437  event->scenePos().y() - boundingRect.height() / 2);
438  m_aligner->alignSample(topItem, reference, true);
439  }
440  adjustSceneRect();
441  }
442  }
443 }
static QRectF getDefaultBoundingRect(const QString &name)
returns default bounding rectangle for given IvView name
QString getClassName() const
void adjustSceneRect()
static SessionItem * createSampleItems(const QString &name, SampleModel *sampleModel, MaterialModel *materialModel)
Populate sample model with.
static bool isValidExampleName(const QString &name)
static const QString P_FORM_FACTOR
Definition: ParticleItem.h:25
static bool isValidType(const QString &name)
static const QString P_XPOS
static const QString P_YPOS
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:125
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")

References adjustSceneRect(), SampleViewAligner::alignSample(), checkDragEvent(), GUIExamplesFactory::createSampleItems(), DesignerMimeData::getClassName(), DesignerHelper::getDefaultBoundingRect(), SessionModel::insertItem(), SessionModel::insertNewItem(), isAcceptedByMultiLayer(), GUIExamplesFactory::isValidExampleName(), SampleViewFactory::isValidType(), m_aligner, m_materialModel, m_sampleModel, SessionItem::modelType(), ParticleItem::P_FORM_FACTOR, SessionGraphicsItem::P_XPOS, SessionGraphicsItem::P_YPOS, SessionItem::setGroupProperty(), and SessionItem::setItemValue().

Here is the call graph for this function:

◆ getNodeEditor()

NodeEditor* DesignerScene::getNodeEditor ( )
inline

Definition at line 53 of file DesignerScene.h.

53 { return m_nodeEditor; }

References m_nodeEditor.

◆ getSampleModel()

◆ getViewForItem()

IView * DesignerScene::getViewForItem ( SessionItem item)

Definition at line 125 of file DesignerScene.cpp.

126 {
127  auto it = m_ItemToView.find(item);
128  if (it != m_ItemToView.end()) {
129  return it.value();
130  }
131  return nullptr;
132 }

References m_ItemToView.

Referenced by addViewForItem(), SampleViewAligner::getConnectedViews(), and SampleViewAligner::getViewForIndex().

◆ isAcceptedByMultiLayer()

bool DesignerScene::isAcceptedByMultiLayer ( const DesignerMimeData mimeData,
QGraphicsSceneDragDropEvent *  event 
)
private

Definition at line 487 of file DesignerScene.cpp.

489 {
490  if (!mimeData)
491  return false;
492 
493  // // MultiLayer can be inserted in MultiLayer
494  // if (mimeData->getClassName() == "MultiLayer" && isMultiLayerNearby(event)) {
495  // return true;
496  // }
497 
498  // layer can be inserted in MultiLayer
499  if (mimeData->getClassName() == "Layer" && isMultiLayerNearby(event)) {
500  return true;
501  }
502  return false;
503 }
bool isMultiLayerNearby(QGraphicsSceneDragDropEvent *event)
Returns true if there is MultiLayerView nearby during drag event.

References DesignerMimeData::getClassName(), and isMultiLayerNearby().

Referenced by dragMoveEvent(), and dropEvent().

Here is the call graph for this function:

◆ isLayerDragged()

bool DesignerScene::isLayerDragged ( ) const
private

Definition at line 505 of file DesignerScene.cpp.

506 {
507  ILayerView* layer = dynamic_cast<ILayerView*>(mouseGrabberItem());
508  if (layer && !m_layer_interface_line.isNull()) {
509  return true;
510  }
511  return false;
512 }
Base class for LayerView and MultiLayerView Provides functionality for moving view on top of MultiLay...
Definition: ILayerView.h:25

References m_layer_interface_line.

Referenced by drawForeground(), and mouseMoveEvent().

◆ isMultiLayerNearby()

bool DesignerScene::isMultiLayerNearby ( QGraphicsSceneDragDropEvent *  event)
private

Returns true if there is MultiLayerView nearby during drag event.

Definition at line 466 of file DesignerScene.cpp.

467 {
469  rect.moveCenter(event->scenePos());
470  for (QGraphicsItem* item : items(rect)) {
471  if (item->type() == ViewTypes::MULTILAYER)
472  return true;
473  }
474  return false;
475 }
static QRectF getDefaultMultiLayerRect()
@ MULTILAYER
Definition: ViewTypes.h:29

References DesignerHelper::getDefaultMultiLayerRect(), and ViewTypes::MULTILAYER.

Referenced by isAcceptedByMultiLayer().

Here is the call graph for this function:

◆ mouseMoveEvent()

void DesignerScene::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
protected

Definition at line 457 of file DesignerScene.cpp.

458 {
459  if (isLayerDragged()) {
460  invalidate(); // to redraw vertical dashed line which denotes where to drag the layer
461  }
462  QGraphicsScene::mouseMoveEvent(event);
463 }

References isLayerDragged().

Here is the call graph for this function:

◆ onEstablishedConnection

void DesignerScene::onEstablishedConnection ( NodeEditorConnection connection)
slot

propagates connection established by NodeEditor to the model

Definition at line 346 of file DesignerScene.cpp.

347 {
348  ConnectableView* parentView = connection->getParentView();
349  ConnectableView* childView = connection->getChildView();
350 
351  QString tag;
352  if (connection->getParentView()->getItem()->modelType() == "ParticleLayout") {
353  if (connection->inputPort()->getPortType() == NodeEditorPort::INTERFERENCE)
355  } else if (connection->getParentView()->getItem()->modelType() == "ParticleCoreShell") {
356  if (parentView->getInputPortIndex(connection->inputPort()) == 0)
358  else if (parentView->getInputPortIndex(connection->inputPort()) == 1)
360  else if (connection->inputPort()->getPortType() == NodeEditorPort::TRANSFORMATION)
362 
363  } else if (connection->getParentView()->getItem()->modelType() == "ParticleComposition") {
364  if (connection->inputPort()->getPortType() == NodeEditorPort::TRANSFORMATION)
366  } else if (connection->getParentView()->getItem()->modelType() == "MesoCrystal") {
367  if (connection->inputPort()->getPortType() == NodeEditorPort::TRANSFORMATION)
369  }
370  delete connection; // deleting just created connection because it will be recreated from the
371  // model
372  m_sampleModel->moveItem(childView->getItem(), parentView->getItem(), -1, tag);
373 }
view of ISampleNode's with rectangular shape and node functionality
int getInputPortIndex(NodeEditorPort *port)
virtual SessionItem * getItem()
Definition: IView.h:59
ConnectableView * getChildView()
returns child view, i.e. the view which owns output port of given connection
NodeEditorPort * inputPort()
ConnectableView * getParentView()
returns parent view, i.e. the view which owns input port of given connection
EPortType getPortType() const
static const QString T_CORE
static const QString T_SHELL
static const QString T_TRANSFORMATION
Definition: ParticleItem.h:29
static const QString T_INTERFERENCE
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 NodeEditorConnection::getChildView(), ConnectableView::getInputPortIndex(), IView::getItem(), NodeEditorConnection::getParentView(), NodeEditorPort::getPortType(), NodeEditorConnection::inputPort(), NodeEditorPort::INTERFERENCE, m_sampleModel, SessionItem::modelType(), SessionModel::moveItem(), ParticleCoreShellItem::T_CORE, ParticleLayoutItem::T_INTERFERENCE, ParticleCoreShellItem::T_SHELL, ParticleItem::T_TRANSFORMATION, and NodeEditorPort::TRANSFORMATION.

Referenced by DesignerScene().

Here is the call graph for this function:

◆ onRowsAboutToBeRemoved

void DesignerScene::onRowsAboutToBeRemoved ( const QModelIndex &  parent,
int  first,
int  last 
)
slot

Definition at line 157 of file DesignerScene.cpp.

158 {
159  m_block_selection = true;
160  for (int irow = first; irow <= last; ++irow) {
161  QModelIndex itemIndex = m_sampleModel->index(irow, 0, parent);
162  deleteViews(itemIndex); // deleting all child items
163  }
164  m_block_selection = false;
165 }

References deleteViews(), SessionModel::index(), m_block_selection, and m_sampleModel.

Referenced by setSampleModel().

Here is the call graph for this function:

◆ onRowsInserted

void DesignerScene::onRowsInserted ( const QModelIndex &  parent,
int  first,
int  last 
)
slot

Definition at line 147 of file DesignerScene.cpp.

148 {
149  updateScene();
150 }

References updateScene().

Referenced by setSampleModel().

Here is the call graph for this function:

◆ onRowsRemoved

void DesignerScene::onRowsRemoved ( const QModelIndex &  parent,
int  first,
int  last 
)
slot

Definition at line 152 of file DesignerScene.cpp.

153 {
154  updateScene();
155 }

References updateScene().

Referenced by setSampleModel().

Here is the call graph for this function:

◆ onSceneSelectionChanged

void DesignerScene::onSceneSelectionChanged ( )
slot

propagate selection from scene to model

Definition at line 192 of file DesignerScene.cpp.

193 {
194  if (m_block_selection)
195  return;
196 
197  m_block_selection = true;
198 
199  m_selectionModel->clearSelection();
200  QList<QGraphicsItem*> selected = selectedItems();
201  for (int i = 0; i < selected.size(); ++i) {
202  IView* view = dynamic_cast<IView*>(selected[i]);
203  if (view) {
204  SessionItem* sampleItem = view->getItem();
205  QModelIndex itemIndex = m_sampleModel->indexOfItem(sampleItem);
206  ASSERT(itemIndex.isValid());
207  if (!m_selectionModel->isSelected(m_proxy->mapFromSource(itemIndex)))
208  m_selectionModel->select(m_proxy->mapFromSource(itemIndex),
209  QItemSelectionModel::Select);
210  }
211  }
212 
213  m_block_selection = false;
214 }
QModelIndex indexOfItem(SessionItem *item) const

References ASSERT, IView::getItem(), SessionModel::indexOfItem(), m_block_selection, m_proxy, m_sampleModel, and m_selectionModel.

Referenced by DesignerScene().

Here is the call graph for this function:

◆ onSessionSelectionChanged

void DesignerScene::onSessionSelectionChanged ( const QItemSelection &  ,
const QItemSelection &   
)
slot

propagate selection from model to scene

Definition at line 168 of file DesignerScene.cpp.

170 {
171  if (m_block_selection)
172  return;
173 
174  m_block_selection = true;
175 
176  for (QMap<SessionItem*, IView*>::iterator it = m_ItemToView.begin(); it != m_ItemToView.end();
177  ++it) {
178  QModelIndex index = m_proxy->mapFromSource(m_sampleModel->indexOfItem(it.key()));
179  if (index.isValid()) {
180  if (m_selectionModel->isSelected(index)) {
181  it.value()->setSelected(true);
182  } else {
183  it.value()->setSelected(false);
184  }
185  }
186  }
187 
188  m_block_selection = false;
189 }

References SessionModel::indexOfItem(), m_block_selection, m_ItemToView, m_proxy, m_sampleModel, and m_selectionModel.

Referenced by setSelectionModel().

Here is the call graph for this function:

◆ onSmartAlign

void DesignerScene::onSmartAlign ( )
slot

Definition at line 514 of file DesignerScene.cpp.

515 {
517 }
void smartAlign()
Spring based implified algorithm for smart alignment.

References m_aligner, and SampleViewAligner::smartAlign().

Here is the call graph for this function:

◆ removeConnection

void DesignerScene::removeConnection ( NodeEditorConnection connection)
slot

propagates break of connection between views on scene to the model

Definition at line 376 of file DesignerScene.cpp.

377 {
378  IView* childView = dynamic_cast<IView*>(connection->outputPort()->parentItem());
379  m_sampleModel->moveItem(childView->getItem(), 0);
380 }
NodeEditorPort * outputPort()

References IView::getItem(), m_sampleModel, SessionModel::moveItem(), and NodeEditorConnection::outputPort().

Referenced by deleteSelectedItems().

Here is the call graph for this function:

◆ removeItemViewFromScene()

void DesignerScene::removeItemViewFromScene ( SessionItem item)
private

removes view from scene corresponding to given item

Definition at line 287 of file DesignerScene.cpp.

288 {
289  ASSERT(item);
290 
291  for (QMap<SessionItem*, IView*>::iterator it = m_ItemToView.begin(); it != m_ItemToView.end();
292  ++it) {
293  if (it.key() == item) {
294  IView* view = it.value();
295  view->setSelected(false);
296  m_ItemToView.erase(it);
297  emit view->aboutToBeDeleted();
298  view->deleteLater();
299  // delete view;
300  update();
301  break;
302  }
303  }
304 }
void aboutToBeDeleted()

References IView::aboutToBeDeleted(), ASSERT, and m_ItemToView.

Referenced by deleteViews().

◆ resetScene

void DesignerScene::resetScene ( )
slot

Definition at line 134 of file DesignerScene.cpp.

135 {
136  clear();
137  m_ItemToView.clear();
139 }

References m_ItemToView, and m_layer_interface_line.

Referenced by setSampleModel().

◆ selectionModeChangeRequest

void DesignerScene::selectionModeChangeRequest ( int  )
signal

◆ setInstrumentModel()

void DesignerScene::setInstrumentModel ( InstrumentModel instrumentModel)

Definition at line 96 of file DesignerScene.cpp.

97 {
98  m_instrumentModel = instrumentModel;
99 }

References m_instrumentModel.

Referenced by SampleDesigner::setModels().

◆ setLayerInterfaceLine

void DesignerScene::setLayerInterfaceLine ( const QLineF &  line = {})
inlineslot

Definition at line 68 of file DesignerScene.h.

68  {})
69  {
71  invalidate();
72  }

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

◆ setMaterialModel()

void DesignerScene::setMaterialModel ( MaterialModel materialModel)

Definition at line 101 of file DesignerScene.cpp.

102 {
103  m_materialModel = materialModel;
104 }

References m_materialModel.

Referenced by SampleDesigner::setModels().

◆ setSampleModel()

void DesignerScene::setSampleModel ( SampleModel sampleModel)

Definition at line 64 of file DesignerScene.cpp.

65 {
66  ASSERT(sampleModel);
67 
68  if (sampleModel != m_sampleModel) {
69 
70  if (m_sampleModel) {
71  disconnect(m_sampleModel, &SampleModel::modelAboutToBeReset, this,
73  disconnect(m_sampleModel, &SampleModel::rowsInserted, this,
75  disconnect(m_sampleModel, &SampleModel::rowsAboutToBeRemoved, this,
77  disconnect(m_sampleModel, &SampleModel::rowsRemoved, this,
79  disconnect(m_sampleModel, &SampleModel::modelReset, this, &DesignerScene::updateScene);
80  }
81 
82  m_sampleModel = sampleModel;
83 
84  connect(m_sampleModel, &SampleModel::modelAboutToBeReset, this, &DesignerScene::resetScene);
85  connect(m_sampleModel, &SampleModel::rowsInserted, this, &DesignerScene::onRowsInserted);
86  connect(m_sampleModel, &SampleModel::rowsAboutToBeRemoved, this,
88  connect(m_sampleModel, &SampleModel::rowsRemoved, this, &DesignerScene::onRowsRemoved);
89  connect(m_sampleModel, &SampleModel::modelReset, this, &DesignerScene::updateScene);
90 
91  resetScene();
92  updateScene();
93  }
94 }
void onRowsInserted(const QModelIndex &parent, int first, int last)
void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void onRowsRemoved(const QModelIndex &parent, int first, int last)

References ASSERT, m_sampleModel, onRowsAboutToBeRemoved(), onRowsInserted(), onRowsRemoved(), resetScene(), and updateScene().

Referenced by SampleDesigner::setModels().

Here is the call graph for this function:

◆ setSelectionModel()

void DesignerScene::setSelectionModel ( QItemSelectionModel *  model,
FilterPropertyProxy proxy 
)

Definition at line 106 of file DesignerScene.cpp.

107 {
108  ASSERT(model);
109 
110  if (model != m_selectionModel) {
111 
112  if (m_selectionModel) {
113  disconnect(m_selectionModel, &QItemSelectionModel::selectionChanged, this,
115  }
116 
117  m_selectionModel = model;
118  m_proxy = proxy;
119 
120  connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this,
122  }
123 }
void onSessionSelectionChanged(const QItemSelection &, const QItemSelection &)
propagate selection from model to scene

References ASSERT, m_proxy, m_selectionModel, and onSessionSelectionChanged().

Referenced by SampleDesigner::setSelectionModel().

Here is the call graph for this function:

◆ updateScene

void DesignerScene::updateScene ( )
slot

Definition at line 141 of file DesignerScene.cpp.

142 {
143  updateViews();
144  alignViews();
145 }
void updateViews(const QModelIndex &parentIndex={}, IView *parentView=0)
runs through all items recursively and updates corresponding views
void alignViews()
aligns SampleView's on graphical canvas

References alignViews(), and updateViews().

Referenced by onRowsInserted(), onRowsRemoved(), and setSampleModel().

Here is the call graph for this function:

◆ updateViews()

void DesignerScene::updateViews ( const QModelIndex &  parentIndex = {},
IView parentView = 0 
)
private

runs through all items recursively and updates corresponding views

Definition at line 217 of file DesignerScene.cpp.

218 {
220 
221  IView* childView(0);
222  int childCount = 0;
223  for (int i_row = 0; i_row < m_sampleModel->rowCount(parentIndex); ++i_row) {
224  QModelIndex itemIndex = m_sampleModel->index(i_row, 0, parentIndex);
225 
226  if (SessionItem* item = m_sampleModel->itemForIndex(itemIndex)) {
227 
228  if (item && !SampleViewFactory::isValidType(item->modelType()))
229  continue;
230 
231  childView = addViewForItem(item);
232  if (childView) {
233  if (parentView)
234  parentView->addView(childView, childCount++);
235  }
236  }
237 
238  updateViews(itemIndex, childView);
239  }
240 }
IView * addViewForItem(SessionItem *item)
adds view for item, if it doesn't exists
virtual void addView(IView *childView, int row=0)
Definition: IView.cpp:53

References IView::addView(), addViewForItem(), ASSERT, SessionModel::index(), SampleViewFactory::isValidType(), SessionModel::itemForIndex(), m_sampleModel, and SessionModel::rowCount().

Referenced by updateScene().

Here is the call graph for this function:

Member Data Documentation

◆ m_aligner

SampleViewAligner* DesignerScene::m_aligner
private

Definition at line 114 of file DesignerScene.h.

Referenced by ~DesignerScene(), alignViews(), dropEvent(), and onSmartAlign().

◆ m_block_selection

bool DesignerScene::m_block_selection
private

◆ m_instrumentModel

InstrumentModel* DesignerScene::m_instrumentModel
private

Definition at line 102 of file DesignerScene.h.

Referenced by setInstrumentModel().

◆ m_ItemToView

QMap<SessionItem*, IView*> DesignerScene::m_ItemToView
private

Correspondance of model's item and scene's view.

Definition at line 108 of file DesignerScene.h.

Referenced by addViewForItem(), deleteSelectedItems(), getViewForItem(), onSessionSelectionChanged(), removeItemViewFromScene(), and resetScene().

◆ m_layer_interface_line

QLineF DesignerScene::m_layer_interface_line
private

Foreground line representing appropriate interface during layer's movement.

Definition at line 111 of file DesignerScene.h.

Referenced by drawForeground(), isLayerDragged(), and resetScene().

◆ m_materialModel

MaterialModel* DesignerScene::m_materialModel
private

Definition at line 103 of file DesignerScene.h.

Referenced by dropEvent(), and setMaterialModel().

◆ m_nodeEditor

NodeEditor* DesignerScene::m_nodeEditor
private

Definition at line 116 of file DesignerScene.h.

Referenced by DesignerScene(), and getNodeEditor().

◆ m_proxy

FilterPropertyProxy* DesignerScene::m_proxy
private

◆ m_sampleModel

◆ m_selectionModel

QItemSelectionModel* DesignerScene::m_selectionModel
private

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