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

The PlotStatusLabel class shows status string as reported by DescriptedPlot in a frame. More...

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)
 

Private Slots

void onPlotDestroyed (QObject *obj)
 

Private Member Functions

void setConnected (ScientificPlot *plot, bool flag)
 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
 

Detailed 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.

Constructor & Destructor Documentation

◆ PlotStatusLabel()

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

Definition at line 18 of file PlotStatusLabel.cpp.

18  : StatusLabel(parent)
19 {
20  if (plot)
21  addPlot(plot);
22 }
void addPlot(ScientificPlot *plot)
StatusLabel(QWidget *parent=0)
Definition: StatusLabel.cpp:32

References addPlot().

Here is the call graph for this function:

Member Function Documentation

◆ addPlot()

void PlotStatusLabel::addPlot ( ScientificPlot plot)

Definition at line 24 of file PlotStatusLabel.cpp.

25 {
26  if (m_plots.contains(plot))
27  return;
28 
29  m_plots.push_back(plot);
30  setPlotLabelEnabled(plot, true);
31 }
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 79 of file PlotStatusLabel.cpp.

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

References m_plots.

Referenced by setConnected().

◆ onPlotStatusString

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

Definition at line 53 of file PlotStatusLabel.cpp.

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

References StatusLabel::setText().

Referenced by setConnected().

Here is the call graph for this function:

◆ paintEvent()

void StatusLabel::paintEvent ( QPaintEvent *  event)
protectedinherited

Definition at line 63 of file StatusLabel.cpp.

64 {
65  QWidget::paintEvent(event);
66 
67  QPainter painter(this);
68  painter.setBrush(QColor(Qt::black));
69  painter.setPen(QColor(Qt::black));
70  painter.setFont(m_font);
71 
72  QRect textRect(0, 0, geometry().width(), geometry().height());
73  painter.fillRect(textRect, QColor(Qt::white));
74  painter.drawText(textRect, m_alignment, m_text);
75 }
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 45 of file PlotStatusLabel.cpp.

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

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 57 of file StatusLabel.cpp.

58 {
59  m_alignment = alignment;
60  update();
61 }

References StatusLabel::m_alignment.

◆ setConnected()

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

Connects with colorMap's status string signal.

Definition at line 68 of file PlotStatusLabel.cpp.

69 {
70  if (flag) {
72  Qt::UniqueConnection);
73  connect(plot, &ScientificPlot::destroyed, this, &PlotStatusLabel::onPlotDestroyed);
74  } else {
76  }
77 }
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 45 of file StatusLabel.cpp.

46 {
47  m_font = font;
48  update();
49 }

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 35 of file PlotStatusLabel.cpp.

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

References m_plots, and setPlotLabelEnabled().

Referenced by ColorMapCanvas::setStatusLabelEnabled(), Plot1DCanvas::setStatusLabelEnabled(), and SpecularPlotCanvas::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 60 of file PlotStatusLabel.cpp.

61 {
62  plot->setMouseTrackingEnabled(flag);
63  setConnected(plot, flag);
64 }
void setConnected(ScientificPlot *plot, bool flag)
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 51 of file StatusLabel.cpp.

52 {
53  m_font.setPointSize(pointSize);
54  update();
55 }

References StatusLabel::m_font.

◆ setText()

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

Definition at line 39 of file StatusLabel.cpp.

40 {
41  m_text = text;
42  update();
43 }

References StatusLabel::m_text.

Referenced by onPlotStatusString(), ColorMapCanvas::onStatusString(), Plot1DCanvas::onStatusString(), and SpecularPlotCanvas::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: