18#include <QActionGroup>
19#include <QCoreApplication>
21#include <QInputDialog>
23#include <QPlainTextEdit>
27#include <QSignalMapper>
29#include <Poco/Logger.h>
30#include <Poco/Message.h>
31#include <Poco/SplitterChannel.h>
32#include <Poco/Version.h>
36int DEFAULT_LINE_COUNT_MAX = 8192;
37const char *PRIORITY_KEY_NAME =
"MessageDisplayPriority";
38const char *LINE_COUNT_MAX_KEY_NAME =
"MessageDisplayLineCountMax";
51 : m_logLevel(logLevel), m_maximumLineCount(maximumLineCount) {}
59 storage.value(LINE_COUNT_MAX_KEY_NAME, DEFAULT_LINE_COUNT_MAX).toInt());
64 ConfigService::Instance().setLogLevel(settings.
logLevel(),
true);
90 : QWidget(parent), m_logChannel(new
QtSignalChannel), m_textDisplay(new QPlainTextEdit(this)), m_formats(),
91 m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)),
92 m_error(new QAction(tr(
"&Error"), this)), m_warning(new QAction(tr(
"&Warning"), this)),
93 m_notice(new QAction(tr(
"&Notice"), this)), m_information(new QAction(tr(
"&Information"), this)),
94 m_debug(new QAction(tr(
"&Debug"), this)) {
102 auto rootChannel = Poco::Logger::root().getChannel();
103#if POCO_VERSION > 0x01090400
105 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel.get())) {
107 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel)) {
124 auto &configSvc = ConfigService::Instance();
126 auto rootChannel = Poco::Logger::root().getChannel();
127#if POCO_VERSION > 0x01090400
129 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel.get())) {
131 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel)) {
135 throw std::runtime_error(
"MessageDisplay requires the root logger to be configured with a SplitterChannel.\n"
136 "Set 'logging.loggers.root.channel.class = SplitterChannel' in properties file.");
140 configSvc.setLogLevel(logLevel,
true);
171 if (msg.scriptPath() == oldPath)
172 msg.setScriptPath(newPath);
205 this->
append(
Message(text, Message::Priority::PRIO_WARNING));
217 this->
append(
Message(text, Message::Priority::PRIO_INFORMATION));
236 if (msg.
priority() <= Message::Priority::PRIO_ERROR) {
238 "Sorry, there was an error, please look at the message display for "
240 NotificationService::MessageIcon::Critical);
243 if (msg.
priority() <= Message::Priority::PRIO_WARNING)
281 cursor.movePosition(QTextCursor::End);
323 menu->exec(this->mapToGlobal(mousePos));
337 constexpr int minLineCountAllowed(-1);
339 QInputDialog::getInt(
this,
"",
"No. of lines\n(-1 keeps all content)",
maximumLineCount(), minLineCountAllowed));
365 menu->addSeparator();
367 menu->addAction(
"Clear All",
this, SLOT(
clear()));
368 menu->addSeparator();
371 menu->addSeparator();
373 QMenu *logLevelMenu = menu->addMenu(
"&Log Level");
374 logLevelMenu->addAction(
m_error);
378 logLevelMenu->addAction(
m_debug);
381 int level = Poco::Logger::root().getLevel();
382 if (level == Poco::Message::PRIO_ERROR)
384 if (level == Poco::Message::PRIO_WARNING)
386 if (level == Poco::Message::PRIO_NOTICE)
388 if (level == Poco::Message::PRIO_INFORMATION)
390 if (level >= Poco::Message::PRIO_DEBUG)
428 QTextCharFormat textFormat;
430 textFormat.setForeground(Qt::red);
431 m_formats[Message::Priority::PRIO_ERROR] = textFormat;
433 textFormat.setForeground(QColor::fromRgb(255, 100, 0));
434 m_formats[Message::Priority::PRIO_WARNING] = textFormat;
436 textFormat.setForeground(Qt::gray);
437 m_formats[Message::Priority::PRIO_INFORMATION] = textFormat;
439 textFormat.setForeground(QColor::fromRgb(65, 105, 225));
440 m_formats[Message::Priority::PRIO_NOTICE] = textFormat;
453 m_textDisplay->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
457 auto layoutBox =
new QHBoxLayout(
this);
458 layoutBox->setContentsMargins(0, 0, 0, 0);
463 connect(
m_textDisplay, SIGNAL(customContextMenuRequested(
const QPoint &)),
this,
472 return m_formats.value(priority, QTextCharFormat());
483 !QCoreApplication::closingDown())
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService