BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::ColorMapPlotController Class Reference

Establish communication between QCPColorMap and ColorMapItem. More...

Inheritance diagram for ModelView::ColorMapPlotController:
[legend]
Collaboration diagram for ModelView::ColorMapPlotController:
[legend]

Classes

struct  ColorMapPlotControllerImpl
 

Public Member Functions

 ColorMapPlotController (QCustomPlot *plot, QCPColorScale *color_scale=nullptr)
 
 ~ColorMapPlotController () override
 
ColorMapItemcurrentItem () const
 
void setItem (SessionItem *item)
 
void setOnAboutToRemoveItem (Callbacks::item_tagrow_t f)
 
void setOnChildPropertyChange (Callbacks::item_str_t f)
 Sets callback to be notified on item's children property change. More...
 
void setOnDataChange (Callbacks::item_int_t f)
 Sets callback to be notified on item's data change. More...
 
void setOnItemDestroy (Callbacks::item_t f)
 
void setOnItemInserted (Callbacks::item_tagrow_t f)
 Sets callback to be notified on child insertion. More...
 
void setOnItemRemoved (Callbacks::item_tagrow_t f)
 Sets callback to be notified on child removal. More...
 
void setOnPropertyChange (Callbacks::item_str_t f)
 Sets callback to be notified on item's property change. More...
 

Protected Member Functions

SessionItemitem () const
 For necessary manipulations on unsubscription. More...
 
void subscribe () override
 
void unsubscribe () override
 For necessary manipulations on new item. More...
 

Private Member Functions

void unsubscribe_from_current ()
 

Private Attributes

SessionItemm_item {nullptr}
 
std::unique_ptr< ColorMapPlotControllerImplp_impl
 

Detailed Description

Establish communication between QCPColorMap and ColorMapItem.

Provide update on QCPColorMap when ColorMapItem is changed. QCPColorMap is added to QCustomPlot plottables, when controller is created, and removed from plottables, when controller is destroyed.

Definition at line 34 of file colormapplotcontroller.h.

Constructor & Destructor Documentation

◆ ColorMapPlotController()

ColorMapPlotController::ColorMapPlotController ( QCustomPlot *  plot,
QCPColorScale *  color_scale = nullptr 
)
explicit

Definition at line 102 of file colormapplotcontroller.cpp.

103  : p_impl(std::make_unique<ColorMapPlotControllerImpl>(this, custom_plot, color_scale))
104 {
105 }
std::unique_ptr< ColorMapPlotControllerImpl > p_impl

◆ ~ColorMapPlotController()

ColorMapPlotController::~ColorMapPlotController ( )
overridedefault

Member Function Documentation

◆ currentItem()

ColorMapItem * ModelView::ItemListener< ColorMapItem >::currentItem ( ) const
inlineinherited

Definition at line 28 of file itemlistener.h.

28 { return static_cast<T*>(item()); }
SessionItem * item() const
For necessary manipulations on unsubscription.

◆ item()

◆ setItem()

void ModelView::ItemListenerBase::setItem ( ModelView::SessionItem item)
inherited

Definition at line 30 of file itemlistenerbase.cpp.

31 {
32  if (m_item == item)
33  return;
34 
36 
37  m_item = item;
38 
39  if (!m_item)
40  return;
41 
42  auto on_item_destroy = [this](auto) {
43  m_item = nullptr;
44  unsubscribe();
45  };
46  m_item->mapper()->setOnItemDestroy(on_item_destroy, this);
47 
48  subscribe();
49 }
virtual void unsubscribe()
For necessary manipulations on new item.
void setOnItemDestroy(Callbacks::item_t f, Callbacks::slot_t owner) override
Definition: itemmapper.cpp:179
ItemMapper * mapper()
Returns item mapper. Allows subscribing to various events happening to the item.

Referenced by ModelView::ItemListenerBase::ItemListenerBase(), and TEST_F().

◆ setOnAboutToRemoveItem()

void ModelView::ItemListenerBase::setOnAboutToRemoveItem ( Callbacks::item_tagrow_t  f)
inherited

Definition at line 102 of file itemlistenerbase.cpp.

103 {
104  item()->mapper()->setOnAboutToRemoveItem(f, this);
105 }
void setOnAboutToRemoveItem(Callbacks::item_tagrow_t f, Callbacks::slot_t owner) override
Sets callback to be notified when row is about to be removed.
Definition: itemmapper.cpp:209

Referenced by ModelView::GraphViewportPlotController::subscribe().

◆ setOnChildPropertyChange()

void ModelView::ItemListenerBase::setOnChildPropertyChange ( Callbacks::item_str_t  f)
inherited

Sets callback to be notified on item's children property change.

Callback will be called with (compound_item, property_name). For MultiLayer containing the layer with "thickness" property, the signal will be triggered on thickness change using (layeritem*, "thickness") as callback parameters.

Definition at line 77 of file itemlistenerbase.cpp.

78 {
79  item()->mapper()->setOnChildPropertyChange(f, this);
80 }
void setOnChildPropertyChange(Callbacks::item_str_t f, Callbacks::slot_t owner) override
Sets callback to be notified on item's children property change.
Definition: itemmapper.cpp:194

◆ setOnDataChange()

void ModelView::ItemListenerBase::setOnDataChange ( Callbacks::item_int_t  f)
inherited

Sets callback to be notified on item's data change.

Callback will be called with (SessionItem*, data_role).

Definition at line 59 of file itemlistenerbase.cpp.

