BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskGraphicsScene.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/MaskWidgets/MaskGraphicsScene.cpp
6 //! @brief Implements class MaskGraphicsScene
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
24 #include <QGraphicsItem>
25 #include <QGraphicsSceneMoveEvent>
26 #include <QItemSelection>
27 #include <QLineF>
28 #include <QPainter>
29 
30 namespace {
31 const QRectF default_scene_rect(0, 0, 800, 600);
32 const qreal min_distance_to_create_rect = 10;
33 } // namespace
34 
36  : QGraphicsScene(parent)
37  , m_maskModel(0)
38  , m_selectionModel(0)
39  , m_proxy(0)
40  , m_block_selection(false)
41  , m_intensityItem(0)
42  , m_currentItem(0)
43 {
44  setSceneRect(default_scene_rect);
45  connect(this, &MaskGraphicsScene::selectionChanged, this,
47 }
48 
50 {
51  // Fix within #1792
52  if (m_proxy)
54 }
55 
56 void MaskGraphicsScene::setMaskContext(SessionModel* model, const QModelIndex& maskContainerIndex,
57  IntensityDataItem* intensityItem)
58 {
59  m_intensityItem = intensityItem;
60 
61  if (model != m_maskModel || m_maskContainerIndex != maskContainerIndex) {
62 
63  if (m_maskModel) {
64  disconnect(m_maskModel, &SessionModel::modelAboutToBeReset, this,
66  disconnect(m_maskModel, &SessionModel::rowsInserted, this,
68  disconnect(m_maskModel, &SessionModel::rowsAboutToBeRemoved, this,
70  disconnect(m_maskModel, &SessionModel::rowsRemoved, this,
72  disconnect(m_maskModel, &SessionModel::modelReset, this,
74  }
75 
76  m_maskModel = model;
77 
78  QString containerType = m_maskModel->itemForIndex(maskContainerIndex)->modelType();
79  if (containerType != "MaskContainer" && containerType != "ProjectionContainer")
80  throw GUIHelpers::Error(
81  "MaskGraphicsScene::setMaskContext() -> Error. Not a container");
82 
83  m_maskContainerIndex = maskContainerIndex;
84 
85  if (m_maskModel) {
86  connect(m_maskModel, &SessionModel::modelAboutToBeReset, this,
88  connect(m_maskModel, &SessionModel::rowsInserted, this,
90  connect(m_maskModel, &SessionModel::rowsAboutToBeRemoved, this,
92  connect(m_maskModel, &SessionModel::rowsRemoved, this,
94  connect(m_maskModel, &SessionModel::modelReset, this, &MaskGraphicsScene::updateScene);
95  }
96 
97  resetScene();
98  updateScene();
99  }
100 }
101 
103 {
104  m_intensityItem = nullptr;
105  if (m_maskModel) {
106  disconnect(m_maskModel, &SessionModel::modelAboutToBeReset, this,
108  disconnect(m_maskModel, &SessionModel::rowsInserted, this,
110  disconnect(m_maskModel, &SessionModel::rowsAboutToBeRemoved, this,
112  disconnect(m_maskModel, &SessionModel::rowsRemoved, this,
114  disconnect(m_maskModel, &SessionModel::modelReset, this, &MaskGraphicsScene::updateScene);
115  }
116  m_maskModel = nullptr;
118  resetScene();
119 }
120 
121 void MaskGraphicsScene::setSelectionModel(QItemSelectionModel* model)
122 {
123  ASSERT(model);
124  m_selectionModel = model;
125  connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this,
126  &MaskGraphicsScene::onSessionSelectionChanged, Qt::UniqueConnection);
127 }
128 
130 {
131  ASSERT(m_proxy);
132  return m_proxy->colorMap();
133 }
134 
135 void MaskGraphicsScene::onActivityModeChanged(MaskEditorFlags::Activity value)
136 {
137  if (!m_proxy)
138  return;
139 
142 
143  m_context.setActivityType(value);
145 
146  updateCursors();
147 }
148 
149 void MaskGraphicsScene::onMaskValueChanged(MaskEditorFlags::MaskValue value)
150 {
151  m_context.setMaskValue(value);
152 }
153 
154 void MaskGraphicsScene::onRowsInserted(const QModelIndex&, int, int)
155 {
156  updateScene();
157 }
158 
159 void MaskGraphicsScene::onRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last)
160 {
161  m_block_selection = true;
162  for (int irow = first; irow <= last; ++irow) {
163  QModelIndex itemIndex = m_maskModel->index(irow, 0, parent);
164  deleteViews(itemIndex); // deleting all child items
165  }
166  m_block_selection = false;
167 }
168 
169 void MaskGraphicsScene::onRowsRemoved(const QModelIndex&, int, int)
170 {
171  updateScene();
172 }
173 
175 {
176  if (isDrawingInProgress()) {
178  QModelIndex index = m_maskModel->indexOfItem(m_currentItem);
179  m_maskModel->removeRows(index.row(), 1, index.parent());
180  setDrawingInProgress(false);
181  }
182 }
183 
185 {
187  m_block_selection = true;
188  m_selectionModel->clearSelection();
189  clearSelection();
190 
191  clear();
192  m_ItemToView.clear();
193  m_proxy = 0;
194  m_adaptor.reset(new ColorMapSceneAdaptor);
195 
196  m_block_selection = false;
197 }
198 
199 //! Main method to update scene on various changes in the model.
200 
202 {
203  if (!m_maskModel)
204  return;
205 
209  setZValues();
210 }
211 
212 //! Propagates selection from model to scene.
213 
214 void MaskGraphicsScene::onSessionSelectionChanged(const QItemSelection&, const QItemSelection&)
215 {
216  if (m_block_selection)
217  return;
218 
219  m_block_selection = true;
220 
221  for (auto it = m_ItemToView.begin(); it != m_ItemToView.end(); ++it) {
222  QModelIndex index = m_maskModel->indexOfItem(it.key());
223  if (index.isValid())
224  it.value()->setSelected(m_selectionModel->isSelected(index));
225  }
226  m_block_selection = false;
227 }
228 
229 //! Propagates selection from scene to model.
230 
232 {
233  if (m_block_selection)
234  return;
235 
236  m_block_selection = true;
237 
238  m_selectionModel->clearSelection();
239 
240  for (QGraphicsItem* graphicsItem : selectedItems()) {
241  if (IShape2DView* view = dynamic_cast<IShape2DView*>(graphicsItem)) {
242  QModelIndex itemIndex = m_maskModel->indexOfItem(view->parameterizedItem());
243  ASSERT(itemIndex.isValid());
244  if (!m_selectionModel->isSelected(itemIndex))
245  m_selectionModel->select(itemIndex, QItemSelectionModel::Select);
246  }
247  }
248  m_block_selection = false;
249 }
250 
251 void MaskGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
252 {
253  if (event->buttons() & Qt::RightButton) {
254  if (isDrawingInProgress()) {
256  } else {
258  }
259  return;
260  }
261  if (isValidForPolygonDrawing(event)) {
262  processPolygonItem(event);
263  return;
264  }
265  if (isValidForLineDrawing(event)) {
266  processLineItem(event);
267  return;
268  }
269  if (isValidForMaskAllDrawing(event)) {
270  processMaskAllItem(event);
271  return;
272  }
273  if (isValidForRectangleShapeDrawing(event)) {
275  return;
276  }
277  QGraphicsScene::mousePressEvent(event);
278 }
279 
280 void MaskGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
281 {
284  return;
285  }
286  QGraphicsScene::mouseMoveEvent(event);
287 
289  m_currentMousePosition = event->scenePos();
290  invalidate();
291  }
292 }
293 
294 //! Finalizes item drawing or pass events to other items.
295 
296 void MaskGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
297 {
298  if (isDrawingInProgress()) {
300  clearSelection();
301  if (m_currentItem) {
302  // drawing ended up with item drawn, let's make it selected
303  if (IShape2DView* view = m_ItemToView[m_currentItem]) {
304  view->setSelected(true);
305  }
306  } else {
307  // drawing ended without item to be draw (too short mouse move)
308  // making item beneath of mouse release position to be selected
310  }
311  setDrawingInProgress(false);
312  }
313  } else {
314  QGraphicsScene::mouseReleaseEvent(event);
315  }
316 }
317 
318 //! Draws dashed line to the current mouse position in the case of ungoing
319 //! line or polygon drawing.
320 
321 void MaskGraphicsScene::drawForeground(QPainter* painter, const QRectF&)
322 {
323  // if(!isDrawingInProgress())
324  // return;
325 
326  if (m_currentMousePosition == QPointF())
327  return;
328 
329  if (PolygonView* polygon = currentPolygon()) {
330  painter->setPen(QPen(Qt::black, 1, Qt::DashLine));
331  painter->drawLine(QLineF(polygon->lastAddedPoint(), m_currentMousePosition));
332  } else {
333  if (m_context.isLineMode()) {
334  const QRectF& plot_scene_rectangle = m_adaptor->viewportRectangle();
335  if (!plot_scene_rectangle.contains(m_currentMousePosition))
336  return;
337 
338  painter->setPen(QPen(Qt::black, 1, Qt::DashLine));
340  QPointF p1(m_currentMousePosition.x(), plot_scene_rectangle.bottom());
341  QPointF p2(m_currentMousePosition.x(), plot_scene_rectangle.top());
342  painter->drawLine(QLineF(p1, p2));
343  }
345  QPointF p1(plot_scene_rectangle.left(), m_currentMousePosition.y());
346  QPointF p2(plot_scene_rectangle.right(), m_currentMousePosition.y());
347  painter->drawLine(QLineF(p1, p2));
348  }
349  }
350  }
351 }
352 
353 //! Creates item context menu if there is IMaskView beneath the mouse right click.
354 
355 void MaskGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
356 {
357  if (isDrawingInProgress())
358  return;
359 
360  if (dynamic_cast<IShape2DView*>(itemAt(event->scenePos(), QTransform())))
361  emit itemContextMenuRequest(event->screenPos());
362 }
363 
364 //! Updates proxy widget for intensity data item.
365 
367 {
369  if (!m_proxy) {
373  addItem(m_proxy);
374  }
375 }
376 
377 //! Recutsively runs through the model and creates corresponding views.
378 
379 void MaskGraphicsScene::updateViews(const QModelIndex& parentIndex, IShape2DView* parentView)
380 {
382  IShape2DView* childView(0);
383  for (int i_row = 0; i_row < m_maskModel->rowCount(parentIndex); ++i_row) {
384  QModelIndex itemIndex = m_maskModel->index(i_row, 0, parentIndex);
385  if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
386  if (item->modelType() == "GroupProperty" || item->modelType() == "Property")
387  continue;
388 
389  childView = addViewForItem(item);
390  if (childView) {
391  if (parentView)
392  parentView->addView(childView, i_row);
393  }
394  }
395  updateViews(itemIndex, childView);
396  }
397 }
398 
399 //! Creates a view for given item.
400 
402 {
403  ASSERT(item);
404  IShape2DView* view = m_ItemToView[item];
405  if (!view) {
406  view = MaskViewFactory::createMaskView(item, m_adaptor.data());
407  if (view) {
408  m_ItemToView[item] = view;
409  addItem(view);
410  return view;
411  }
412  }
413  return view;
414 }
415 
416 //! Recursive delete of all views corresponding to given index.
417 
418 void MaskGraphicsScene::deleteViews(const QModelIndex& parentIndex)
419 {
420  for (int i_row = 0; i_row < m_maskModel->rowCount(parentIndex); ++i_row) {
421  QModelIndex itemIndex = m_maskModel->index(i_row, 0, parentIndex);
422 
423  if (SessionItem* item = m_maskModel->itemForIndex(itemIndex))
425 
426  deleteViews(itemIndex);
427  }
428  removeItemViewFromScene(m_maskModel->itemForIndex(parentIndex)); // deleting parent item
429 }
430 
431 //! Removes single view from scene.
432 
434 {
435  for (auto it = m_ItemToView.begin(); it != m_ItemToView.end(); ++it) {
436  if (it.key() == item) {
437  IShape2DView* view = it.value();
438  view->setSelected(false);
439  m_ItemToView.erase(it);
440  delete view;
441  break;
442  }
443  }
444 }
445 
446 //! Returns true if left mouse bottom click was inside ColorMap viewport rectangle.
447 
448 bool MaskGraphicsScene::isValidMouseClick(QGraphicsSceneMouseEvent* event)
449 {
450  if (!m_adaptor)
451  return false;
452  if (!(event->buttons() & Qt::LeftButton))
453  return false;
454  if (!m_adaptor->viewportRectangle().contains(event->scenePos()))
455  return false;
456  return true;
457 }
458 
459 //! Returns true if mouse click is valid for rectangular/elliptic/ROI shapes.
460 
461 bool MaskGraphicsScene::isValidForRectangleShapeDrawing(QGraphicsSceneMouseEvent* event)
462 {
463  if (isDrawingInProgress())
464  return false;
465  if (!isValidMouseClick(event))
466  return false;
468  return false;
470  return false;
471  if (m_context.isROIMode()) {
472  // only one ROI is allowed
473  for (SessionItem* item : m_ItemToView.keys())
474  if (item->modelType() == "RegionOfInterest")
475  return false;
476  }
477  return true;
478 }
479 
480 //! Returns true if mouse click is in context suitable for polygon drawing.
481 
482 bool MaskGraphicsScene::isValidForPolygonDrawing(QGraphicsSceneMouseEvent* event)
483 {
484  if (!isValidMouseClick(event))
485  return false;
486  if (!m_context.isPolygonMode())
487  return false;
488  if (!isDrawingInProgress()) {
490  return false;
491  }
492  return true;
493 }
494 
495 //! Returns true if mouse click is in context suitable for line drawing.
496 
497 bool MaskGraphicsScene::isValidForLineDrawing(QGraphicsSceneMouseEvent* event)
498 {
499  if (!isValidMouseClick(event))
500  return false;
501  if (isDrawingInProgress())
502  return false;
503  if (!m_context.isLineMode())
504  return false;
505  if (QGraphicsItem* graphicsItem = itemAt(event->scenePos(), QTransform())) {
506  if (graphicsItem->type() == MaskEditorHelper::VERTICALLINE
507  || graphicsItem->type() == MaskEditorHelper::HORIZONTALLINE)
508  return false;
509  }
510  return true;
511 }
512 
513 //! Returns true if MaskAllItem can be drawn. Only one item of such type is allowed.
514 
515 bool MaskGraphicsScene::isValidForMaskAllDrawing(QGraphicsSceneMouseEvent* event)
516 {
517  if (!isValidMouseClick(event))
518  return false;
519  if (isDrawingInProgress())
520  return false;
521  if (!m_context.isMaskAllMode())
522  return false;
523  for (SessionItem* item : m_ItemToView.keys())
524  if (item->modelType() == "MaskAllMask")
525  return false;
526  return true;
527 }
528 
529 //! Return true if area beneath the mouse contains views of given type.
530 
531 bool MaskGraphicsScene::isAreaContains(QGraphicsSceneMouseEvent* event,
533 {
534  for (QGraphicsItem* graphicsItem : this->items(event->scenePos()))
535  if (graphicsItem->type() == viewType)
536  return true;
537  return false;
538 }
539 
541 {
543 }
544 
546 {
548  if (value == false)
549  m_currentItem = 0;
550 }
551 
552 //! Sets the state of all views in pan&zoom mode.
553 //! In pan&zoom mode, the selection is removed, all items can't receive mouse clicks, and all
554 //! events are propagated down to ColorMap plot.
555 
557 {
558  if (value)
559  m_selectionModel->clearSelection();
560 
561  Qt::MouseButtons acceptedButton = (value ? Qt::NoButton : Qt::LeftButton);
562  for (IShape2DView* view : m_ItemToView.values())
563  view->setAcceptedMouseButtons(acceptedButton);
564 
565  m_proxy->setInZoomMode(value);
566 }
567 
568 //! Change cursor to stress that hovered item is movable (when not in PanZoom mode)
569 
571 {
572  for (auto it = m_ItemToView.begin(); it != m_ItemToView.end(); ++it) {
573  if (it.key()->modelType() == "VerticalLineMask") {
574  it.value()->setCursor(m_context.isInZoomMode() ? Qt::ArrowCursor : Qt::SizeHorCursor);
575  } else if (it.key()->modelType() == "HorizontalLineMask") {
576  it.value()->setCursor(m_context.isInZoomMode() ? Qt::ArrowCursor : Qt::SizeVerCursor);
577  }
578  }
579 }
580 
581 void MaskGraphicsScene::makeViewAtMousePosSelected(QGraphicsSceneMouseEvent* event)
582 {
583  if (QGraphicsItem* graphicsItem = itemAt(event->scenePos(), QTransform()))
584  graphicsItem->setSelected(true);
585 }
586 
587 //! Processes RectangleItem and EllipseItem drawing
588 //! If the mouse move distance with left button down is larger than certain threshold,
589 //! new item will be created. Further, this function will update size and position
590 //! of current rectangle if mouse keep moving.
591 
592 void MaskGraphicsScene::processRectangleShapeItem(QGraphicsSceneMouseEvent* event)
593 {
594  if (!isDrawingInProgress())
595  setDrawingInProgress(true);
596 
597  QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton);
598  QPointF mouse_pos = event->scenePos();
599  QLineF line(mouse_pos, click_pos);
600 
601  if (!m_currentItem && line.length() > min_distance_to_create_rect) {
604  if (!m_context.isROIMode())
607  }
608  if (!m_currentItem)
609  return;
610 
611  qreal xmin = std::min(click_pos.x(), mouse_pos.x());
612  qreal xmax = std::max(click_pos.x(), mouse_pos.x());
613  qreal ymin = std::min(click_pos.y(), mouse_pos.y());
614  qreal ymax = std::max(click_pos.y(), mouse_pos.y());
615 
616  if (m_currentItem->modelType() == "RectangleMask"
617  || m_currentItem->modelType() == "RegionOfInterest") {
622  } else if (m_currentItem->modelType() == "EllipseMask") {
624  m_adaptor->fromSceneX(xmin + (xmax - xmin) / 2.));
626  m_adaptor->fromSceneY(ymin + (ymax - ymin) / 2.));
628  (m_adaptor->fromSceneX(xmax) - m_adaptor->fromSceneX(xmin))
629  / 2.);
631  (m_adaptor->fromSceneY(ymin) - m_adaptor->fromSceneY(ymax))
632  / 2.);
633  }
634 }
635 
636 void MaskGraphicsScene::processPolygonItem(QGraphicsSceneMouseEvent* event)
637 {
639 
640  if (!m_currentItem) {
641  setDrawingInProgress(true);
644  m_selectionModel->clearSelection();
646  QItemSelectionModel::Select);
648  }
649  ASSERT(m_currentItem->modelType() == "PolygonMask");
650 
651  if (PolygonView* polygon = currentPolygon()) {
652  if (polygon->closePolygonIfNecessary()) {
653  setDrawingInProgress(false);
655  return;
656  }
657  }
659  QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton);
660 
661  point->setItemValue(PolygonPointItem::P_POSX, m_adaptor->fromSceneX(click_pos.x()));
662  point->setItemValue(PolygonPointItem::P_POSY, m_adaptor->fromSceneY(click_pos.y()));
663 }
664 
665 void MaskGraphicsScene::processLineItem(QGraphicsSceneMouseEvent* event)
666 {
667  setDrawingInProgress(true);
668  QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton);
669 
671  processVerticalLineItem(click_pos);
672 
674  processHorizontalLineItem(click_pos);
675 
676  m_selectionModel->clearSelection();
677  m_selectionModel->select(m_maskModel->indexOfItem(m_currentItem), QItemSelectionModel::Select);
680 
681  setDrawingInProgress(false);
682 }
683 
685 {
688 }
689 
691 {
694 }
695 
696 void MaskGraphicsScene::processMaskAllItem(QGraphicsSceneMouseEvent* event)
697 {
698  Q_UNUSED(event);
699  setDrawingInProgress(true);
701  m_selectionModel->clearSelection();
702  setDrawingInProgress(false);
703 }
704 
705 //! Update Z-values of all IMaskView to reflect stacking order in SessionModel.
706 //! Item with irow=0 is the top most on graphics scene (and so is having largest z-values).
707 
709 {
710  ASSERT(m_maskContainerIndex.isValid());
711  for (int i = 0; i < m_maskModel->rowCount(m_maskContainerIndex); i++) {
712  QModelIndex itemIndex = m_maskModel->index(i, 0, m_maskContainerIndex);
713  SessionItem* item = m_maskModel->itemForIndex(itemIndex);
714  if (IShape2DView* view = m_ItemToView[item])
715  view->setZValue(m_maskModel->rowCount(m_maskContainerIndex) - itemIndex.row() + 1);
716  }
717 }
718 
719 //! Returns polygon which is currently under the drawing.
720 
722 {
723  PolygonView* result(0);
725  if (m_currentItem)
726  result = dynamic_cast<PolygonView*>(m_ItemToView[m_currentItem]);
727  }
728  return result;
729 }
730 
731 //! Sets item name depending on alreay existent items.
732 //! If there is already "Rectangle1", the new name will be "Rectangle2"
733 
735 {
736  if (itemToChange->modelType() == "RegionOfInterest")
737  return;
738 
739  int glob_index(0);
740  for (int i_row = 0; i_row < m_maskModel->rowCount(m_maskContainerIndex); ++i_row) {
741  QModelIndex itemIndex = m_maskModel->index(i_row, 0, m_maskContainerIndex);
742  if (SessionItem* currentItem = m_maskModel->itemForIndex(itemIndex)) {
743  if (currentItem->modelType() == itemToChange->modelType()) {
744  QString itemName = currentItem->itemName();
745  if (itemName.startsWith(itemToChange->itemName())) {
746  int item_index = itemName.remove(0, itemToChange->itemName().size()).toInt();
747  if (item_index > glob_index)
748  glob_index = item_index;
749  }
750  }
751  }
752  }
753  itemToChange->setItemName(itemToChange->itemName() + QString::number(++glob_index));
754 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class ColorMapSceneAdaptor.
Defines class GUIHelpers functions.
Defines class IntensityDataItem.
Defines class MaskGraphicsProxy.
Defines class MaskGraphicsScene.
Defines MaskItems classes.
Defines class MaskViewFactory.
Defines PolygonView class.
Defines class SessionModel.
Performs conversion of MaskItems coordinates between ColorMap and GraphicsScene.
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
static const QString P_XRADIUS
Definition: MaskItems.h:91
static const QString P_YRADIUS
Definition: MaskItems.h:92
static const QString P_XCENTER
Definition: MaskItems.h:89
static const QString P_YCENTER
Definition: MaskItems.h:90
static const QString P_POSY
Definition: MaskItems.h:81
Main interface class for views representing MaskItems, Projections on graphics scene.
Definition: IShape2DView.h:27
virtual void addView(IShape2DView *childView, int row=0)
QString activityToModelType() const
Returns model type corresponding to current activity.
int activityToRow() const
Returns model row corresponding to given activity.
void setDrawingInProgress(bool value)
void setActivityType(MaskEditorFlags::Activity value)
bool isVerticalLineMode() const
bool isRectangleShapeMode() const
bool isActivityRequiresDrawingCancel(MaskEditorFlags::Activity proposed_new_activity)
return true, if proposed activity requires the cancel of drawing i.e.
bool isHorizontalLineMode() const
bool isDrawingInProgress() const
void setMaskValue(MaskEditorFlags::MaskValue value)
Graphics proxy to place QWidget inside QGraphicsScene, used by MaskEditorCanvas.
void setIntensityItem(IntensityDataItem *item)
void setInZoomMode(bool value)
Sets widget to zoom mode, when signals (zoom wheel, mouse clicks) are send down to ColorMap plot.
void setSceneAdaptor(ISceneAdaptor *sceneAdaptor)
PolygonView * currentPolygon() const
Returns polygon which is currently under the drawing.
void mousePressEvent(QGraphicsSceneMouseEvent *event)
bool isAreaContains(QGraphicsSceneMouseEvent *event, MaskEditorHelper::EViewTypes viewType)
Return true if area beneath the mouse contains views of given type.
bool isValidMouseClick(QGraphicsSceneMouseEvent *event)
Returns true if left mouse bottom click was inside ColorMap viewport rectangle.
void setSelectionModel(QItemSelectionModel *model)
void updateScene()
Main method to update scene on various changes in the model.
MaskGraphicsScene(QObject *parent=0)
void processLineItem(QGraphicsSceneMouseEvent *event)
void processVerticalLineItem(const QPointF &pos)
SessionModel * m_maskModel
void setZValues()
Update Z-values of all IMaskView to reflect stacking order in SessionModel.
void setDrawingInProgress(bool value)
void processPolygonItem(QGraphicsSceneMouseEvent *event)
void processMaskAllItem(QGraphicsSceneMouseEvent *event)
void setInPanAndZoomMode(bool value)
Sets the state of all views in pan&zoom mode.
QItemSelectionModel * m_selectionModel
void processHorizontalLineItem(const QPointF &pos)
void drawForeground(QPainter *painter, const QRectF &rect)
Draws dashed line to the current mouse position in the case of ungoing line or polygon drawing.
void onMaskValueChanged(MaskEditorFlags::MaskValue value)
void updateViews(const QModelIndex &parentIndex={}, IShape2DView *parentView=0)
Recutsively runs through the model and creates corresponding views.
void deleteViews(const QModelIndex &itemIndex)
Recursive delete of all views corresponding to given index.
IntensityDataItem * m_intensityItem
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void processRectangleShapeItem(QGraphicsSceneMouseEvent *event)
Processes RectangleItem and EllipseItem drawing If the mouse move distance with left button down is l...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Finalizes item drawing or pass events to other items.
bool isDrawingInProgress() const
void removeItemViewFromScene(SessionItem *item)
Removes single view from scene.
void itemContextMenuRequest(const QPoint &point)
MaskGraphicsProxy * m_proxy
void setMaskContext(SessionModel *model, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void onSceneSelectionChanged()
Propagates selection from scene to model.
IShape2DView * addViewForItem(SessionItem *item)
Creates a view for given item.
bool isValidForMaskAllDrawing(QGraphicsSceneMouseEvent *event)
Returns true if MaskAllItem can be drawn. Only one item of such type is allowed.
bool isValidForRectangleShapeDrawing(QGraphicsSceneMouseEvent *event)
Returns true if mouse click is valid for rectangular/elliptic/ROI shapes.
void onRowsInserted(const QModelIndex &, int, int)
bool isValidForPolygonDrawing(QGraphicsSceneMouseEvent *event)
Returns true if mouse click is in context suitable for polygon drawing.
void setItemName(SessionItem *itemToChange)
Sets item name depending on alreay existent items.
MaskDrawingContext m_context
QModelIndex m_maskContainerIndex
bool isValidForLineDrawing(QGraphicsSceneMouseEvent *event)
Returns true if mouse click is in context suitable for line drawing.
QMap< SessionItem *, IShape2DView * > m_ItemToView
void onRowsRemoved(const QModelIndex &, int, int)
void makeViewAtMousePosSelected(QGraphicsSceneMouseEvent *event)
void updateProxyWidget()
Updates proxy widget for intensity data item.
void onSessionSelectionChanged(const QItemSelection &, const QItemSelection &)
Propagates selection from model to scene.
void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void updateCursors()
Change cursor to stress that hovered item is movable (when not in PanZoom mode)
SessionItem * m_currentItem
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Creates item context menu if there is IMaskView beneath the mouse right click.
QSharedPointer< ISceneAdaptor > m_adaptor
void onActivityModeChanged(MaskEditorFlags::Activity value)
static const QString P_MASK_VALUE
Definition: MaskItems.h:33
static IShape2DView * createMaskView(SessionItem *item, ISceneAdaptor *adaptor=0)
static const QString P_POSX
Definition: MaskItems.h:57
static const QString P_POSY
Definition: MaskItems.h:58
This is a View of polygon mask (represented by PolygonItem) on GraphicsScene.
Definition: PolygonView.h:23
static const QString P_XUP
Definition: MaskItems.h:43
static const QString P_YLOW
Definition: MaskItems.h:42
static const QString P_YUP
Definition: MaskItems.h:44
static const QString P_XLOW
Definition: MaskItems.h:41
QString itemName() const
Get item name, return display name if no name is set.
void setItemName(const QString &name)
Set item name, add property if necessary.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
QString modelType() const
Get model type.
SessionItem * itemForIndex(const QModelIndex &index) const
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:125
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")
QModelIndex indexOfItem(SessionItem *item) const
static const QString P_POSX
Definition: MaskItems.h:73