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

Description

The PlotStatusLabel class shows status string as reported by DescriptedPlot in a frame. Can work with more than one DescriptedPlot. Provides automatic adjustment of font size, depending on available space in parent layout. Also doesn't trigger layout resize, being happy with place it has.

Definition at line 29 of file PlotStatusLabel.h.

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

Public Slots

void onPlotStatusString (const QString &text)
 

Public Member Functions

 PlotStatusLabel (ScientificPlot *plot, QWidget *parent=nullptr)
 
void addPlot (ScientificPlot *plot)
 
void reset ()
 Disconnects all color maps from the label. More...
 
void setAlignment (Qt::Alignment)
 
void setFont (const QFont &font)
 
void setLabelEnabled (bool flag)
 Enables/disables label. If disabled, all colorMaps are disconnected and label is hiding. More...
 
void setPointSize (int pointSize)
 
void setText (const QString &text)
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 

Private Slots

void onPlotDestroyed (QObject *obj)
 

Private Member Functions

void setConnected (ScientificPlot *plot, bool flag) const
 Connects with colorMap's status string signal. More...
 
void setPlotLabelEnabled (ScientificPlot *plot, bool flag)
 Enables/disables showing of label for given plot. More...
 

Private Attributes

Qt::Alignment m_alignment
 
QFont m_font
 
QList< ScientificPlot * > m_plots
 
QString m_text
 

Constructor & Destructor Documentation

◆ PlotStatusLabel()

PlotStatusLabel::PlotStatusLabel ( ScientificPlot plot,
QWidget *  parent = nullptr 
)

Definition at line 18 of file PlotStatusLabel.cpp.

19  : StatusLabel(parent)
20 {
21  if (plot)
22  addPlot(plot);
23 }
void addPlot(ScientificPlot *plot)
StatusLabel(QWidget *parent=nullptr)
Definition: StatusLabel.cpp:34

References addPlot().

Here is the call graph for this function:

Member Function Documentation

◆ addPlot()

void PlotStatusLabel::addPlot ( ScientificPlot plot)

Definition at line 25 of file PlotStatusLabel.cpp.

26 {
27  if (m_plots.contains(plot))
28  return;
29 
30  m_plots.push_back(plot);
31  setPlotLabelEnabled(plot, true);
32 }
QList< ScientificPlot * > m_plots
void setPlotLabelEnabled(ScientificPlot *plot, bool flag)
Enables/disables showing of label for given plot.

References m_plots, and setPlotLabelEnabled().

Referenced by PlotStatusLabel(), ProjectionsEditorCanvas::setColorMap(), MaskEditorCanvas::setMaskContext(), FitComparisonWidget::subscribeToItem(), and FitComparisonWidget1D::subscribeToItem().

Here is the call graph for this function:

◆ onPlotDestroyed

void PlotStatusLabel::onPlotDestroyed ( QObject *  obj)
privateslot

Definition at line 80 of file PlotStatusLabel.cpp.

81 {
82  auto it = std::remove_if(m_plots.begin(), m_plots.end(),
83  [obj](ScientificPlot* cm) { return cm == obj; });
84  m_plots.erase(it, m_plots.end());
85 }
Common interface for plot-descriptor interaction.

References m_plots.

Referenced by setConnected().

◆ onPlotStatusString

void PlotStatusLabel::onPlotStatusString ( const QString &  text)
slot

Definition at line 54 of file PlotStatusLabel.cpp.

55 {
56  setText(text);
57 }
void setText(const QString &text)
Definition: StatusLabel.cpp:42

References StatusLabel::setText().

Referenced by setConnected().

Here is the call graph for this function:

◆ paintEvent()

void StatusLabel::paintEvent ( QPaintEvent *  event)
overrideprotectedinherited

Definition at line 66 of file StatusLabel.cpp.

67 {
68  QWidget::paintEvent(event);
69 
70  QPainter painter(this);
71  painter.setBrush(QColor(Qt::black));
72  painter.setPen(QColor(Qt::black));
73  painter.setFont(m_font);
74 
75  QRect textRect(0, 0, geometry().width(), geometry().height());
76  painter.fillRect(textRect, QColor(Qt::white));
77  painter.drawText(textRect, m_alignment, m_text);
78 }
QString m_text
Definition: StatusLabel.h:43
QFont m_font
Definition: StatusLabel.h:45
Qt::Alignment m_alignment
Definition: StatusLabel.h:44

References StatusLabel::m_alignment, StatusLabel::m_font, and StatusLabel::m_text.

◆ reset()

void PlotStatusLabel::reset ( )

Disconnects all color maps from the label.

