Skip to content

Commit

Permalink
Add light-weight message class. Refs #6202
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 15, 2013
1 parent 07c8220 commit a58a33f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
54 changes: 54 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/Message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef MESSAGE_H_
#define MESSAGE_H_

//----------------------------------
// Includes
//----------------------------------
#include <QObject>
#include <QString>

#include "MantidKernel/ClassMacros.h"
#include "MantidKernel/Logger.h" // So we can match the Logger priority

//----------------------------------------------------------
// Forward declarations
//----------------------------------------------------------

namespace MantidQt
{
namespace API
{
/** @class Message
* Provides a simple binding of a text message with a priority
*/
class Message : public QObject
{
// No Q_Object macro by design

public:
/// Priority matches Mantid Logger priority
typedef Mantid::Kernel::Logger::Priority Priority;

/// Construct a message from a string with a given priority (default=notice)
Message(const QString & text, Priority priority=Priority::PRIO_NOTICE)
: m_text(text), m_priority(priority)
{}

public:

/// @returns The message text
inline QString text() const {return m_text;}
/// @returns The message priority
inline Priority priority() const {return m_priority;}

private:
DISABLE_DEFAULT_CONSTRUCT(Message);

QString m_text;
Priority m_priority;
};

}
}

#endif //MESSAGE_H_
9 changes: 7 additions & 2 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/MessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace MantidQt
{
namespace API
{
//----------------------------------------------------------
// Forward declarations
//----------------------------------------------------------
class Message;

/** @class MessageDisplay
* Provides a widget for display messages in a text box
* It deals with Message objects which in turn hide whether
Expand Down Expand Up @@ -48,9 +53,9 @@ namespace MantidQt

public slots:
/// Write a message after the current contents
void append(const QString & msg);
void append(const Message & msg);
/// Replace the display text with the given contents
void replace(const QString & msg);
void replace(const Message & msg);
/// Clear all of the text
void clear();

Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/MantidQt/API/src/MessageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Includes
//-------------------------------------------
#include "MantidQtAPI/MessageDisplay.h"
#include "MantidQtAPI/Message.h"

#include "MantidKernel/Logger.h"

Expand Down Expand Up @@ -68,17 +69,17 @@ namespace MantidQt
* @param msg A message that is echoed to the display after the
* current text
*/
void MessageDisplay::append(const QString & msg)
void MessageDisplay::append(const Message & msg)
{
m_textDisplay->append(msg);
m_textDisplay->append(msg.text());
}

/**
* @param msg Replace the curren contents with this message
*/
void MessageDisplay::replace(const QString & msg)
void MessageDisplay::replace(const Message & msg)
{
m_textDisplay->setText(msg);
m_textDisplay->setText(msg.text());
}

/**
Expand Down

0 comments on commit a58a33f

Please sign in to comment.