Mantid
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | Properties | Private Slots | Private Member Functions | Private Attributes | List of all members
MantidQt::MantidWidgets::MessageDisplay Class Reference

Provides a widget for display messages in a text box It deals with Message objects which in turn hide whether a message is a framework Poco message or a simple string. More...

#include <MessageDisplay.h>

Inheritance diagram for MantidQt::MantidWidgets::MessageDisplay:
MantidQt::MantidWidgets::Configurable

Public Slots

void append (const Message &msg)
 Write a message after the current contents. More...
 
void appendDebug (const QString &text)
 Convenience method for appending message at debug level. More...
 
void appendError (const QString &text)
 Convenience method for appending message at error level. More...
 
void appendFatal (const QString &text)
 Convenience method for appending message at fatal level. More...
 
void appendInformation (const QString &text)
 Convenience method for appending message at information level. More...
 
void appendNotice (const QString &text)
 Convenience method for appending message at notice level. More...
 
void appendPython (const QString &text, const int &priority, const QString &fileName)
 Write a Python script message, intended for use with Python API. More...
 
void appendWarning (const QString &text)
 Convenience method for appending message at warning level. More...
 
void clear ()
 Clear all of the text. More...
 
bool isScrollbarAtBottom () const
 Returns true if scroll-bar is at the bottom of widget. More...
 
QTextCursor moveCursorToEnd ()
 Move the text cursor to after the last character. More...
 
void replace (const Message &msg)
 Replace the display text with the given contents. More...
 
void scrollToBottom ()
 Scroll to the bottom of the text. More...
 
void scrollToTop ()
 Scroll to the bottom of the text. More...
 

Signals

void errorReceived (const QString &text)
 Indicate that a message of error or higher has been received. More...
 
void warningReceived (const QString &text)
 Indicate that a message of warning or higher has been received. More...
 

Public Member Functions

QString activeScript () const
 Get the path of the currently active script. More...
 
void appendToHistory (const Message &msg)
 Append a message to the message history. More...
 
void attachLoggingChannel (int logLevel=0)
 Attaches the Mantid logging framework. More...
 
void filePathModified (const QString &oldPath, const QString &newPath)
 Method to be called when a file's path is modified. More...
 
void filterMessages ()
 Filter messages by message type. More...
 
QMenu * generateContextMenu ()
 Generate the display's context menu QMenu object. More...
 
QList< MessagegetHistory ()
 Get the window's message history. More...
 
QPlainTextEdit * getTextEdit ()
 Get the window's QPlainTextEdit object. More...
 
 MessageDisplay (const MessageDisplay &)=delete
 
 MessageDisplay (const QFont &font, QWidget *parent=nullptr)
 Constructor accepting a QFont. More...
 
 MessageDisplay (QWidget *parent=nullptr)
 Default constructor with optional parent. More...
 
MessageDisplayoperator= (const MessageDisplay &)=delete
 
void readSettings (const QSettings &storage) override
 Load settings from the persistent store. More...
 
void setActiveScript (const QString &scriptPath)
 Set the path of the currently active script. More...
 
void setShowActiveScriptOutput (const bool &show)
 Get whether only active script output should be displayed. More...
 
void setShowAllScriptOutput (const bool &show)
 Set whether all script output should be displayed. More...
 
void setShowFrameworkOutput (const bool &show)
 Set whether framework output should be displayed. More...
 
void setSource (const QString &source)
 If set, only Mantid log messages from this source are emitted. More...
 
bool showActiveScriptOutput () const
 Get whether only active script output is being displayed. More...
 
bool showAllScriptOutput () const
 Get whether all script output is being displayed. More...
 
bool showFrameworkOutput () const
 Get whether framework output is being displayed. More...
 
const QString & source () const
 Get the current source are emitted. More...
 
void writeSettings (QSettings &storage) const override
 Load settings from the persistent store. More...
 
 ~MessageDisplay () override
 Destructor. More...
 
- Public Member Functions inherited from MantidQt::MantidWidgets::Configurable
virtual void readSettings (const QSettings &)=0
 
virtual void writeSettings (QSettings &) const =0
 
virtual ~Configurable ()=default
 

Properties

QString source
 

Private Slots

