BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectionsEditorCanvas.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Projection/ProjectionsEditorCanvas.cpp
6 //! @brief Implements class ProjectionsEditorCanvas
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 <QItemSelectionModel>
25 #include <QVBoxLayout>
26 
27 #include <boost/polymorphic_cast.hpp>
28 
29 using boost::polymorphic_downcast;
30 
32  : QWidget(parent)
33  , m_scene(new MaskGraphicsScene(this))
34  , m_view(new MaskGraphicsView(m_scene))
35  , m_colorMap(nullptr)
36  , m_statusLabel(new PlotStatusLabel(nullptr, this))
37  , m_liveProjection(nullptr)
38  , m_model(nullptr)
39  , m_intensityDataItem(nullptr)
40  , m_currentActivity(MaskEditorFlags::HORIZONTAL_LINE_MODE)
41  , m_block_update(false)
42 {
43  setObjectName("MaskEditorCanvas");
44  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
45 
46  auto* mainLayout = new QVBoxLayout;
47  mainLayout->addWidget(m_view);
48  mainLayout->addWidget(m_statusLabel);
49  mainLayout->setMargin(0);
50  mainLayout->setSpacing(0);
51  setLayout(mainLayout);
52 
57 }
58 
60  const QModelIndex& shapeContainerIndex,
61  IntensityDataItem* intensityItem)
62 {
63  m_model = model;
64  m_scene->setMaskContext(model, shapeContainerIndex, intensityItem);
65  m_view->updateSize(m_view->size());
66 
67  m_containerIndex = shapeContainerIndex;
68  m_intensityDataItem = intensityItem;
69 
71 
73 }
74 
76 {
77  m_intensityDataItem = nullptr;
78  m_containerIndex = {};
79  setConnected(false);
80  m_colorMap = nullptr;
82 }
83 
84 void ProjectionsEditorCanvas::setSelectionModel(QItemSelectionModel* model)
85 {
86  getScene()->setSelectionModel(model);
87 }
88 
90 {
92  return;
93 
94  m_block_update = true;
95 
100 
101  if (m_liveProjection)
103 
104  m_block_update = false;
105 }
106 
108 {
109  if (m_block_update)
110  return;
111 
112  m_block_update = true;
113 
114  if (m_liveProjection) {
117  delete m_liveProjection;
118  m_liveProjection = nullptr;
119  }
120 
121  m_block_update = false;
122 }
123 
125 {
126  if (m_block_update)
127  return;
128 
129  m_block_update = true;
130 
131  if (m_liveProjection) {
133  polymorphic_downcast<HorizontalLineItem*>(m_liveProjection)->setPosY(y);
135  polymorphic_downcast<VerticalLineItem*>(m_liveProjection)->setPosX(x);
136  }
137 
138  m_block_update = false;
139 }
140 
142 {
145 }
146 
147 void ProjectionsEditorCanvas::onActivityModeChanged(MaskEditorFlags::Activity value)
148 {
149  m_currentActivity = value;
152 }
153 
155 {
156  ASSERT(colorMap);
157  setConnected(false);
158 
159  m_colorMap = colorMap;
160  setConnected(true);
161 
162  m_statusLabel->reset();
163  m_statusLabel->addPlot(colorMap);
164 }
165 
167 {
168  if (!m_colorMap)
169  return;
170 
171  if (isConnected) {
173  &ProjectionsEditorCanvas::onEnteringColorMap, Qt::UniqueConnection);
175  &ProjectionsEditorCanvas::onLeavingColorMap, Qt::UniqueConnection);
177  &ProjectionsEditorCanvas::onPositionChanged, Qt::UniqueConnection);
178  connect(m_colorMap, &ColorMap::marginsChanged, this,
179  &ProjectionsEditorCanvas::marginsChanged, Qt::UniqueConnection);
180  }
181 
182  else {
189  disconnect(m_colorMap, &ColorMap::marginsChanged, this,
191  }
192 }
Defines class ColorMap.
Defines class IntensityDataItem.
Defines class MaskGraphicsScene.
Defines class MaskGraphicsView.
Defines MaskItems classes.
Defines class PlotStatusLabel.
Defines class ProjectionsEditorCanvas.
Defines class ScientificPlotEvent.
Defines class SessionModel.
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
void marginsChanged(double left, double right)
void resetView()
Set axes viewport to original data.
Help class to define various flags for MaskEditor operation.
Graphics scene for MaskEditorCanvas to draw masks on top of intensity data widgets.
void setSelectionModel(QItemSelectionModel *model)
void setMaskContext(SessionModel *model, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void onActivityModeChanged(MaskEditorFlags::Activity value)
Graphics view for MaskEditorCanvas.
void changeActivityRequest(MaskEditorFlags::Activity)
void updateSize(const QSize &newSize)
void deleteSelectedRequest()
void onResetViewRequest()
Reset given view to original zoom state. Also asks graphics scene to do the same with color map.
void setIsVisibleValue(bool visible)
Definition: MaskItems.cpp:100
The PlotStatusLabel class shows status string as reported by DescriptedPlot in a frame....
void reset()
Disconnects all color maps from the label.
void addPlot(ScientificPlot *plot)
void setSelectionModel(QItemSelectionModel *model)
MaskEditorFlags::Activity m_currentActivity
void onActivityModeChanged(MaskEditorFlags::Activity value)
void onPositionChanged(double x, double y)
ProjectionsEditorCanvas(QWidget *parent=nullptr)
MaskItem * m_liveProjection
temporary projection item matching mouse move
void changeActivityRequest(MaskEditorFlags::Activity)
void setConnected(bool isConnected)
void setContext(SessionModel *model, const QModelIndex &shapeContainerIndex, IntensityDataItem *intensityItem)
void marginsChanged(double left, double right)
void setColorMap(ColorMap *colorMap)
MaskGraphicsScene * getScene()
IntensityDataItem * m_intensityDataItem
void positionChanged(double x, double y)
ScientificPlotEvent * plotEvent()
int rowOfChild(SessionItem *child) const
Returns row index of given child.
SessionItem * takeRow(int row)
Removes row from item and returns the item.
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:137