BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectionsPlot Class Reference

Description

A customplot based widget to display projections of IntensityDataItem on X,Y axes.

Definition at line 30 of file ProjectionsPlot.h.

Inheritance diagram for ProjectionsPlot:
[legend]
Collaboration diagram for ProjectionsPlot:
[legend]

Public Slots

void onMarginsChanged (double left, double right)
 

Public Member Functions

 ProjectionsPlot (QString projectionType, QWidget *parent=nullptr)
 
 ~ProjectionsPlot () override
 
virtual QList< QAction * > actionList ()
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
virtual void setItem (SessionItem *item)
 

Protected Member Functions

void hideEvent (QHideEvent *) override
 
void onProjectionPropertyChanged (SessionItem *item, const QString &property)
 
void showEvent (QShowEvent *) override
 
void subscribeToItem () override
 
void unsubscribeFromItem () override
 

Private Member Functions

void clearProjection (SessionItem *item)
 Removes plot corresponding to given projection item. More...
 
void clearProjections ()
 Clears all graphs corresponding to projection items. More...
 
QCPGraph * graphForItem (SessionItem *item)
 
IntensityDataItemintensityItem ()
 
bool isHorizontalType ()
 Returns true, if widget is intended for horizontal projections. More...
 
void onAxisPropertyChanged (const QString &axisName, const QString &propertyName)
 Updates zoom of projections in accordance with IntensityDataItem. More...
 
void onIntensityItemPropertyChanged (const QString &propertyName)
 Updates projection appearance (line style, etc) More...
 
ProjectionContainerItemprojectionContainerItem ()
 
QVector< SessionItem * > projectionItems ()
 
void replot ()
 
void setGraphFromItem (QCPGraph *graph, SessionItem *item)
 Sets the data to graph from given projection iten. More...
 
void setInterpolate (bool isInterpolated)
 
void setLogz (bool isLogz)
 
void unsubscribeFromChildren ()
 
void updateAxesRange ()
 Updates canva's axes to match current zoom level of IntensityDataItem. More...
 
void updateAxesTitle ()
 
void updateProjections ()
 Runs through all projection items and generates missed plots. More...
 
void updateProjectionsData ()
 Creates cached 2D histogram for later projection calculations. More...
 

Private Attributes

bool m_block_plot_update
 
QCustomPlot * m_customPlot
 
std::unique_ptr< Datafield > m_field
 
QMap< SessionItem *, QCPGraph * > m_item_to_graph
 
SessionItemControllerm_itemController
 
QString m_projectionType
 

Constructor & Destructor Documentation

◆ ProjectionsPlot()

ProjectionsPlot::ProjectionsPlot ( QString  projectionType,
QWidget *  parent = nullptr 
)

Definition at line 31 of file ProjectionsPlot.cpp.

