BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskEditorCanvas.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/MaskEditorCanvas.cpp
6 //! @brief Implements class MaskEditorCanvas
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 
26 #include <QVBoxLayout>
27 
29  : QWidget(parent)
30  , m_scene(new MaskGraphicsScene(this))
31  , m_view(new MaskGraphicsView(m_scene))
32  , m_intensityDataItem(nullptr)
33  , m_statusLabel(new PlotStatusLabel(nullptr, this))
34  , m_resultsPresenter(new MaskResultsPresenter(this))
35 {
36  setObjectName("MaskEditorCanvas");
37  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
38 
39  auto* mainLayout = new QVBoxLayout;
40  mainLayout->addWidget(m_view);
41  mainLayout->addWidget(m_statusLabel);
42  mainLayout->setMargin(0);
43  mainLayout->setSpacing(0);
44  setLayout(mainLayout);
45 
50 }
51 
52 void MaskEditorCanvas::setMaskContext(SessionModel* model, const QModelIndex& maskContainerIndex,
53  IntensityDataItem* intensityItem)
54 {
55  m_intensityDataItem = intensityItem;
56 
57  m_scene->setMaskContext(model, maskContainerIndex, intensityItem);
58  m_resultsPresenter->setMaskContext(model, maskContainerIndex, intensityItem);
59  m_view->updateSize(m_view->size());
60 
62 }
63 
65 {
66  m_intensityDataItem = nullptr;
69 }
70 
71 void MaskEditorCanvas::setSelectionModel(QItemSelectionModel* model)
72 {
73  m_scene->setSelectionModel(model);
74 }
75 
77 {
78  return m_scene;
79 }
80 
81 void MaskEditorCanvas::onPresentationTypeRequest(MaskEditorFlags::PresentationType presentationType)
82 {
83  m_scene->clearSelection(); // important to avoid crash (unsubscribe while calling subscribers)
84  m_resultsPresenter->updatePresenter(presentationType);
85 
86  if (auto* container = m_intensityDataItem->maskContainerItem()) {
87  bool isVisible = presentationType.testFlag(MaskEditorFlags::MASK_EDITOR);
88  for (MaskItem* mask : container->maskItems())
89  mask->setIsVisibleValue(isVisible);
90  }
91 }
92 
93 //! Saves plot into project directory.
94 
96 {
97  QString dirname = gSessionData->projectDocument.value()->userExportDir();
98 
101 }
102 
104 {
106 
107  if (isAxisRangeMatchData())
108  setZoomToROI();
109  else
111 }
112 
113 //! Returns true if IntensityData is currently at 100% zoom level
114 
116 {
117  ASSERT(m_intensityDataItem);
118 
120  return false;
122  return false;
124  return false;
126  return false;
127  return true;
128 }
129 
131 {
132  if (MaskContainerItem* maskContainer = m_intensityDataItem->maskContainerItem()) {
133  if (auto* roiItem = maskContainer->regionOfInterestItem()) {
134  m_intensityDataItem->setLowerX(roiItem->xLow());
135  m_intensityDataItem->setUpperX(roiItem->xUp());
136  m_intensityDataItem->setLowerY(roiItem->yLow());
137  m_intensityDataItem->setUpperY(roiItem->yUp());
138  }
139  }
140 }
Defines class ColorMap.
Defines class IntensityDataItem.
Defines class MaskEditorCanvas.
Defines class MaskGraphicsScene.
Defines class MaskGraphicsView.
Defines MaskItems classes.
Defines class MaskResultsPresenter.
Defines class PlotStatusLabel.
Defines class ProjectDocument.
Defines class SavePlotAssistant.
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
Defines struct SessionData.
QCustomPlot * customPlot() override
Definition: ColorMap.h:45
Datafield * getDatafield()
Definition: DataItem.h:41
void setLowerX(double value)
MaskContainerItem * maskContainerItem()
double xMin() const
Returns min and max range of x-axis as given by IntensityData.
void setLowerY(double value)
double getLowerY() const
Returns lower and upper zoom ranges of y-axis.
void resetView()
Set axes viewport to original data.
void setUpperX(double value)
double getUpperY() const
double getUpperX() const
void setUpperY(double value)
double getLowerX() const
Returns lower and upper zoom ranges of x-axis.
double yMin() const
Returns min and max range of y-axis as given by IntensityData.
Container holding various masks as children.
Definition: MaskItems.h:202
void deleteSelectedRequest()
void onSavePlotRequest()
Saves plot into project directory.
MaskGraphicsView * m_view
bool isAxisRangeMatchData() const
Returns true if IntensityData is currently at 100% zoom level.
PlotStatusLabel * m_statusLabel
void changeActivityRequest(MaskEditorFlags::Activity)
MaskGraphicsScene * getScene()
void onPresentationTypeRequest(MaskEditorFlags::PresentationType presentationType)
MaskResultsPresenter * m_resultsPresenter
IntensityDataItem * m_intensityDataItem
void setSelectionModel(QItemSelectionModel *model)
MaskGraphicsScene * m_scene
void setMaskContext(SessionModel *model, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
MaskEditorCanvas(QWidget *parent=nullptr)
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)
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.
A base class for all mask items.
Definition: MaskItems.h:27
Updates bin values inside IntensityData to display current mask state. Returns IntensityData to origi...
void setMaskContext(SessionModel *maskModel, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void updatePresenter(MaskEditorFlags::PresentationType presentationType)
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)
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42
void savePlot(const QString &dirname, QCustomPlot *plot, Datafield *output_data)
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27