BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobMessagePanel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Fit/JobMessagePanel.cpp
6 //! @brief Implements class JobMessagePanel
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <QScrollBar>
17 #include <QTextEdit>
18 
19 namespace {
20 
21 //! text color for the given log level
22 QColor color(FitLogLevel level)
23 {
24  switch (level) {
26  return Qt::black;
28  return Qt::darkBlue;
30  return Qt::darkGreen;
32  return Qt::darkYellow;
33  case FitLogLevel::Error:
34  return Qt::darkRed;
35  default:
36  return Qt::red;
37  }
38 }
39 
40 } // namespace
41 
42 
44  : QTextEdit(parent)
45  , m_log(nullptr)
46 {
47  setWindowTitle("Message Panel");
48  setReadOnly(true);
49  setFont(QFont("Courier"));
50 }
51 
53 {
54  QScrollBar* scrollbar = verticalScrollBar();
55  bool autoscroll = scrollbar->value() == scrollbar->maximum();
56  setTextColor(color(message.level));
57  append(QString::fromStdString(message.text));
58  if (autoscroll) {
59  QTextCursor c = textCursor();
60  c.movePosition(QTextCursor::End);
61  setTextCursor(c);
62  }
63 }
64 
66 {
67  if (m_log)
68  m_log->disconnect(this);
69  m_log = log;
70  clear();
71  if (m_log) {
72  for (const auto& record : m_log->messages())
73  appendMessage(record);
74  connect(m_log, &FitLog::cleared, this, &JobMessagePanel::clear);
76  }
77 }
FitLogLevel
enum class describing the log level of a message
Definition: FitLog.h:24
Defines class JobMessagePanel.
the collected messages of a fitting session
Definition: FitLog.h:27
const std::vector< Message > & messages() const
Definition: FitLog.cpp:35
void cleared()
void messageAppended(const Message &message)
JobMessagePanel(QWidget *parent=nullptr)
void appendMessage(const FitLog::Message &message)
void setLog(FitLog *log)
std::string text
Definition: FitLog.h:31
FitLogLevel level
Definition: FitLog.h:32