Mantid
Loading...
Searching...
No Matches
MessageDisplay.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------
10// Includes
11//----------------------------------
12#include "DllOption.h"
16
17#include <QHash>
18#include <QTextCharFormat>
19#include <QTextCursor>
20#include <QWidget>
21
22//----------------------------------------------------------
23// Forward declarations
24//----------------------------------------------------------
25class QAction;
26class QActionGroup;
27class QMenu;
28class QPlainTextEdit;
29class QPoint;
30class QSettings;
31class QShowEvent;
32class QSignalMapper;
33
34namespace MantidQt {
35namespace MantidWidgets {
36
38public:
39 MessageDisplaySettings(int logLevel = 0, int maximumLineCount = 8192);
40
41 [[nodiscard]] int logLevel() const;
42 [[nodiscard]] int maximumLineCount() const;
43
44private:
47};
48
55class EXPORT_OPT_MANTIDQT_COMMON MessageDisplay : public QWidget, public Configurable<MessageDisplaySettings> {
56 Q_OBJECT
57 Q_PROPERTY(QString source READ source WRITE setSource)
58
59public:
61 [[nodiscard]] MessageDisplaySettings readSettings(const QSettings &storage) const;
63 void restoreSettings(const MessageDisplaySettings &settings) override;
65 [[nodiscard]] MessageDisplaySettings captureSettings() const override;
67 void saveSettings(QSettings &storage, const MessageDisplaySettings &settings) const;
68
69public:
71 MessageDisplay(QWidget *parent = nullptr);
73 MessageDisplay(const QFont &font, QWidget *parent = nullptr);
74 MessageDisplay(const MessageDisplay &) = delete;
77 ~MessageDisplay() override;
78
79 // Setup logging framework connections
80 void attachLoggingChannel(int logLevel = 0);
82 void setSource(const QString &source);
84 inline const QString &source() const { return m_logChannel->source(); }
86 QPlainTextEdit *getTextEdit() { return m_textDisplay; }
88 const QList<Message> &getHistory() { return m_messageHistory; }
90 QMenu *generateContextMenu();
92 void filterMessages();
94 void filePathModified(const QString &oldPath, const QString &newPath);
96 void appendToHistory(const Message &msg);
98 inline bool showFrameworkOutput() const { return m_showFrameworkOutput; }
100 void setShowFrameworkOutput(const bool &show) { m_showFrameworkOutput = show; }
102 inline bool showAllScriptOutput() const { return m_showAllScriptOutput; }
104 void setShowAllScriptOutput(const bool &show) { m_showAllScriptOutput = show; }
106 inline bool showActiveScriptOutput() const { return m_showActiveScriptOutput; }
108 void setShowActiveScriptOutput(const bool &show) { m_showActiveScriptOutput = show; }
110 inline const QString &activeScript() const { return m_activeScript; }
112 void setActiveScript(const QString &scriptPath) { m_activeScript = scriptPath; }
113
114signals:
116 void errorReceived(const QString &text);
118 void warningReceived(const QString &text);
119
120public slots:
122 void appendFatal(const QString &text);
124 void appendError(const QString &text);
126 void appendWarning(const QString &text);
128 void appendNotice(const QString &text);
130 void appendInformation(const QString &text);
132 void appendDebug(const QString &text);
134 void append(const Message &msg);
136 void appendPython(const QString &text, const int &priority, const QString &fileName);
138 void replace(const Message &msg);
140 void clear();
142 QTextCursor moveCursorToEnd();
144 bool isScrollbarAtBottom() const;
146 void scrollToTop();
148 void scrollToBottom();
149
150private slots:
152 void showContextMenu(const QPoint &event);
154 void setLogLevel(int priority);
156 void setScrollbackLimit();
158 int maximumLineCount() const;
160 void setMaximumLineCount(int count);
161
162private:
164 void initActions();
166 void initFormats();
168 void setupTextArea(const QFont &font);
170 QTextCharFormat format(const Message::Priority priority) const;
172 bool shouldBeDisplayed(const Message &msg);
173
177 QPlainTextEdit *m_textDisplay;
181 QActionGroup *m_loglevels;
183 QSignalMapper *m_logLevelMapping;
185 QAction *m_error, *m_warning, *m_notice, *m_information, *m_debug;
189 bool m_showFrameworkOutput{true}, m_showAllScriptOutput{true}, m_showActiveScriptOutput{false};
191};
192} // namespace MantidWidgets
193} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
int count
counter
Definition Matrix.cpp:37
Defines the in-memory half of the persistent settings lifecycle.
Provides a widget for display messages in a text box It deals with Message objects which in turn hide...
bool showFrameworkOutput() const
Get whether framework output is being displayed.
MessageDisplay(const MessageDisplay &)=delete
void errorReceived(const QString &text)
Indicate that a message of error or higher has been received.
const QString & source() const
Get the current source are emitted.
bool showAllScriptOutput() const
Get whether all script output is being displayed.
QPlainTextEdit * m_textDisplay
The actual widget holding the text.
void warningReceived(const QString &text)
Indicate that a message of warning or higher has been received.
QActionGroup * m_loglevels
Mutually exclusive log actions.
bool showActiveScriptOutput() const
Get whether only active script output is being displayed.
QPlainTextEdit * getTextEdit()
Get the window's QPlainTextEdit object.
void setShowFrameworkOutput(const bool &show)
Set whether framework output should be displayed.
QList< Message > m_messageHistory
Keep track of the message history.
const QList< Message > & getHistory()
Get the window's message history.
void setActiveScript(const QString &scriptPath)
Set the path of the currently active script.
QSignalMapper * m_logLevelMapping
Map action signal to log level parameter.
const QString & activeScript() const
Get the path of the currently active script.
QtSignalChannel * m_logChannel
A reference to the log channel.
void setShowAllScriptOutput(const bool &show)
Set whether all script output should be displayed.
QHash< Message::Priority, QTextCharFormat > m_formats
Map priority to text formatting.
void setShowActiveScriptOutput(const bool &show)
Get whether only active script output should be displayed.
MessageDisplay & operator=(const MessageDisplay &)=delete
Provides a simple binding of a text message with a priority.
Definition Message.h:28
Mantid::Kernel::Logger::Priority Priority
Priority matches Mantid Logger priority.
Definition Message.h:33
Provides a translation layer that takes a Poco::Message and converts it to a Qt signal.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...