Skip to content

Commit

Permalink
Allow QtChannel to filter on a given source. Refs #6202
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 9, 2013
1 parent 025b543 commit 858ff82
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/QtSignalChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ namespace MantidQt
Q_OBJECT

public:
/// Constructor
QtSignalChannel();
/// Default constructor
QtSignalChannel(const QString & source = "");
/// Destructor
~QtSignalChannel();

/// If set, only Mantid log messages from this source are emitted
void setSource(const QString & source);
/// Get the current source are emitted
inline const QString & source() const { return m_source; }

/// Converts the Poco::Message to a Qt signal
void log(const Poco::Message& msg);

Expand All @@ -62,6 +67,9 @@ namespace MantidQt

private:
Q_DISABLE_COPY(QtSignalChannel);

/// Optional source (use std::string to avoid conversion in comparison)
QString m_source;
};
}
}
Expand Down
24 changes: 21 additions & 3 deletions Code/Mantid/MantidQt/API/src/QtSignalChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,43 @@ namespace MantidQt
{

/**
* Creates a QtSignalChannel. This channel receives
* Poco::Message objects and re-emits MantidQt Message objects
* with the option to specify that only messages from a defined
* source are emitted.
* @param source A string specifying a source for the message
*/
QtSignalChannel::QtSignalChannel()
: QObject(), Poco::Channel()
QtSignalChannel::QtSignalChannel(const QString & source)
: QObject(), Poco::Channel(), m_source(source)
{
}

/**
*/
QtSignalChannel::~QtSignalChannel()
{
}

/**
* @param source A string specifying the required source for messages
* that will be emitted
*/
void QtSignalChannel::setSource(const QString & source)
{
m_source = source;
}

/**
* If the source is set then only messages with a matching source
* cause a Qt signal to be emitted
* @param msg A Poco message object containing a priority & the string message
*/
void QtSignalChannel::log(const Poco::Message& msg)
{
emit messageReceived(API::Message(QString::fromStdString(msg.getText()), msg.getPriority()));
if(m_source.isEmpty() || this->source() == msg.getSource().c_str())
{
emit messageReceived(API::Message(QString::fromStdString(msg.getText()), msg.getPriority()));
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace MantidQt
class MessageDisplay : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString source READ source WRITE setSource);

public:
/// Controls whether the display is allowed to set the log levels
Expand All @@ -56,10 +57,16 @@ namespace MantidQt

// Setup logging framework connections
void attachLoggingChannel();
/// If set, only Mantid log messages from this source are emitted
void setSource(const QString & source);
/// Get the current source are emitted
inline const QString & source() const { return m_logChannel->source(); }

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

public slots:
/// Convenience method for appending message at fatal level
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/MantidQt/MantidWidgets/src/MessageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ namespace MantidQt
this, SLOT(append(const Message &)));
}

/**
* @param source A string specifying the required source for messages
* that will be emitted
*/
void MessageDisplay::setSource(const QString & source)
{
m_logChannel->setSource(source);
}

//----------------------------------------------------------------------------------------
// Public slots
//----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -154,6 +163,7 @@ namespace MantidQt
scrollToBottom();

if(msg.priority() <= Message::Priority::PRIO_ERROR ) emit errorReceived(msg.text());
if(msg.priority() <= Message::Priority::PRIO_WARNING ) emit warningReceived(msg.text());
}

/**
Expand Down Expand Up @@ -285,6 +295,7 @@ namespace MantidQt
void MessageDisplay::setupTextArea()
{
m_textDisplay->setReadOnly(true);
m_textDisplay->ensureCursorVisible();

this->setLayout(new QHBoxLayout(this));
QLayout *layout = this->layout();
Expand Down

0 comments on commit 858ff82

Please sign in to comment.