32  : SessionItemWidget(parent)
33  , m_projectionType(std::move(projectionType))
34  , m_customPlot(new QCustomPlot)
35  , m_block_plot_update(false)
36 {
37  auto* vlayout = new QVBoxLayout(this);
38  vlayout->setMargin(0);
39  vlayout->setSpacing(0);
40  vlayout->addWidget(m_customPlot);
41  m_customPlot->setAttribute(Qt::WA_NoMousePropagation, false);
42  setLayout(vlayout);
43 
44  m_customPlot->xAxis->setTickLabelFont(
45  QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
46  m_customPlot->yAxis->setTickLabelFont(
47  QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
48 
50 }
QCustomPlot * m_customPlot
QString m_projectionType
SessionItemWidget(QWidget *parent=nullptr)
int plot_tick_label_size()
Definition: PlotConstants.h:23
void setDefaultMargins(QCustomPlot *customPlot)
Sets default margins for axes rectangle plot.
Definition: RangeUtils.cpp:138

References m_customPlot, GUI::Constants::plot_tick_label_size(), and GUI::View::RangeUtils::setDefaultMargins().

Here is the call graph for this function:

◆ ~ProjectionsPlot()

ProjectionsPlot::~ProjectionsPlot ( )
override

Definition at line 52 of file ProjectionsPlot.cpp.

53 {
55 }
void unsubscribeFromChildren()

References unsubscribeFromChildren().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

QList< QAction * > SessionItemWidget::actionList ( )
virtualinherited

◆ clearProjection()

void ProjectionsPlot::clearProjection ( SessionItem item)
private

Removes plot corresponding to given projection item.

Definition at line 235 of file ProjectionsPlot.cpp.

236 {
237  if (auto* graph = graphForItem(item)) {
238  m_block_plot_update = true;
239  m_customPlot->removePlottable(graph);
240  m_item_to_graph.remove(item);
241  replot();
242  m_block_plot_update = false;
243  }
244 }
QCPGraph * graphForItem(SessionItem *item)
QMap< SessionItem *, QCPGraph * > m_item_to_graph

References graphForItem(), m_block_plot_update, m_customPlot, m_item_to_graph, and replot().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ clearProjections()

void ProjectionsPlot::clearProjections ( )
private

Clears all graphs corresponding to projection items.

Definition at line 221 of file ProjectionsPlot.cpp.

222 {
223  m_block_plot_update = true;
224 
225  m_customPlot->clearPlottables();
226  m_item_to_graph.clear();
227 
228  replot();
229 
230  m_block_plot_update = false;
231 }

References m_block_plot_update, m_customPlot, m_item_to_graph, and replot().

Referenced by unsubscribeFromItem().

Here is the call graph for this function:

◆ currentItem() [1/2]

◆ currentItem() [2/2]

const SessionItem * SessionItemWidget::currentItem ( ) const
inherited

Definition at line 46 of file SessionItemWidget.cpp.

47 {
48  return m_itemController->currentItem();
49 }
SessionItemController * m_itemController

References SessionItemController::currentItem(), and SessionItemWidget::m_itemController.

Here is the call graph for this function:

◆ graphForItem()

QCPGraph * ProjectionsPlot::graphForItem ( SessionItem item)
private

Definition at line 147 of file ProjectionsPlot.cpp.

148 {
149  if (item->modelType() != m_projectionType)
150  return nullptr;
151 
152  QCPGraph* graph = m_item_to_graph[item];
153  if (!graph) {
154  graph = m_customPlot->addGraph();
155  QPen pen;
156  pen.setColor(QColor(0, 0, 255, 200));
157  graph->setLineStyle(intensityItem()->isInterpolated() ? QCPGraph::lsLine
158  : QCPGraph::lsStepCenter);
159  graph->setPen(pen);
160  m_item_to_graph[item] = graph;
161  }
162 
163  return graph;
164 }
IntensityDataItem * intensityItem()
QString modelType() const
Get model type.

References intensityItem(), m_customPlot, m_item_to_graph, m_projectionType, and SessionItem::modelType().

Referenced by clearProjection(), onProjectionPropertyChanged(), and updateProjections().

Here is the call graph for this function:

◆ hideEvent()

void SessionItemWidget::hideEvent ( QHideEvent *  )
overrideprotectedinherited

Definition at line 56 of file SessionItemWidget.cpp.

57 {
59 }
void unsubscribe()
Fully unsubscribes the parent from listening item's signals. Controller stays active to track item de...

References SessionItemWidget::m_itemController, and SessionItemController::unsubscribe().

Here is the call graph for this function:

◆ intensityItem()

IntensityDataItem * ProjectionsPlot::intensityItem ( )
private

Definition at line 128 of file ProjectionsPlot.cpp.

129 {
130  auto* result = dynamic_cast<IntensityDataItem*>(currentItem());
131  ASSERT(result);
132  return result;
133 }

References SessionItemWidget::currentItem().

Referenced by graphForItem(), onAxisPropertyChanged(), onIntensityItemPropertyChanged(), projectionContainerItem(), subscribeToItem(), updateAxesRange(), updateAxesTitle(), and updateProjectionsData().

Here is the call graph for this function:

◆ isHorizontalType()

bool ProjectionsPlot::isHorizontalType ( )
private

Returns true, if widget is intended for horizontal projections.

Definition at line 316 of file ProjectionsPlot.cpp.

317 {
319 }
static constexpr auto M_TYPE
Definition: MaskItems.h:147

References m_projectionType, and HorizontalLineItem::M_TYPE.

Referenced by updateAxesRange(), and updateAxesTitle().

◆ onAxisPropertyChanged()

void ProjectionsPlot::onAxisPropertyChanged ( const QString &  axisName,
const QString &  propertyName 
)
private

Updates zoom of projections in accordance with IntensityDataItem.

Definition at line 258 of file ProjectionsPlot.cpp.

259 {
260  Q_UNUSED(axisName);
261 
262  if (BasicAxisItem::isBoundsPropertiesName(propertyName))
263  updateAxesRange();
264  else if (BasicAxisItem::isTitlePropertyName(propertyName))
265  updateAxesTitle();
266  else if (AmplitudeAxisItem::isLogScalePropertyName(propertyName))
267  setLogz(intensityItem()->isLogz());
268 
269  replot();
270 }
static bool isLogScalePropertyName(const QString &name)
Definition: AxesItems.cpp:193
static bool isBoundsPropertiesName(const QString &name)
either lower bound or upper bound property name
Definition: AxesItems.cpp:75
static bool isTitlePropertyName(const QString &name)
Definition: AxesItems.cpp:95
void updateAxesRange()
Updates canva's axes to match current zoom level of IntensityDataItem.
void setLogz(bool isLogz)

References intensityItem(), BasicAxisItem::isBoundsPropertiesName(), AmplitudeAxisItem::isLogScalePropertyName(), BasicAxisItem::isTitlePropertyName(), replot(), setLogz(), updateAxesRange(), and updateAxesTitle().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ onIntensityItemPropertyChanged()

void ProjectionsPlot::onIntensityItemPropertyChanged ( const QString &  propertyName)
private

Updates projection appearance (line style, etc)

Definition at line 248 of file ProjectionsPlot.cpp.

249 {
251  setInterpolate(intensityItem()->isInterpolated());
252  replot();
253  }
254 }
static bool isInterpolatedPropertyName(const QString &name)
void setInterpolate(bool isInterpolated)

References intensityItem(), IntensityDataItem::isInterpolatedPropertyName(), replot(), and setInterpolate().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ onMarginsChanged

void ProjectionsPlot::onMarginsChanged ( double  left,
double  right 
)
slot

Definition at line 57 of file ProjectionsPlot.cpp.

58 {
59  QMargins orig = m_customPlot->axisRect()->margins();
60  m_customPlot->axisRect()->setMargins(QMargins(left, orig.top(), right, orig.bottom()));
61  replot();
62 }

References m_customPlot, and replot().

Referenced by ProjectionsWidget::onMarginsChanged().

Here is the call graph for this function:

◆ onProjectionPropertyChanged()

void ProjectionsPlot::onProjectionPropertyChanged ( SessionItem item,
const QString &  property 
)
protected

Definition at line 114 of file ProjectionsPlot.cpp.

115 {
117  return;
118 
119  m_block_plot_update = true;
120 
121  if (auto* graph = graphForItem(item))
122  setGraphFromItem(graph, item);
123  replot();
124 
125  m_block_plot_update = false;
126 }
void setGraphFromItem(QCPGraph *graph, SessionItem *item)
Sets the data to graph from given projection iten.

References graphForItem(), m_block_plot_update, replot(), and setGraphFromItem().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ projectionContainerItem()

ProjectionContainerItem * ProjectionsPlot::projectionContainerItem ( )
private

Definition at line 135 of file ProjectionsPlot.cpp.

136 {
138  ASSERT(result);
139  return result;
140 }
ProjectionContainerItem * projectionContainerItem()
A container to hold ProjectionItems, intended to store projections of color map on X,...

References intensityItem(), and IntensityDataItem::projectionContainerItem().

Referenced by projectionItems(), subscribeToItem(), and unsubscribeFromChildren().

Here is the call graph for this function:

◆ projectionItems()

QVector< SessionItem * > ProjectionsPlot::projectionItems ( )
private

Definition at line 142 of file ProjectionsPlot.cpp.

143 {
145 }
ProjectionContainerItem * projectionContainerItem()
QVector< SessionItem * > childrenOfType(const QString &model_type) const
Returns a vector of all children of the given type.

References SessionItem::childrenOfType(), m_projectionType, and projectionContainerItem().

Referenced by updateProjections().

Here is the call graph for this function:

◆ replot()

void ProjectionsPlot::replot ( )
private

◆ setGraphFromItem()

void ProjectionsPlot::setGraphFromItem ( QCPGraph *  graph,
SessionItem item 
)
private

Sets the data to graph from given projection iten.

Definition at line 274 of file ProjectionsPlot.cpp.

275 {
276  std::unique_ptr<Datafield> field;
277 
278  // TODO: merge with very similar code in SaveProjectionsAssistant::projectionsData
279  if (item->modelType() == HorizontalLineItem::M_TYPE) {
280  double value = polymorphic_downcast<HorizontalLineItem*>(item)->posY();
281  field.reset(m_field->xProjection(value));
282  } else {
283  double value = polymorphic_downcast<VerticalLineItem*>(item)->posX();
284  field.reset(m_field->yProjection(value));
285  }
286 
287 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
288  auto centers = field->axis(0).binCenters();
289  auto values = field->flatVector();
290  graph->setData(QVector<double>(centers.begin(), centers.end()),
291  QVector<double>(values.begin(), values.end()));
292 #else
293  graph->setData(QVector<double>::fromStdVector(hist->binCenters()),
294  QVector<double>::fromStdVector(hist->binValues()));
295 #endif
296 }
std::unique_ptr< Datafield > m_field

References m_field, HorizontalLineItem::M_TYPE, and SessionItem::modelType().

Referenced by onProjectionPropertyChanged(), and updateProjections().

Here is the call graph for this function:

◆ setInterpolate()

void ProjectionsPlot::setInterpolate ( bool  isInterpolated)
private

Definition at line 298 of file ProjectionsPlot.cpp.

299 {
300  for (auto* graph : m_item_to_graph)
301  graph->setLineStyle(isInterpolated ? QCPGraph::lsLine : QCPGraph::lsStepCenter);
302 }

References m_item_to_graph.

Referenced by onIntensityItemPropertyChanged().

◆ setItem()

◆ setLogz()

void ProjectionsPlot::setLogz ( bool  isLogz)
private

Definition at line 304 of file ProjectionsPlot.cpp.

305 {
307 }
void setLogz(QCPColorScale *scale, bool isLogz)
Definition: RangeUtils.cpp:110

References m_customPlot, and GUI::View::RangeUtils::setLogz().

Referenced by onAxisPropertyChanged(), and updateProjectionsData().

Here is the call graph for this function:

◆ showEvent()

void SessionItemWidget::showEvent ( QShowEvent *  )
overrideprotectedinherited

Definition at line 51 of file SessionItemWidget.cpp.

52 {
54 }

References SessionItemWidget::m_itemController, and SessionItemController::subscribe().

Here is the call graph for this function:

◆ subscribeToItem()

void ProjectionsPlot::subscribeToItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 64 of file ProjectionsPlot.cpp.

65 {
66  // Update projection plot on new item appearance
68  [this](SessionItem* item) {
69  if (item)
71  },
72  this);
73 
74  // Remove projection plot
76  [this](SessionItem* item) { clearProjection(item); }, this);
77 
78  // Update projection position
80  [this](SessionItem* item, const QString& name) { onProjectionPropertyChanged(item, name); },
81  this);
82 
83  // Values of intensity changed, regenerate everything.
85  [this]() {
88  },
89  this);
90 
91  // IntensityItem property (e.g. interpolation changed)
93  [this](const QString& name) { onIntensityItemPropertyChanged(name); }, this);
94 
95  // Update to changed IntensityDataItem axes
97  [this](SessionItem* item, const QString name) {
98  if (item->modelType() == BasicAxisItem::M_TYPE
101  },
102  this);
103 
106 }
static constexpr auto M_TYPE
Definition: AxesItems.h:81
static constexpr auto M_TYPE
Definition: AxesItems.h:35
void setOnAboutToRemoveChild(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:72
void setOnChildrenChange(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Calls back when number of children has changed, reports newChild. newChild == nullptr denotes the cas...
Definition: ModelMapper.cpp:62
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
void setOnValueChange(std::function< void(void)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:34
void setOnChildPropertyChange(std::function< void(SessionItem *, QString)> f, const void *caller=nullptr)
Calls back on child property change, report childItem and property name.
Definition: ModelMapper.cpp:53
void updateProjectionsData()
Creates cached 2D histogram for later projection calculations.
void onIntensityItemPropertyChanged(const QString &propertyName)
Updates projection appearance (line style, etc)
void clearProjection(SessionItem *item)
Removes plot corresponding to given projection item.
void updateProjections()
Runs through all projection items and generates missed plots.
void onAxisPropertyChanged(const QString &axisName, const QString &propertyName)
Updates zoom of projections in accordance with IntensityDataItem.
void onProjectionPropertyChanged(SessionItem *item, const QString &property)
QString itemName() const
Get item name, return display name if no name is set.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
QString const & name(EShape k)
Definition: particles.cpp:20

References clearProjection(), intensityItem(), SessionItem::itemName(), BasicAxisItem::M_TYPE, AmplitudeAxisItem::M_TYPE, SessionItem::mapper(), SessionItem::modelType(), GUI::RealSpace::Particles::name(), onAxisPropertyChanged(), onIntensityItemPropertyChanged(), onProjectionPropertyChanged(), projectionContainerItem(), ModelMapper::setOnAboutToRemoveChild(), ModelMapper::setOnChildPropertyChange(), ModelMapper::setOnChildrenChange(), ModelMapper::setOnPropertyChange(), ModelMapper::setOnValueChange(), updateProjections(), and updateProjectionsData().

Here is the call graph for this function:

◆ unsubscribeFromChildren()

void ProjectionsPlot::unsubscribeFromChildren ( )
private

Definition at line 166 of file ProjectionsPlot.cpp.

167 {
168  if (currentItem())
170 }
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78

References SessionItemWidget::currentItem(), SessionItem::mapper(), projectionContainerItem(), and ModelMapper::unsubscribe().

Referenced by ~ProjectionsPlot(), and unsubscribeFromItem().

Here is the call graph for this function:

◆ unsubscribeFromItem()

void ProjectionsPlot::unsubscribeFromItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 108 of file ProjectionsPlot.cpp.

109 {
112 }
void clearProjections()
Clears all graphs corresponding to projection items.

References clearProjections(), and unsubscribeFromChildren().

Here is the call graph for this function:

◆ updateAxesRange()

void ProjectionsPlot::updateAxesRange ( )
private

Updates canva's axes to match current zoom level of IntensityDataItem.

Definition at line 201 of file ProjectionsPlot.cpp.

202 {
203  if (isHorizontalType())
205  else
207 
209 }
bool isHorizontalType()
Returns true, if widget is intended for horizontal projections.
QCPRange itemZoomY(const IntensityDataItem *item)
Returns y-axis vizible range (zoom).
Definition: RangeUtils.cpp:94
QCPRange itemDataZoom(const IntensityDataItem *item)
Returns z-axis visible range (zoom).
Definition: RangeUtils.cpp:105
QCPRange itemZoomX(const IntensityDataItem *item)
Returns x-axis vizible range (zoom).
Definition: RangeUtils.cpp:84

References intensityItem(), isHorizontalType(), GUI::View::RangeUtils::itemDataZoom(), GUI::View::RangeUtils::itemZoomX(), GUI::View::RangeUtils::itemZoomY(), and m_customPlot.

Referenced by onAxisPropertyChanged(), and updateProjectionsData().

Here is the call graph for this function:

◆ updateAxesTitle()

void ProjectionsPlot::updateAxesTitle ( )
private

Definition at line 211 of file ProjectionsPlot.cpp.

212 {
213  if (isHorizontalType())
214  m_customPlot->xAxis->setLabel(intensityItem()->getXaxisTitle());
215  else
216  m_customPlot->xAxis->setLabel(intensityItem()->getYaxisTitle());
217 }

References intensityItem(), isHorizontalType(), and m_customPlot.

Referenced by onAxisPropertyChanged(), and updateProjectionsData().

Here is the call graph for this function:

◆ updateProjections()

void ProjectionsPlot::updateProjections ( )
private

Runs through all projection items and generates missed plots.

Definition at line 184 of file ProjectionsPlot.cpp.

185 {
187  return;
188 
189  m_block_plot_update = true;
190 
191  for (auto* projItem : projectionItems())
192  setGraphFromItem(graphForItem(projItem), projItem);
193 
194  replot();
195 
196  m_block_plot_update = false;
197 }
QVector< SessionItem * > projectionItems()

References graphForItem(), m_block_plot_update, projectionItems(), replot(), and setGraphFromItem().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ updateProjectionsData()

void ProjectionsPlot::updateProjectionsData ( )
private

Creates cached 2D histogram for later projection calculations.

Definition at line 174 of file ProjectionsPlot.cpp.

175 {
176  m_field.reset(intensityItem()->getDatafield());
177  updateAxesRange();
178  updateAxesTitle();
179  setLogz(intensityItem()->isLogz());
180 }

References intensityItem(), m_field, setLogz(), updateAxesRange(), and updateAxesTitle().

Referenced by subscribeToItem().

Here is the call graph for this function:

Member Data Documentation

◆ m_block_plot_update

bool ProjectionsPlot::m_block_plot_update
private

◆ m_customPlot

QCustomPlot* ProjectionsPlot::m_customPlot
private

◆ m_field

std::unique_ptr<Datafield> ProjectionsPlot::m_field
private

Definition at line 73 of file ProjectionsPlot.h.

Referenced by setGraphFromItem(), and updateProjectionsData().

◆ m_item_to_graph

QMap<SessionItem*, QCPGraph*> ProjectionsPlot::m_item_to_graph
private

Definition at line 74 of file ProjectionsPlot.h.

Referenced by clearProjection(), clearProjections(), graphForItem(), and setInterpolate().

◆ m_itemController

◆ m_projectionType

QString ProjectionsPlot::m_projectionType
private

Definition at line 71 of file ProjectionsPlot.h.

Referenced by graphForItem(), isHorizontalType(), and projectionItems().


The documentation for this class was generated from the following files: