BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
layerelementcontroller.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/sldeditor/layerelementcontroller.h
6 //! @brief Defines class 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 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI2_SLDEDITOR_LAYERELEMENTCONTROLLER_H
16 #define BORNAGAIN_GUI2_SLDEDITOR_LAYERELEMENTCONTROLLER_H
17 
18 #include "darefl_export.h"
20 #include <QObject>
21 #include <QPainterPath>
22 #include <vector>
23 
24 namespace gui2 {
25 
26 // The mvvm item associated to this layer
27 class LayerElementItem;
28 // The graphics scene to put the QGraphicsViewItem on
29 class GraphicsScene;
30 // The handle QGraphicsViewItem
31 class HandleElementView;
32 // The segment QGraphicsViewItem
33 class SegmentElementView;
34 // The roughness QGraphicsViewItem
35 class RoughnessElementView;
36 
37 //! Manages the whole appearance of a layer on the graphicsscene
38 class DAREFLCORE_EXPORT LayerElementController : public QObject {
39  Q_OBJECT
40 
41 public:
42  LayerElementController(LayerElementItem* layer_view_item);
43  LayerElementItem* layerElementItem() const;
44  void autoPopulate();
45  void deleteViewItems();
46  void connectToModel() const;
47  void disconnectFormModel() const;
48 
49  // ##################################################################################
50  // Scene management related
51  void setScene(GraphicsScene* scene);
52  GraphicsScene* scene() const;
53  void unsetScene();
54 
55  // ##################################################################################
56  // Sample id management related
57  void setSampleItemId(std::string indentifier);
58  std::string sampleItemId() const;
59  void unsetSampleItemId();
60 
61  // ##################################################################################
62  // Inter layer logic related
63  void setLayerAbove(LayerElementController* layer_view_controller);
64  void setLayerBelow(LayerElementController* layer_view_controller);
65  LayerElementController* layerAbove() const;
66  LayerElementController* layerBelow() const;
67  void unsetLayerAbove(bool silent = true);
68  void unsetLayerBelow(bool silent = true);
69 
70  // ##################################################################################
71  // Segment related public methods
72  void setSideSegment(SegmentElementView* segment_view);
73  void setTopSegment(SegmentElementView* segment_view);
74  SegmentElementView* sideSegment() const;
75  SegmentElementView* topSegment() const;
76  void unsetSideSegment();
77  void unsetTopSegment();
78  void segmentViewMoved(SegmentElementView* segment_view);
79 
80  // ##################################################################################
81  // Handle related public methods
82  void setSegmentHandles(HandleElementView* first_handle, HandleElementView* secondHandle);
83  HandleElementView* firstSegmentHandle() const;
84  HandleElementView* secondSegmentHandle() const;
85  void unsetSegmentHandles();
86  void handleViewMoved(HandleElementView* handle_view);
87 
88  // ##################################################################################
89  // Roughness related
90  void setRoughness(RoughnessElementView* roughness_view);
91  void setRoughnessHandles(HandleElementView* first_handle_view,
92  HandleElementView* second_handle_view);
93  RoughnessElementView* roughness() const;
94  HandleElementView* leftRoughnessHandle() const;
95  HandleElementView* rightRoughnessHandle() const;
96  void unsetRoughness();
97  void unsetRoughnessHandles();
98  void updateRoughness() const;
99 
100 signals:
101  void heightChanged(std::string id, double value) const;
102  void widthChanged(std::string id, double value) const;
103  void roughnessChanged(std::string id, double value) const;
104 
105 private:
106  ModelView::SceneAdapterInterface* sceneAdapter() const;
107 
108 protected:
109  // ##################################################################################
110  // Segment related protected methods
111  void updateSideSegment() const;
112  void updateTopSegment() const;
113  QRectF sideSegmentRect() const;
114  QRectF topSegmentRect() const;
115  void putSegementsOnScene() const;
116  void removeSegmentsFromScene() const;
117 
118  void sideSegmentMoved() const;
119  void topSegmentMoved() const;
120 
121  // ##################################################################################
122  // Handle related protected methods
123  void updateSegmentHandles() const;
124  QRectF firstSegmentHandleRect() const;
125  QRectF secondSegmentHandleRect() const;
126  void putSegmentHandlesOnScene() const;
127  void removeSegmentHandlesFromScene() const;
128 
129  // ##################################################################################
130  // Roughness related protected methods
131  QPainterPath leftRoughnessPath() const;
132  QPainterPath rightRoughnessPath() const;
133  QRectF leftRoughnessHandleRect() const;
134  QRectF rightRoughnessHandleRect() const;
135  void putRoughnessOnScene() const;
136  void putRoughnessHandlesOnScene() const;
137  void removeRoughnessFromScene() const;
138  void removeRoughnessHandlesFromScene() const;
139  void setRoughnessInLimits(double roughness, bool active = true) const;
140 
141  void leftHandleMoved() const;
142  void rightHandleMoved() const;
143 
144 private:
146  GraphicsScene* p_scene = nullptr;
147  std::string m_sample_item_id;
148 
149  std::vector<SegmentElementView*> m_segment_views = {nullptr, nullptr};
150  std::vector<HandleElementView*> m_handle_views = {nullptr, nullptr};
151  std::vector<HandleElementView*> m_rough_handles_views = {nullptr, nullptr};
152  RoughnessElementView* p_roughness_view = nullptr;
153 
154  LayerElementController* p_controller_above = nullptr;
155  LayerElementController* p_controller_below = nullptr;
156 };
157 
158 } // namespace gui2
159 
160 #endif // BORNAGAIN_GUI2_SLDEDITOR_LAYERELEMENTCONTROLLER_H
Interface to convert coordinates of "scene" to coordinates of "widget".
Custom graphics scene to show QCustomPlot with additional elements on top.
Definition: graphicsscene.h:34
The handle QGraphicsViewItem on GraphicsScene.
Manages the whole appearance of a layer on the graphicsscene.
void widthChanged(std::string id, double value) const
void roughnessChanged(std::string id, double value) const
void heightChanged(std::string id, double value) const
The mvvm session item associated to a layer.
The roughness QGraphicsViewItem.
The segment QGraphicsViewItem on the Graphicsscene.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?