int maximumLineCount () const
 Return the maximum number of lines displayed. More...
 
void setLogLevel (int priority)
 Set the global logging level. More...
 
void setMaximumLineCount (int count)
 Set the maximum number of lines displayed. More...
 
void setScrollbackLimit ()
 Set the number of blocks kept by the display. More...
 
void showContextMenu (const QPoint &event)
 Provide a custom context menu. More...
 

Private Member Functions

QTextCharFormat format (const Message::Priority priority) const
 Return format for given log level. More...
 
void initActions ()
 Setup the actions. More...
 
void initFormats ()
 Initialize the text formats. More...
 
void setupTextArea (const QFont &font)
 Set the properties of the text display. More...
 
bool shouldBeDisplayed (const Message &msg)
 Return True if message should be shown given current user settings. More...
 

Private Attributes

QString m_activeScript
 
QAction * m_debug
 
QAction * m_error
 Log level actions. More...
 
QHash< Message::Priority, QTextCharFormat > m_formats
 Map priority to text formatting. More...
 
QAction * m_information
 
QtSignalChannelm_logChannel
 A reference to the log channel. More...
 
QSignalMapper * m_logLevelMapping
 Map action signal to log level parameter. More...
 
QActionGroup * m_loglevels
 Mutually exclusive log actions. More...
 
QList< Messagem_messageHistory
 Keep track of the message history. More...
 
QAction * m_notice
 
bool m_showActiveScriptOutput {false}
 
bool m_showAllScriptOutput {true}
 
bool m_showFrameworkOutput {true}
 Bools to dictate whether to print certain types of messages. More...
 
QPlainTextEdit * m_textDisplay
 The actual widget holding the text. More...
 
QAction * m_warning
 

Detailed Description

Provides a widget for display messages in a text box It deals with Message objects which in turn hide whether a message is a framework Poco message or a simple string.

It can connect to the Mantid logging framework if required

Definition at line 43 of file MessageDisplay.h.

Constructor & Destructor Documentation

◆ MessageDisplay() [1/3]

MantidQt::MantidWidgets::MessageDisplay::MessageDisplay ( QWidget *  parent = nullptr)

Default constructor with optional parent.

Construct a MessageDisplay with the default font.

Parameters
parentAn optional parent widget

Definition at line 78 of file MessageDisplay.cpp.

◆ MessageDisplay() [2/3]

MantidQt::MantidWidgets::MessageDisplay::MessageDisplay ( const QFont &  font,
QWidget *  parent = nullptr 
)

Constructor accepting a QFont.

Construct a MessageDisplay using the given font.

Parameters
fontA reference to a font object
parentAn optional parent widget

Definition at line 85 of file MessageDisplay.cpp.

References initActions(), initFormats(), and setupTextArea().

◆ MessageDisplay() [3/3]

MantidQt::MantidWidgets::MessageDisplay::MessageDisplay ( const MessageDisplay )
delete

◆ ~MessageDisplay()

MantidQt::MantidWidgets::MessageDisplay::~MessageDisplay ( )
override

Destructor.

Definition at line 96 of file MessageDisplay.cpp.

References m_logChannel, and m_textDisplay.

Member Function Documentation

◆ activeScript()

QString MantidQt::MantidWidgets::MessageDisplay::activeScript ( ) const
inline

Get the path of the currently active script.

Definition at line 93 of file MessageDisplay.h.

Referenced by shouldBeDisplayed().

◆ append

void MantidQt::MantidWidgets::MessageDisplay::append ( const Message msg)
slot

◆ appendDebug

void MantidQt::MantidWidgets::MessageDisplay::appendDebug ( const QString &  text)
slot

Convenience method for appending message at debug level.

Parameters
textThe text string to append at PRIO_DEBUG level

Definition at line 219 of file MessageDisplay.cpp.

References append().

◆ appendError

void MantidQt::MantidWidgets::MessageDisplay::appendError ( const QString &  text)
slot

Convenience method for appending message at error level.

Parameters
textThe text string to append at PRIO_ERROR level

Definition at line 195 of file MessageDisplay.cpp.

References append().

◆ appendFatal

void MantidQt::MantidWidgets::MessageDisplay::appendFatal ( const QString &  text)
slot

Convenience method for appending message at fatal level.

Parameters
textThe text string to append at PRIO_FATAL level

Definition at line 190 of file MessageDisplay.cpp.

References append().

◆ appendInformation

void MantidQt::MantidWidgets::MessageDisplay::appendInformation ( const QString &  text)
slot

Convenience method for appending message at information level.

Parameters
textThe text string to append at PRIO_INFORMATION level

Definition at line 212 of file MessageDisplay.cpp.

References append().

◆ appendNotice

void MantidQt::MantidWidgets::MessageDisplay::appendNotice ( const QString &  text)
slot

Convenience method for appending message at notice level.

Parameters
textThe text string to append at PRIO_NOTICE level

Definition at line 207 of file MessageDisplay.cpp.

References append().

◆ appendPython

void MantidQt::MantidWidgets::MessageDisplay::appendPython ( const QString &  text,
const int &  priority,
const QString &  filePath 
)
slot

Write a Python script message, intended for use with Python API.

Append a message to the message window, adding the script name associated with the message.

Parameters
textThe message to display in the window
priorityThe priority level of the message
filePathThe path of the Python script being executed

Definition at line 251 of file MessageDisplay.cpp.

References append().

◆ appendToHistory()

void MantidQt::MantidWidgets::MessageDisplay::appendToHistory ( const Message msg)

Append a message to the message history.

If the length of the history exceeds the max line count, remove entries from the start until it does not.

Parameters
msgThe Message object to append

Definition at line 177 of file MessageDisplay.cpp.

References m_messageHistory, and maximumLineCount().

Referenced by append().

◆ appendWarning

void MantidQt::MantidWidgets::MessageDisplay::appendWarning ( const QString &  text)
slot

Convenience method for appending message at warning level.

Parameters
textThe text string to append at PRIO_WARNING level

Definition at line 200 of file MessageDisplay.cpp.

References append().

◆ attachLoggingChannel()

void MantidQt::MantidWidgets::MessageDisplay::attachLoggingChannel ( int  logLevel = 0)

Attaches the Mantid logging framework.

Starts the ConfigService if required

Parameters
logLevelIf > 0 then set the filter channel level to this. A number =< 0 uses the channel

Definition at line 118 of file MessageDisplay.cpp.

References append(), Mantid::Kernel::SingletonHolder< T >::Instance(), and m_logChannel.

◆ clear

void MantidQt::MantidWidgets::MessageDisplay::clear ( )
slot

Clear all of the text.

Definition at line 267 of file MessageDisplay.cpp.

References m_messageHistory, and m_textDisplay.

Referenced by generateContextMenu(), and replace().

◆ errorReceived

void MantidQt::MantidWidgets::MessageDisplay::errorReceived ( const QString &  text)
signal

Indicate that a message of error or higher has been received.

Referenced by append().

◆ filePathModified()

void MantidQt::MantidWidgets::MessageDisplay::filePathModified ( const QString &  oldPath,
const QString &  newPath 
)

Method to be called when a file's path is modified.

Each Message object associated with the file has its scriptPath attribute updated.

Parameters
oldPathThe path of the file being renamed
newPathThe new path of the file

Definition at line 165 of file MessageDisplay.cpp.

References m_messageHistory.

◆ filterMessages()

void MantidQt::MantidWidgets::MessageDisplay::filterMessages ( )

Filter messages by message type.

Filter messages, either by Framework or all/individual scripts.

Definition at line 149 of file MessageDisplay.cpp.

References format(), getHistory(), m_textDisplay, moveCursorToEnd(), and shouldBeDisplayed().

◆ format()

QTextCharFormat MantidQt::MantidWidgets::MessageDisplay::format ( const Message::Priority  priority) const
private

Return format for given log level.

Parameters
priorityAn enumeration for the log level
Returns
format for given log level

Definition at line 467 of file MessageDisplay.cpp.

References m_formats.

Referenced by append(), filterMessages(), and initFormats().

◆ generateContextMenu()

QMenu * MantidQt::MantidWidgets::MessageDisplay::generateContextMenu ( )

Generate the display's context menu QMenu object.

Definition at line 359 of file MessageDisplay.cpp.

References clear(), m_debug, m_error, m_information, m_notice, m_textDisplay, m_warning, and setScrollbackLimit().

Referenced by showContextMenu().

◆ getHistory()

QList< Message > MantidQt::MantidWidgets::MessageDisplay::getHistory ( )
inline

Get the window's message history.

Definition at line 71 of file MessageDisplay.h.

Referenced by filterMessages().

◆ getTextEdit()

QPlainTextEdit * MantidQt::MantidWidgets::MessageDisplay::getTextEdit ( )
inline

Get the window's QPlainTextEdit object.

Definition at line 69 of file MessageDisplay.h.

◆ initActions()

void MantidQt::MantidWidgets::MessageDisplay::initActions ( )
private

Setup the actions.

Definition at line 391 of file MessageDisplay.cpp.

References m_debug, m_error, m_information, m_logLevelMapping, m_loglevels, m_notice, m_warning, and setLogLevel().

Referenced by MessageDisplay().

◆ initFormats()

void MantidQt::MantidWidgets::MessageDisplay::initFormats ( )
private

Initialize the text formats.

Sets up the internal map of text formatters for each log level.

Definition at line 422 of file MessageDisplay.cpp.

References format(), and m_formats.

Referenced by MessageDisplay().

◆ isScrollbarAtBottom

bool MantidQt::MantidWidgets::MessageDisplay::isScrollbarAtBottom ( ) const
slot

Returns true if scroll-bar is at the bottom of widget.

Returns
True if scroll bar is at bottom, false otherwise

Definition at line 285 of file MessageDisplay.cpp.

References m_textDisplay.

◆ maximumLineCount

int MantidQt::MantidWidgets::MessageDisplay::maximumLineCount ( ) const
privateslot

Return the maximum number of lines displayed.

Returns
The maximum number of lines displayed in the text edit

Definition at line 348 of file MessageDisplay.cpp.

References m_textDisplay.

Referenced by appendToHistory(), setScrollbackLimit(), and writeSettings().

◆ moveCursorToEnd

QTextCursor MantidQt::MantidWidgets::MessageDisplay::moveCursorToEnd ( )
slot

Move the text cursor to after the last character.

Returns
The cursor at the end of the text

Definition at line 275 of file MessageDisplay.cpp.

References m_textDisplay.

Referenced by append(), and filterMessages().

◆ operator=()

MessageDisplay & MantidQt::MantidWidgets::MessageDisplay::operator= ( const MessageDisplay )
delete

◆ readSettings()

void MantidQt::MantidWidgets::MessageDisplay::readSettings ( const QSettings &  storage)
overridevirtual

Load settings from the persistent store.

The client is expected to call this method with the QSettings object opened at the approriate group

Parameters
storageA pointer to an existing QSettings instance opened at the group containing the values

Implements MantidQt::MantidWidgets::Configurable.

Definition at line 55 of file MessageDisplay.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), and setMaximumLineCount().

◆ replace

void MantidQt::MantidWidgets::MessageDisplay::replace ( const Message msg)
slot

Replace the display text with the given contents.

Parameters
msgReplace the current contents with this message

Definition at line 259 of file MessageDisplay.cpp.

References append(), clear(), and MantidQt::MantidWidgets::Message::text().

◆ scrollToBottom

void MantidQt::MantidWidgets::MessageDisplay::scrollToBottom ( )
slot

Scroll to the bottom of the text.

Moves the cursor to the bottom of the document.

Definition at line 304 of file MessageDisplay.cpp.

References m_textDisplay.

◆ scrollToTop

void MantidQt::MantidWidgets::MessageDisplay::scrollToTop ( )
slot

Scroll to the bottom of the text.

Moves the cursor to the top of the document.

Definition at line 292 of file MessageDisplay.cpp.

References m_textDisplay.

◆ setActiveScript()

void MantidQt::MantidWidgets::MessageDisplay::setActiveScript ( const QString &  scriptPath)
inline

Set the path of the currently active script.

Definition at line 95 of file MessageDisplay.h.

◆ setLogLevel

void MantidQt::MantidWidgets::MessageDisplay::setLogLevel ( int  priority)
privateslot

Set the global logging level.

Definition at line 327 of file MessageDisplay.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance().

Referenced by initActions().

◆ setMaximumLineCount

void MantidQt::MantidWidgets::MessageDisplay::setMaximumLineCount ( int  count)
privateslot

Set the maximum number of lines displayed.

The maximum number of lines that are to be displayed in the text edit.

Parameters
countThe new maximum number of lines to retain.

Definition at line 354 of file MessageDisplay.cpp.

References count, and m_textDisplay.

Referenced by readSettings(), setScrollbackLimit(), and setupTextArea().

◆ setScrollbackLimit

void MantidQt::MantidWidgets::MessageDisplay::setScrollbackLimit ( )
privateslot

Set the number of blocks kept by the display.

Set the maximum number of blocks kept by the text edit.

Definition at line 332 of file MessageDisplay.cpp.

References maximumLineCount(), and setMaximumLineCount().

Referenced by generateContextMenu().

◆ setShowActiveScriptOutput()

void MantidQt::MantidWidgets::MessageDisplay::setShowActiveScriptOutput ( const bool &  show)
inline

Get whether only active script output should be displayed.

Definition at line 91 of file MessageDisplay.h.

◆ setShowAllScriptOutput()

void MantidQt::MantidWidgets::MessageDisplay::setShowAllScriptOutput ( const bool &  show)
inline

Set whether all script output should be displayed.

Definition at line 87 of file MessageDisplay.h.

◆ setShowFrameworkOutput()

void MantidQt::MantidWidgets::MessageDisplay::setShowFrameworkOutput ( const bool &  show)
inline

Set whether framework output should be displayed.

Definition at line 83 of file MessageDisplay.h.

◆ setSource()

void MantidQt::MantidWidgets::MessageDisplay::setSource ( const QString &  source)

If set, only Mantid log messages from this source are emitted.

Parameters
sourceA string specifying the required source for messages that will be emitted

Definition at line 144 of file MessageDisplay.cpp.

References m_logChannel, MantidQt::MantidWidgets::QtSignalChannel::setSource(), and source.

◆ setupTextArea()

void MantidQt::MantidWidgets::MessageDisplay::setupTextArea ( const QFont &  font)
private

Set the properties of the text display.

Set the properties of the text display, i.e read-only and make it occupy the whole widget.

Parameters
fontA reference to the font for the text area

Definition at line 444 of file MessageDisplay.cpp.

References m_textDisplay, setMaximumLineCount(), and showContextMenu().

Referenced by MessageDisplay().

◆ shouldBeDisplayed()

bool MantidQt::MantidWidgets::MessageDisplay::shouldBeDisplayed ( const Message msg)
private

Return True if message should be shown given current user settings.

Returns true if the given message should be displayed given the current settings.

Parameters
msgA Message object

Definition at line 475 of file MessageDisplay.cpp.

References activeScript(), MantidQt::MantidWidgets::Message::scriptPath(), showActiveScriptOutput(), showAllScriptOutput(), and showFrameworkOutput().

Referenced by append(), and filterMessages().

◆ showActiveScriptOutput()

bool MantidQt::MantidWidgets::MessageDisplay::showActiveScriptOutput ( ) const
inline

Get whether only active script output is being displayed.

Definition at line 89 of file MessageDisplay.h.

Referenced by shouldBeDisplayed().

◆ showAllScriptOutput()

bool MantidQt::MantidWidgets::MessageDisplay::showAllScriptOutput ( ) const
inline

Get whether all script output is being displayed.

Definition at line 85 of file MessageDisplay.h.

Referenced by shouldBeDisplayed().

◆ showContextMenu

void MantidQt::MantidWidgets::MessageDisplay::showContextMenu ( const QPoint &  event)
privateslot

Provide a custom context menu.

Definition at line 317 of file MessageDisplay.cpp.

References generateContextMenu().

Referenced by setupTextArea().

◆ showFrameworkOutput()

bool MantidQt::MantidWidgets::MessageDisplay::showFrameworkOutput ( ) const
inline

Get whether framework output is being displayed.

Definition at line 81 of file MessageDisplay.h.

Referenced by shouldBeDisplayed().

◆ source()

const QString & MantidQt::MantidWidgets::MessageDisplay::source ( ) const
inline

Get the current source are emitted.

Definition at line 67 of file MessageDisplay.h.

◆ warningReceived

void MantidQt::MantidWidgets::MessageDisplay::warningReceived ( const QString &  text)
signal

Indicate that a message of warning or higher has been received.

Referenced by append().

◆ writeSettings()

void MantidQt::MantidWidgets::MessageDisplay::writeSettings ( QSettings &  storage) const
overridevirtual

Load settings from the persistent store.

The client is expected to call this method with the QSettings object opened at the approriate group

Parameters
storageA pointer to an existing QSettings instance opened at the group where the values should be stored.

Implements MantidQt::MantidWidgets::Configurable.

Definition at line 69 of file MessageDisplay.cpp.

References maximumLineCount().

Member Data Documentation

◆ m_activeScript

QString MantidQt::MantidWidgets::MessageDisplay::m_activeScript
private

Definition at line 173 of file MessageDisplay.h.

◆ m_debug

QAction * MantidQt::MantidWidgets::MessageDisplay::m_debug
private

Definition at line 168 of file MessageDisplay.h.

Referenced by generateContextMenu(), and initActions().

◆ m_error

QAction* MantidQt::MantidWidgets::MessageDisplay::m_error
private

Log level actions.

Definition at line 168 of file MessageDisplay.h.

Referenced by generateContextMenu(), and initActions().

◆ m_formats

QHash<Message::Priority, QTextCharFormat> MantidQt::MantidWidgets::MessageDisplay::m_formats
private

Map priority to text formatting.

Definition at line 162 of file MessageDisplay.h.

Referenced by format(), and initFormats().

◆ m_information

QAction * MantidQt::MantidWidgets::MessageDisplay::m_information
private

Definition at line 168 of file MessageDisplay.h.

Referenced by generateContextMenu(), and initActions().

◆ m_logChannel

QtSignalChannel* MantidQt::MantidWidgets::MessageDisplay::m_logChannel
private

A reference to the log channel.

Definition at line 158 of file MessageDisplay.h.

Referenced by attachLoggingChannel(), setSource(), and ~MessageDisplay().

◆ m_logLevelMapping

QSignalMapper* MantidQt::MantidWidgets::MessageDisplay::m_logLevelMapping
private

Map action signal to log level parameter.

Definition at line 166 of file MessageDisplay.h.

Referenced by initActions().

◆ m_loglevels

QActionGroup* MantidQt::MantidWidgets::MessageDisplay::m_loglevels
private

Mutually exclusive log actions.

Definition at line 164 of file MessageDisplay.h.

Referenced by initActions().

◆ m_messageHistory

QList<Message> MantidQt::MantidWidgets::MessageDisplay::m_messageHistory
private

Keep track of the message history.

Definition at line 170 of file MessageDisplay.h.

Referenced by appendToHistory(), clear(), and filePathModified().

◆ m_notice

QAction * MantidQt::MantidWidgets::MessageDisplay::m_notice
private

Definition at line 168 of file MessageDisplay.h.

Referenced by generateContextMenu(), and initActions().

◆ m_showActiveScriptOutput

bool MantidQt::MantidWidgets::MessageDisplay::m_showActiveScriptOutput {false}
private

Definition at line 172 of file MessageDisplay.h.

◆ m_showAllScriptOutput

bool MantidQt::MantidWidgets::MessageDisplay::m_showAllScriptOutput {true}
private

Definition at line 172 of file MessageDisplay.h.

◆ m_showFrameworkOutput

bool MantidQt::MantidWidgets::MessageDisplay::m_showFrameworkOutput {true}
private

Bools to dictate whether to print certain types of messages.

Definition at line 172 of file MessageDisplay.h.

◆ m_textDisplay

QPlainTextEdit* MantidQt::MantidWidgets::MessageDisplay::m_textDisplay
private

◆ m_warning

QAction * MantidQt::MantidWidgets::MessageDisplay::m_warning
private

Definition at line 168 of file MessageDisplay.h.

Referenced by generateContextMenu(), and initActions().

Property Documentation

◆ source

QString MantidQt::MantidWidgets::MessageDisplay::source
readwrite

Definition at line 43 of file MessageDisplay.h.

Referenced by setSource().


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