17#include <QActionGroup>
18#include <QCoreApplication>
20#include <QInputDialog>
22#include <QPlainTextEdit>
26#include <QSignalMapper>
28#include <Poco/Logger.h>
29#include <Poco/Message.h>
30#include <Poco/SplitterChannel.h>
31#include <Poco/Version.h>
35int DEFAULT_LINE_COUNT_MAX = 8192;
36const char *PRIORITY_KEY_NAME =
"MessageDisplayPriority";
37const char *LINE_COUNT_MAX_KEY_NAME =
"MessageDisplayLineCountMax";
56 const int logLevel = storage.value(PRIORITY_KEY_NAME, 0).toInt();
60 setMaximumLineCount(storage.value(LINE_COUNT_MAX_KEY_NAME, DEFAULT_LINE_COUNT_MAX).toInt());
70 storage.setValue(PRIORITY_KEY_NAME, Poco::Logger::root().getLevel());
86 : QWidget(parent), m_logChannel(new
QtSignalChannel), m_textDisplay(new QPlainTextEdit(this)), m_formats(),
87 m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)),
88 m_error(new QAction(tr(
"&Error"), this)), m_warning(new QAction(tr(
"&Warning"), this)),
89 m_notice(new QAction(tr(
"&Notice"), this)), m_information(new QAction(tr(
"&Information"), this)),
90 m_debug(new QAction(tr(
"&Debug"), this)) {
98 auto rootChannel = Poco::Logger::root().getChannel();
99#if POCO_VERSION > 0x01090400
101 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel.get())) {
103 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel)) {
122 auto rootChannel = Poco::Logger::root().getChannel();
123#if POCO_VERSION > 0x01090400
125 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel.get())) {
127 if (
auto *splitChannel =
dynamic_cast<Poco::SplitterChannel *
>(rootChannel)) {
131 throw std::runtime_error(
"MessageDisplay requires the root logger to be configured with a SplitterChannel.\n"
132 "Set 'logging.loggers.root.channel.class = SplitterChannel' in properties file.");
136 configSvc.setLogLevel(logLevel,
true);
167 if (msg.scriptPath() == oldPath)
168 msg.setScriptPath(newPath);
201 this->
append(
Message(text, Message::Priority::PRIO_WARNING));
213 this->
append(
Message(text, Message::Priority::PRIO_INFORMATION));
232 if (msg.
priority() <= Message::Priority::PRIO_ERROR) {
234 "Sorry, there was an error, please look at the message display for "
236 NotificationService::MessageIcon::Critical);
239 if (msg.
priority() <= Message::Priority::PRIO_WARNING)
277 cursor.movePosition(QTextCursor::End);
319 menu->exec(this->mapToGlobal(mousePos));
333 constexpr int minLineCountAllowed(-1);
335 QInputDialog::getInt(
this,
"",
"No. of lines\n(-1 keeps all content)",
maximumLineCount(), minLineCountAllowed));
361 menu->addSeparator();
363 menu->addAction(
"Clear All",
this, SLOT(
clear()));
364 menu->addSeparator();
367 menu->addSeparator();
369 QMenu *logLevelMenu = menu->addMenu(
"&Log Level");
370 logLevelMenu->addAction(
m_error);
374 logLevelMenu->addAction(
m_debug);
377 int level = Poco::Logger::root().getLevel();
378 if (level == Poco::Message::PRIO_ERROR)
380 if (level == Poco::Message::PRIO_WARNING)
382 if (level == Poco::Message::PRIO_NOTICE)
384 if (level == Poco::Message::PRIO_INFORMATION)
386 if (level >= Poco::Message::PRIO_DEBUG)
426 format.setForeground(Qt::red);
429 format.setForeground(QColor::fromRgb(255, 100, 0));
432 format.setForeground(Qt::gray);
435 format.setForeground(Qt::darkBlue);
449 m_textDisplay->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
453 auto layoutBox =
new QHBoxLayout(
this);
454 layoutBox->setContentsMargins(0, 0, 0, 0);
459 connect(
m_textDisplay, SIGNAL(customContextMenuRequested(
const QPoint &)),
this,
468 return m_formats.value(priority, QTextCharFormat());
479 !QCoreApplication::closingDown())
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...