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

Description

The IntensityDataCanvas class represents IntensityDataItem as color map, provides standard actions (reset view, save as) for external toolbars and context menus.

Definition at line 30 of file IntensityDataCanvas.h.

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

Public Slots

void onMousePress (QMouseEvent *event)
 
void onResetViewAction ()
 
void onSavePlotAction ()
 

Public Member Functions

 IntensityDataCanvas (QWidget *parent=nullptr)
 
QList< QAction * > actionList () override
 
SessionItemcurrentItem ()
 
const SessionItemcurrentItem () const
 
QSize minimumSizeHint () const override
 
void setItem (SessionItem *intensityItem) override
 
QSize sizeHint () const override
 

Protected Member Functions

void hideEvent (QHideEvent *) override
 
void rotateData ()
 
void showEvent (QShowEvent *) override
 
void subscribeToItem () override
 
virtual void unsubscribeFromItem ()
 

Private Member Functions

void applyPersistentSettings ()
 Apply persistent settings (gradient, interpolation) to IntensityDataItem. More...
 
void initActions ()
 
void initRotation ()
 
IntensityDataItemintensityDataItem ()
 
void onPropertyChanged (const QString &name)
 Reads gradient/ interpolation settings from IntensityDataItem and writes to persistant project settings. More...
 

Private Attributes

ColorMapCanvasm_colorMap
 
SessionItemControllerm_itemController
 
QAction * m_resetViewAction
 
QAction * m_rotateDataAction
 
QAction * m_savePlotAction
 

Constructor & Destructor Documentation

◆ IntensityDataCanvas()

IntensityDataCanvas::IntensityDataCanvas ( QWidget *  parent = nullptr)
explicit

Definition at line 41 of file IntensityDataCanvas.cpp.

42  : SessionItemWidget(parent)
44  , m_resetViewAction(nullptr)
45  , m_rotateDataAction(nullptr)
46  , m_savePlotAction(nullptr)
47 {
48  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
49 
50  auto* layout = new QVBoxLayout;
51  layout->setMargin(0);
52  layout->setSpacing(0);
53  layout->addWidget(m_colorMap);
54  setLayout(layout);
55 
57 
58  initActions();
59 
60  connect(m_colorMap->customPlot(), &QCustomPlot::mousePress, this,
61  &IntensityDataCanvas::onMousePress, Qt::UniqueConnection);
62 }
The ColorMapCanvas class contains ColorMap for intensity data presentation, and provide control of fo...
void setStatusLabelEnabled(bool flag)
QCustomPlot * customPlot()
void onMousePress(QMouseEvent *event)
ColorMapCanvas * m_colorMap
SessionItemWidget(QWidget *parent=nullptr)

References ColorMapCanvas::customPlot(), initActions(), m_colorMap, onMousePress(), and ColorMapCanvas::setStatusLabelEnabled().

Here is the call graph for this function:

Member Function Documentation

◆ actionList()

QList< QAction * > IntensityDataCanvas::actionList ( )
overridevirtual

Reimplemented from SessionItemWidget.

Definition at line 84 of file IntensityDataCanvas.cpp.

85 {
88  else
90 }

References m_resetViewAction, m_rotateDataAction, and m_savePlotAction.

Referenced by IntensityDataWidget::actionList().

◆ applyPersistentSettings()

void IntensityDataCanvas::applyPersistentSettings ( )
private

Apply persistent settings (gradient, interpolation) to IntensityDataItem.

Definition at line 189 of file IntensityDataCanvas.cpp.

