BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
PolygonView.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/PolygonView.h
6 //! @brief Defines PolygonView class
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_POLYGONVIEW_H
16 #define BORNAGAIN_GUI_VIEW_MASK_POLYGONVIEW_H
17 
19 #include <QPolygonF>
20 
21 class PolygonItem;
22 
23 
24 //! This is a View of polygon mask (represented by PolygonItem) on GraphicsScene.
25 
26 class PolygonView : public IShape2DView {
27  Q_OBJECT
28 
29 public:
30  int type() const override { return MaskEditorHelper::POLYGON; }
31 
32  explicit PolygonView(PolygonItem* item);
33  ~PolygonView() override;
34 
35  SessionItem* parameterizedItem() const override;
36 
37  void addView(IShape2DView* childView, int row) override;
38  bool isClosedPolygon();
39  QPointF lastAddedPoint() const;
40  QPainterPath shape() const override;
41 
42 public slots:
44  void onClosePolygonRequest(bool value);
45 
46 protected slots:
47  void update_view() override;
48 
49 protected:
50  void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override;
51  QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
52  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
53 
54 private:
55  void update_polygon();
56  void update_points();
57  void setChildrenVisible(bool value);
59  void onItemDestroyed() override;
60 
61 private:
63  QPolygonF m_polygon;
66 };
67 
68 #endif // BORNAGAIN_GUI_VIEW_MASK_POLYGONVIEW_H
Defines interface IShape2DView.
Main interface class for views representing MaskItems, Projections on graphics scene.
Definition: IShape2DView.h:27
This is a View of polygon mask (represented by PolygonItem) on GraphicsScene.
Definition: PolygonView.h:26
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void onClosePolygonRequest(bool value)
bool closePolygonIfNecessary()
Returns true if there was a request to close polygon (emitted by its start point),...
Definition: PolygonView.cpp:87
void onItemDestroyed() override
~PolygonView() override
Definition: PolygonView.cpp:37
int type() const override
Definition: PolygonView.h:30
PolygonView(PolygonItem *item)
Definition: PolygonView.cpp:26
bool m_close_polygon_request
Definition: PolygonView.h:65
QPointF lastAddedPoint() const
Returns last added poligon point in scene coordinates.
Definition: PolygonView.cpp:72
PolygonItem * m_item
Definition: PolygonView.h:62
QPolygonF m_polygon
Definition: PolygonView.h:63
void addView(IShape2DView *childView, int row) override
Definition: PolygonView.cpp:47
void update_view() override
void update_polygon()
Runs through all PolygonPointItem and calculate bounding rectangle. Determines position of the rectan...
bool makePolygonClosed()
bool isClosedPolygon()
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
QPainterPath shape() const override
Definition: PolygonView.cpp:77
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
SessionItem * parameterizedItem() const override
Definition: PolygonView.cpp:42
void update_points()
When polygon moves as a whole thing across the scene, given method updates coordinates of PolygonPoin...
bool m_block_on_point_update
Definition: PolygonView.h:64
void setChildrenVisible(bool value)
Base class for a GUI data item.
Definition: SessionItem.h:204