BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskGraphicsScene.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/MaskGraphicsScene.h
6 //! @brief Defines 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 
15 #ifndef BORNAGAIN_GUI_VIEW_MASK_MASKGRAPHICSSCENE_H
16 #define BORNAGAIN_GUI_VIEW_MASK_MASKGRAPHICSSCENE_H
17 
20 #include <QGraphicsScene>
21 #include <QMap>
22 #include <QModelIndex>
23 #include <QSharedPointer>
24 
25 class SessionModel;
26 class SessionItem;
27 class IShape2DView;
28 class ISceneAdaptor;
29 class MaskGraphicsProxy;
30 class QItemSelectionModel;
31 class QItemSelection;
32 class PolygonView;
33 class MaskEditorAction;
34 class IntensityDataItem;
35 class QGraphicsSceneMouseEvent;
36 class QPainter;
37 class ColorMap;
38 
39 //! Graphics scene for MaskEditorCanvas to draw masks on top of intensity data widgets.
40 
41 class MaskGraphicsScene : public QGraphicsScene {
42  Q_OBJECT
43 public:
44  MaskGraphicsScene(QObject* parent = nullptr);
45  ~MaskGraphicsScene() override;
46 
47  void setMaskContext(SessionModel* model, const QModelIndex& maskContainerIndex,
48  IntensityDataItem* intensityItem);
49 
50  void resetContext();
51 
52  void setSelectionModel(QItemSelectionModel* model);
53 
54  ColorMap* colorMap();
55 signals:
56  void itemContextMenuRequest(const QPoint& point);
57 
58 public slots:
59  void onActivityModeChanged(MaskEditorFlags::Activity value);
60  void onMaskValueChanged(MaskEditorFlags::MaskValue value);
61  void onRowsInserted(const QModelIndex&, int, int);
62  void onRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last);
63  void onRowsRemoved(const QModelIndex&, int, int);
64  void cancelCurrentDrawing();
65  void resetScene();
66  void updateScene();
67 
68 private slots:
69  void onSessionSelectionChanged(const QItemSelection& /* selected */,
70  const QItemSelection& /* deselected */);
72 
73 protected:
74  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
75  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
76  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
77  void drawForeground(QPainter* painter, const QRectF& rect) override;
78  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
79 
80 private:
81  void updateProxyWidget();
82  void updateViews(const QModelIndex& parentIndex = {}, IShape2DView* parentView = nullptr);
84  void deleteViews(const QModelIndex& parentIndex);
86 
87  bool isValidMouseClick(QGraphicsSceneMouseEvent* event);
88  bool isValidForRectangleShapeDrawing(QGraphicsSceneMouseEvent* event);
89  bool isValidForPolygonDrawing(QGraphicsSceneMouseEvent* event);
90  bool isValidForLineDrawing(QGraphicsSceneMouseEvent* event);
91  bool isValidForMaskAllDrawing(QGraphicsSceneMouseEvent* event);
92 
93  bool isAreaContains(QGraphicsSceneMouseEvent* event, MaskEditorHelper::EViewTypes viewType);
94  bool isDrawingInProgress() const;
95  void setDrawingInProgress(bool value);
96  void setInPanAndZoomMode(bool value);
97  void updateCursors();
98 
99  void makeViewAtMousePosSelected(QGraphicsSceneMouseEvent* event);
100 
101  void processRectangleShapeItem(QGraphicsSceneMouseEvent* event);
102  void processPolygonItem(QGraphicsSceneMouseEvent* event);
103  void processLineItem(QGraphicsSceneMouseEvent* event);
104  void processVerticalLineItem(const QPointF& pos);
105  void processHorizontalLineItem(const QPointF& pos);
106  void processMaskAllItem(QGraphicsSceneMouseEvent* event);
107 
108  void setZValues();
109  PolygonView* currentPolygon() const;
110  void setItemName(SessionItem* itemToChange);
111 
113  QItemSelectionModel* m_selectionModel;
114  QMap<SessionItem*, IShape2DView*> m_ItemToView;
116  QSharedPointer<ISceneAdaptor> m_adaptor;
118  QModelIndex m_maskContainerIndex;
123 };
124 
125 #endif // BORNAGAIN_GUI_VIEW_MASK_MASKGRAPHICSSCENE_H
Defines class MaskDrawingContext.
Defines class MaskEditorHelper.
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
Interface to adapt MaskItems coordinates (expressed in units of IntensityDataItem) to/from scene coor...
Definition: ISceneAdaptor.h:24
Main interface class for views representing MaskItems, Projections on graphics scene.
Definition: IShape2DView.h:27
Helper class for MaskGraphicsScene to hold drawing conditions.
Graphics proxy to place QWidget inside QGraphicsScene, used by MaskEditorCanvas.
Graphics scene for MaskEditorCanvas to draw masks on top of intensity data widgets.
PolygonView * currentPolygon() const
Returns polygon which is currently under the drawing.
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.
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. Item with irow=0 is the t...
void setDrawingInProgress(bool value)
void processPolygonItem(QGraphicsSceneMouseEvent *event)
void processMaskAllItem(QGraphicsSceneMouseEvent *event)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void setInPanAndZoomMode(bool value)
Sets the state of all views in pan&zoom mode. In pan&zoom mode, the selection is removed,...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Finalizes item drawing or pass events to other items.
QItemSelectionModel * m_selectionModel
void processHorizontalLineItem(const QPointF &pos)
void onMaskValueChanged(MaskEditorFlags::MaskValue value)
IntensityDataItem * m_intensityItem
void processRectangleShapeItem(QGraphicsSceneMouseEvent *event)
Processes RectangleItem and EllipseItem drawing If the mouse move distance with left button down is l...
bool isDrawingInProgress() const
void removeItemViewFromScene(SessionItem *item)
Removes single view from scene.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
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.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
Creates item context menu if there is IMaskView beneath the mouse right click.
void deleteViews(const QModelIndex &parentIndex)
Recursive delete of all views corresponding to given index.
bool isValidForMaskAllDrawing(QGraphicsSceneMouseEvent *event)
Returns true if MaskAllItem can be drawn. Only one item of such type is allowed.
void updateViews(const QModelIndex &parentIndex={}, IShape2DView *parentView=nullptr)
Recutsively runs through the model and creates corresponding views.
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. If there is already "Rectangle1",...
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 drawForeground(QPainter *painter, const QRectF &rect) override
Draws dashed line to the current mouse position in the case of ungoing line or polygon drawing.
void makeViewAtMousePosSelected(QGraphicsSceneMouseEvent *event)
MaskGraphicsScene(QObject *parent=nullptr)
void updateProxyWidget()
Updates proxy widget for intensity data item.
void onSessionSelectionChanged(const QItemSelection &, const QItemSelection &)
Propagates selection from model to scene.
~MaskGraphicsScene() override
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
QSharedPointer< ISceneAdaptor > m_adaptor
void onActivityModeChanged(MaskEditorFlags::Activity value)
This is a View of polygon mask (represented by PolygonItem) on GraphicsScene.
Definition: PolygonView.h:26
Base class for a GUI data item.
Definition: SessionItem.h:204
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42