BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DesignerScene.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SampleDesigner/DesignerScene.h
6 //! @brief Defines class DesignerScene
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_COREGUI_VIEWS_SAMPLEDESIGNER_DESIGNERSCENE_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_SAMPLEDESIGNER_DESIGNERSCENE_H
17 
18 #include <QGraphicsScene>
19 #include <QMap>
20 #include <QModelIndex>
21 
22 class InstrumentModel;
23 class SampleModel;
24 class SessionItem;
26 class QItemSelectionModel;
27 class IView;
28 class QItemSelection;
30 class DesignerMimeData;
31 class SampleViewAligner;
32 class NodeEditor;
34 class MaterialModel;
35 
36 //! Main class which represents SessionModel on graphics scene
37 class DesignerScene : public QGraphicsScene {
38  Q_OBJECT
39 
40 public:
41  explicit DesignerScene(QObject* parent = 0);
42  virtual ~DesignerScene();
43 
44  void setSampleModel(SampleModel* sampleModel);
45  void setInstrumentModel(InstrumentModel* instrumentModel);
46  void setMaterialModel(MaterialModel* materialModel);
47  void setSelectionModel(QItemSelectionModel* model, FilterPropertyProxy* proxy);
48 
50 
52 
54 
55 signals:
57 
58 public slots:
60  void onSessionSelectionChanged(const QItemSelection&, const QItemSelection&);
61  void resetScene();
62  void updateScene();
63 
64  void onRowsInserted(const QModelIndex& parent, int first, int last);
65  void onRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last);
66  void onRowsRemoved(const QModelIndex& parent, int first, int last);
67 
68  void setLayerInterfaceLine(const QLineF& line = {})
69  {
71  invalidate();
72  }
73 
74  void deleteSelectedItems();
75 
76  void onEstablishedConnection(NodeEditorConnection*); // to process signals from NodeEditor
78 
79  void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
80  void dropEvent(QGraphicsSceneDragDropEvent* event);
81 
82  void onSmartAlign();
83 
84 protected:
85  void drawForeground(QPainter* painter, const QRectF& rect);
86  const DesignerMimeData* checkDragEvent(QGraphicsSceneDragDropEvent* event);
87  void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
88 
89 private:
91  void updateViews(const QModelIndex& parentIndex = {}, IView* parentView = 0);
92  void deleteViews(const QModelIndex& parentIndex);
93  void alignViews();
95  bool isMultiLayerNearby(QGraphicsSceneDragDropEvent* event);
96  void adjustSceneRect();
97  bool isAcceptedByMultiLayer(const DesignerMimeData* mimeData,
98  QGraphicsSceneDragDropEvent* event);
99  bool isLayerDragged() const;
100 
104  QItemSelectionModel* m_selectionModel;
107 
108  QMap<SessionItem*, IView*> m_ItemToView;
109  //!< Correspondance of model's item and scene's view
110 
112  //!< Foreground line representing appropriate interface during layer's movement
113 
115 
117 };
118 
119 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_SAMPLEDESIGNER_DESIGNERSCENE_H
Mime data for use with SampleDesigner drag and drop operations.
Main class which represents SessionModel on graphics scene.
Definition: DesignerScene.h:37
void setLayerInterfaceLine(const QLineF &line={})
Definition: DesignerScene.h:68
virtual ~DesignerScene()
SampleModel * getSampleModel()
Definition: DesignerScene.h:49
void updateViews(const QModelIndex &parentIndex={}, IView *parentView=0)
runs through all items recursively and updates corresponding views
bool m_block_selection
void deleteSelectedItems()
propagates deletion of views on the scene to the model
void selectionModeChangeRequest(int)
void deleteViews(const QModelIndex &parentIndex)
runs recursively through model's item and schedules view removal
void setInstrumentModel(InstrumentModel *instrumentModel)
SampleModel * m_sampleModel
void setMaterialModel(MaterialModel *materialModel)
QItemSelectionModel * m_selectionModel
QLineF m_layer_interface_line
Foreground line representing appropriate interface during layer's movement.
void onSessionSelectionChanged(const QItemSelection &, const QItemSelection &)
propagate selection from model to scene
void onRowsInserted(const QModelIndex &parent, int first, int last)
NodeEditor * getNodeEditor()
Definition: DesignerScene.h:53
void alignViews()
aligns SampleView's on graphical canvas
void drawForeground(QPainter *painter, const QRectF &rect)
shows appropriate layer interface to drop while moving ILayerView
void adjustSceneRect()
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
IView * getViewForItem(SessionItem *item)
QMap< SessionItem *, IView * > m_ItemToView
Correspondance of model's item and scene's view.
void setSampleModel(SampleModel *sampleModel)
const DesignerMimeData * checkDragEvent(QGraphicsSceneDragDropEvent *event)
returns proper MimeData if the object can be hadled by graphics scene
bool isMultiLayerNearby(QGraphicsSceneDragDropEvent *event)
Returns true if there is MultiLayerView nearby during drag event.
SampleViewAligner * m_aligner
void onSceneSelectionChanged()
propagate selection from scene to model
bool isLayerDragged() const
IView * addViewForItem(SessionItem *item)
adds view for item, if it doesn't exists
FilterPropertyProxy * m_proxy
void removeItemViewFromScene(SessionItem *item)
removes view from scene corresponding to given item
void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
handles drag event LayerView can be dragged only over MultiLayerView MultiLayerView can be dragged bo...
void removeConnection(NodeEditorConnection *)
propagates break of connection between views on scene to the model
DesignerScene(QObject *parent=0)
void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
NodeEditor * m_nodeEditor
void onRowsRemoved(const QModelIndex &parent, int first, int last)
void dropEvent(QGraphicsSceneDragDropEvent *event)
Hadles drop event LayerView can be dropped on MultiLayerView only MultiLayerView can be droped on the...
InstrumentModel * m_instrumentModel
bool isAcceptedByMultiLayer(const DesignerMimeData *mimeData, QGraphicsSceneDragDropEvent *event)
void onEstablishedConnection(NodeEditorConnection *)
propagates connection established by NodeEditor to the model
void setSelectionModel(QItemSelectionModel *model, FilterPropertyProxy *proxy)
MaterialModel * m_materialModel
The FilterPropertyProxy class filters out all PropertyItem's and similar from SessionModel to have on...
parent class for graphic representation of all ISampleNode's
Definition: IView.h:25
The NodeEditor class implement for QGraphicsScene an editable schematic of the dependency graph,...
Definition: NodeEditor.h:35
Main model to hold sample items.
Definition: SampleModel.h:24
Makes alignment of sample droped on graphics scene.