Definition at line 46 of file PlotStatusLabel.cpp.

47 {
48  for (auto* colorMap : m_plots)
49  setPlotLabelEnabled(colorMap, false);
50 
51  m_plots.clear();
52 }

References m_plots, and setPlotLabelEnabled().

Referenced by MaskEditorCanvas::resetContext(), ProjectionsEditorCanvas::setColorMap(), FitComparisonWidget::subscribeToItem(), and FitComparisonWidget1D::subscribeToItem().

Here is the call graph for this function:

◆ setAlignment()

void StatusLabel::setAlignment ( Qt::Alignment  alignment)
inherited

Definition at line 60 of file StatusLabel.cpp.

61 {
62  m_alignment = alignment;
63  update();
64 }

References StatusLabel::m_alignment.

◆ setConnected()

void PlotStatusLabel::setConnected ( ScientificPlot plot,
bool  flag 
) const
private

Connects with colorMap's status string signal.

Definition at line 69 of file PlotStatusLabel.cpp.

70 {
71  if (flag) {
73  Qt::UniqueConnection);
74  connect(plot, &ScientificPlot::destroyed, this, &PlotStatusLabel::onPlotDestroyed);
75  } else {
77  }
78 }
void onPlotDestroyed(QObject *obj)
void onPlotStatusString(const QString &text)
void statusString(const QString &text)

References onPlotDestroyed(), onPlotStatusString(), and ScientificPlot::statusString().

Referenced by setPlotLabelEnabled().

Here is the call graph for this function:

◆ setFont()

void StatusLabel::setFont ( const QFont &  font)
inherited

Definition at line 48 of file StatusLabel.cpp.

49 {
50  m_font = font;
51  update();
52 }

References StatusLabel::m_font.

◆ setLabelEnabled()

void PlotStatusLabel::setLabelEnabled ( bool  flag)

Enables/disables label. If disabled, all colorMaps are disconnected and label is hiding.

Definition at line 36 of file PlotStatusLabel.cpp.

37 {
38  for (auto* colorMap : m_plots)
39  setPlotLabelEnabled(colorMap, flag);
40 
41  setEnabled(flag);
42 }

References m_plots, and setPlotLabelEnabled().

Referenced by Plot1DCanvas::setStatusLabelEnabled(), SpecularPlotCanvas::setStatusLabelEnabled(), and ColorMapCanvas::setStatusLabelEnabled().

Here is the call graph for this function:

◆ setPlotLabelEnabled()

void PlotStatusLabel::setPlotLabelEnabled ( ScientificPlot plot,
bool  flag 
)
private

Enables/disables showing of label for given plot.

Definition at line 61 of file PlotStatusLabel.cpp.

62 {
63  plot->setMouseTrackingEnabled(flag);
64  setConnected(plot, flag);
65 }
void setConnected(ScientificPlot *plot, bool flag) const
Connects with colorMap's status string signal.
void setMouseTrackingEnabled(bool enable)
Tracks move events (used when showing profile histograms and printing status string)

References setConnected(), and ScientificPlot::setMouseTrackingEnabled().

Referenced by addPlot(), reset(), and setLabelEnabled().

Here is the call graph for this function:

◆ setPointSize()

void StatusLabel::setPointSize ( int  pointSize)
inherited

Definition at line 54 of file StatusLabel.cpp.

55 {
56  m_font.setPointSize(pointSize);
57  update();
58 }

References StatusLabel::m_font.

◆ setText()

void StatusLabel::setText ( const QString &  text)
inherited

Definition at line 42 of file StatusLabel.cpp.

43 {
44  m_text = text;
45  update();
46 }

References StatusLabel::m_text.

Referenced by onPlotStatusString(), Plot1DCanvas::onStatusString(), SpecularPlotCanvas::onStatusString(), and ColorMapCanvas::onStatusString().

Member Data Documentation

◆ m_alignment

Qt::Alignment StatusLabel::m_alignment
privateinherited

Definition at line 44 of file StatusLabel.h.

Referenced by StatusLabel::paintEvent(), and StatusLabel::setAlignment().

◆ m_font

QFont StatusLabel::m_font
privateinherited

◆ m_plots

QList<ScientificPlot*> PlotStatusLabel::m_plots
private

Definition at line 50 of file PlotStatusLabel.h.

Referenced by addPlot(), onPlotDestroyed(), reset(), and setLabelEnabled().

◆ m_text

QString StatusLabel::m_text
privateinherited

Definition at line 43 of file StatusLabel.h.

Referenced by StatusLabel::paintEvent(), and StatusLabel::setText().


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