190 {
191  QSettings settings;
192 
193  if (settings.contains(SettingsKeyGradient)) {
195  QString persistentGradient = settings.value(SettingsKeyGradient).toString();
196  if (combo.getValue() != persistentGradient) {
197  combo.setValue(persistentGradient);
198  intensityDataItem()->setGradient(combo);
199  }
200  }
201 
202  if (settings.contains(SettingsKeyInterpolation)) {
203  bool value = settings.value(SettingsKeyInterpolation).toBool();
205  }
206 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
void setValue(const QString &name)
QString getValue() const
IntensityDataItem * intensityDataItem()
void setGradient(const ComboProperty &gradient)
void setInterpolated(bool interp)
ComboProperty getGradient() const

References IntensityDataItem::getGradient(), ComboProperty::getValue(), intensityDataItem(), IntensityDataItem::setGradient(), IntensityDataItem::setInterpolated(), and ComboProperty::setValue().

Referenced by setItem().

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:

◆ 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:

◆ initActions()

void IntensityDataCanvas::initActions ( )
private

Definition at line 145 of file IntensityDataCanvas.cpp.

146 {
147  m_resetViewAction = new QAction(this);
148  m_resetViewAction->setText("Center view");
149  m_resetViewAction->setIcon(QIcon(":/images/camera-metering-center.svg"));
150  m_resetViewAction->setToolTip("Reset view\n"
151  "x,y,z axes range will be set to default");
152  connect(m_resetViewAction, &QAction::triggered, this, &IntensityDataCanvas::onResetViewAction);
153 
154  m_savePlotAction = new QAction(this);
155  m_savePlotAction->setText("Save");
156  m_savePlotAction->setIcon(QIcon(":/images/content-save-outline.svg"));
157  m_savePlotAction->setToolTip("Save plot");
158  connect(m_savePlotAction, &QAction::triggered, this, &IntensityDataCanvas::onSavePlotAction);
159 }

References m_resetViewAction, m_savePlotAction, onResetViewAction(), and onSavePlotAction().

Referenced by IntensityDataCanvas().

Here is the call graph for this function:

◆ initRotation()

void IntensityDataCanvas::initRotation ( )
private

Definition at line 161 of file IntensityDataCanvas.cpp.

162 {
163  if (dynamic_cast<RealDataItem*>(intensityDataItem()->parentItem())) {
164  m_rotateDataAction = new QAction(this);
165  m_rotateDataAction->setText("Rotate");
166  m_rotateDataAction->setIcon(QIcon(":/images/rotate-left.svg"));
167  m_rotateDataAction->setIconText("Rotate");
168  m_rotateDataAction->setToolTip("Rotate intensity data by 90 deg counterclockwise");
169  connect(m_rotateDataAction, &QAction::triggered, this, &IntensityDataCanvas::rotateData);
170  }
171 }
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33

References intensityDataItem(), m_rotateDataAction, and rotateData().

Referenced by setItem().

Here is the call graph for this function:

◆ intensityDataItem()

IntensityDataItem * IntensityDataCanvas::intensityDataItem ( )
private

Definition at line 138 of file IntensityDataCanvas.cpp.

139 {
140  auto* result = dynamic_cast<IntensityDataItem*>(currentItem());
141  ASSERT(result);
142  return result;
143 }

References SessionItemWidget::currentItem().

Referenced by applyPersistentSettings(), initRotation(), onPropertyChanged(), onResetViewAction(), onSavePlotAction(), rotateData(), setItem(), and subscribeToItem().

Here is the call graph for this function:

◆ minimumSizeHint()

QSize IntensityDataCanvas::minimumSizeHint ( ) const
override

Definition at line 79 of file IntensityDataCanvas.cpp.

80 {
81  return QSize(128, 128);
82 }

◆ onMousePress

void IntensityDataCanvas::onMousePress ( QMouseEvent *  event)
slot

Definition at line 103 of file IntensityDataCanvas.cpp.

104 {
105  if (event->button() == Qt::RightButton)
106  emit customContextMenuRequested(event->globalPos());
107 }

Referenced by IntensityDataCanvas().

◆ onPropertyChanged()

void IntensityDataCanvas::onPropertyChanged ( const QString &  name)
private

Reads gradient/ interpolation settings from IntensityDataItem and writes to persistant project settings.

Definition at line 176 of file IntensityDataCanvas.cpp.

177 {
179  QSettings settings;
180  settings.setValue(SettingsKeyGradient, intensityDataItem()->getGradientValue());
182  QSettings settings;
183  settings.setValue(SettingsKeyInterpolation, intensityDataItem()->isInterpolated());
184  }
185 }
static bool isInterpolatedPropertyName(const QString &name)
static bool isGradientPropertyName(const QString &name)
QString const & name(EShape k)
Definition: particles.cpp:20

References intensityDataItem(), IntensityDataItem::isGradientPropertyName(), IntensityDataItem::isInterpolatedPropertyName(), and GUI::RealSpace::Particles::name().

Referenced by subscribeToItem().

Here is the call graph for this function:

◆ onResetViewAction

void IntensityDataCanvas::onResetViewAction ( )
slot

Definition at line 92 of file IntensityDataCanvas.cpp.

93 {
95 }
void resetView()
Set axes viewport to original data.

References intensityDataItem(), and IntensityDataItem::resetView().

Referenced by initActions().

Here is the call graph for this function:

◆ onSavePlotAction

void IntensityDataCanvas::onSavePlotAction ( )
slot

Definition at line 97 of file IntensityDataCanvas.cpp.

98 {
99  QString dirname = gSessionData->projectDocument.value()->userExportDir();
100  GUI::Plot::savePlot(dirname, m_colorMap->customPlot(), intensityDataItem()->getDatafield());
101 }
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
void savePlot(const QString &dirname, QCustomPlot *plot, Datafield *output_data)
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27