60 {
61  item()->mapper()->setOnDataChange(f, this);
62 }
void setOnDataChange(Callbacks::item_int_t f, Callbacks::slot_t owner) override
Sets callback to be notified on item's data change.
Definition: itemmapper.cpp:184

Referenced by ModelView::Data2DPlotController::subscribe().

◆ setOnItemDestroy()

void ModelView::ItemListenerBase::setOnItemDestroy ( Callbacks::item_t  f)
inherited

Definition at line 51 of file itemlistenerbase.cpp.

52 {
53  item()->mapper()->setOnItemDestroy(f, this);
54 }

◆ setOnItemInserted()

void ModelView::ItemListenerBase::setOnItemInserted ( Callbacks::item_tagrow_t  f)
inherited

Sets callback to be notified on child insertion.

Callback will be called with (compound_item, tag, row). For MultiLayer containing the T_LAYERS tag, the signal will be triggered on layer insertion with (multilayer*, {T_LAYER, row}) as callback parameters.

Definition at line 87 of file itemlistenerbase.cpp.

88 {
89  item()->mapper()->setOnItemInserted(f, this);
90 }
void setOnItemInserted(Callbacks::item_tagrow_t f, Callbacks::slot_t owner) override
Sets callback to be notified on child insertion.
Definition: itemmapper.cpp:199

Referenced by ModelView::ColorMapViewportPlotController::subscribe(), and ModelView::GraphViewportPlotController::subscribe().

◆ setOnItemRemoved()

void ModelView::ItemListenerBase::setOnItemRemoved ( Callbacks::item_tagrow_t  f)
inherited

Sets callback to be notified on child removal.

Callback will be called with (compound_item, tag, row). For MultiLayer containing the T_LAYERS tag, the signal will be triggered on layer removal with (multilayer*, {T_LAYER, oldrow}) as callback parameters.

Definition at line 97 of file itemlistenerbase.cpp.

98 {
99  item()->mapper()->setOnItemRemoved(f, this);
100 }
void setOnItemRemoved(Callbacks::item_tagrow_t f, Callbacks::slot_t owner) override
Sets callback to be notified on child removal.
Definition: itemmapper.cpp:204

◆ setOnPropertyChange()

void ModelView::ItemListenerBase::setOnPropertyChange ( Callbacks::item_str_t  f)
inherited

Sets callback to be notified on item's property change.

Callback will be called with (compound_item, property_name).

Definition at line 67 of file itemlistenerbase.cpp.

68 {
69  item()->mapper()->setOnPropertyChange(f, this);
70 }
void setOnPropertyChange(Callbacks::item_str_t f, Callbacks::slot_t owner) override
Sets callback to be notified on item's property change.
Definition: itemmapper.cpp:189

Referenced by ModelView::AxisTitleController::subscribe(), subscribe(), ModelView::ColorScalePlotController::subscribe(), ModelView::Data1DPlotController::subscribe(), ModelView::GraphPlotController::subscribe(), ModelView::PenController::subscribe(), and ModelView::ViewportAxisPlotController::subscribe().

◆ subscribe()

void ColorMapPlotController::subscribe ( )
overrideprotectedvirtual

Reimplemented from ModelView::ItemListenerBase.

Definition at line 107 of file colormapplotcontroller.cpp.

108 {
109  auto on_property_change = [this](SessionItem*, std::string property_name) {
110  if (property_name == ColorMapItem::P_INTERPOLATION)
111  p_impl->update_interpolation();
112 
113  if (property_name == ColorMapItem::P_GRADIENT)
114  p_impl->update_gradient();
115 
116  if (property_name == ColorMapItem::P_LINK)
117  p_impl->update_data_controller();
118 
119  p_impl->custom_plot->replot();
120  };
121  setOnPropertyChange(on_property_change);
122 
123  p_impl->update_colormap();
124 }
static const std::string P_INTERPOLATION
Definition: colormapitem.h:33
static const std::string P_LINK
Definition: colormapitem.h:30
static const std::string P_GRADIENT
Definition: colormapitem.h:32
void setOnPropertyChange(Callbacks::item_str_t f)
Sets callback to be notified on item's property change.
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38

References ModelView::ColorMapItem::P_GRADIENT, p_impl, ModelView::ColorMapItem::P_INTERPOLATION, ModelView::ColorMapItem::P_LINK, and ModelView::ItemListenerBase::setOnPropertyChange().

Here is the call graph for this function:

◆ unsubscribe()

void ColorMapPlotController::unsubscribe ( )
overrideprotectedvirtual

For necessary manipulations on new item.

Reimplemented from ModelView::ItemListenerBase.

Definition at line 126 of file colormapplotcontroller.cpp.

127 {
128  p_impl->data_controller->setItem(nullptr);
129 }

References p_impl.

◆ unsubscribe_from_current()

void ModelView::ItemListenerBase::unsubscribe_from_current ( )
privateinherited

Definition at line 117 of file itemlistenerbase.cpp.

118 {
119  if (!m_item)
120  return;
121 
122  unsubscribe();
123 
124  m_item->mapper()->unsubscribe(this);
125 }
void unsubscribe(Callbacks::slot_t client) override
Removes given client from all subscriptions.
Definition: itemmapper.cpp:214

Member Data Documentation

◆ m_item

SessionItem* ModelView::ItemListenerBase::m_item {nullptr}
privateinherited

Definition at line 56 of file itemlistenerbase.h.

◆ p_impl

std::unique_ptr<ColorMapPlotControllerImpl> ModelView::ColorMapPlotController::p_impl
private

Definition at line 45 of file colormapplotcontroller.h.

Referenced by subscribe(), and unsubscribe().


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