References ColorMapCanvas::customPlot(), gSessionData, intensityDataItem(), m_colorMap, SessionData::projectDocument, and GUI::Plot::savePlot().

Referenced by initActions().

Here is the call graph for this function:

◆ rotateData()

void IntensityDataCanvas::rotateData ( )
protected

Definition at line 115 of file IntensityDataCanvas.cpp.

116 {
117  auto* realDataItem = dynamic_cast<RealDataItem*>(intensityDataItem()->parentItem());
118  if (!realDataItem || !realDataItem->isIntensityData())
119  // should never happen because of action disabling => no
120  // dialog necessary
121  return;
122 
123  if (realDataItem->rotationAffectsSetup()) {
124  const QString title("Rotate data");
125  const QString message("Rotation will break the link between the data and the instrument. "
126  "Detector masks or projections, if they exist, will be removed.");
128  "Do you wish to rotate the data?", "Yes, please rotate",
129  "No, cancel data rotation"))
130  return;
131  }
132 
133  QApplication::setOverrideCursor(Qt::WaitCursor);
134  realDataItem->rotateData();
135  QApplication::restoreOverrideCursor();
136 }
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67
static QMainWindow * mainWindow
Definition: Globals.h:22
bool question(QWidget *parent, const QString &title, const QString &text, const QString &detailedText, const QString &yesText, const QString &noText)
Definition: MessageBox.cpp:52

References intensityDataItem(), GUI::Global::mainWindow, SessionItem::parentItem(), and GUI::View::Helpers::question().

Referenced by initRotation().

Here is the call graph for this function:

◆ setItem()

void IntensityDataCanvas::setItem ( SessionItem intensityItem)
overridevirtual

Reimplemented from SessionItemWidget.

Definition at line 64 of file IntensityDataCanvas.cpp.

65 {
66  SessionItemWidget::setItem(intensityItem);
68 
70  if (!m_rotateDataAction)
71  initRotation();
72 }
void setItem(SessionItem *intensityDataItem) override
void applyPersistentSettings()
Apply persistent settings (gradient, interpolation) to IntensityDataItem.
virtual void setItem(SessionItem *item)

References applyPersistentSettings(), initRotation(), intensityDataItem(), m_colorMap, m_rotateDataAction, ColorMapCanvas::setItem(), and SessionItemWidget::setItem().

Referenced by IntensityDataWidget::onFFTAction(), and IntensityDataWidget::setItem().

Here is the call graph for this function:

◆ showEvent()

void SessionItemWidget::showEvent ( QShowEvent *  )
overrideprotectedinherited

Definition at line 51 of file SessionItemWidget.cpp.

52 {
54 }
void subscribe()
Subscribe parent to item's signals.

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

Here is the call graph for this function:

◆ sizeHint()

QSize IntensityDataCanvas::sizeHint ( ) const
override

Definition at line 74 of file IntensityDataCanvas.cpp.

75 {
76  return QSize(500, 400);
77 }

◆ subscribeToItem()

void IntensityDataCanvas::subscribeToItem ( )
overrideprotectedvirtual

Reimplemented from SessionItemWidget.

Definition at line 109 of file IntensityDataCanvas.cpp.

110 {
112  [this](const QString& name) { onPropertyChanged(name); }, this);
113 }
void onPropertyChanged(const QString &name)
Reads gradient/ interpolation settings from IntensityDataItem and writes to persistant project settin...
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References intensityDataItem(), SessionItem::mapper(), GUI::RealSpace::Particles::name(), onPropertyChanged(), and ModelMapper::setOnPropertyChange().

Here is the call graph for this function:

◆ unsubscribeFromItem()

virtual void SessionItemWidget::unsubscribeFromItem ( )
inlineprotectedvirtualinherited

Member Data Documentation

◆ m_colorMap

ColorMapCanvas* IntensityDataCanvas::m_colorMap
private

Definition at line 58 of file IntensityDataCanvas.h.

Referenced by IntensityDataCanvas(), onSavePlotAction(), and setItem().

◆ m_itemController

◆ m_resetViewAction

QAction* IntensityDataCanvas::m_resetViewAction
private

Definition at line 59 of file IntensityDataCanvas.h.

Referenced by actionList(), and initActions().

◆ m_rotateDataAction

QAction* IntensityDataCanvas::m_rotateDataAction
private

Definition at line 60 of file IntensityDataCanvas.h.

Referenced by actionList(), initRotation(), and setItem().

◆ m_savePlotAction

QAction* IntensityDataCanvas::m_savePlotAction
private

Definition at line 61 of file IntensityDataCanvas.h.

Referenced by actionList(), and initActions().


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