From: Christoph Egger Date: Tue, 2 Jun 2015 21:11:18 +0000 (+0200) Subject: Make LogDock and LogDockAppender communicate by signals X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=ad626cc187f94df0ce811427af717a202ff82e8b;p=frida%2Ffrida.git Make LogDock and LogDockAppender communicate by signals This way the Appender can work in a different thread from the gui dock without causing problems. Also we no longer need to make the Appender a friend of the gui dock and instead make the dock handle it's own affairs --- diff --git a/src/gui/widgets/LogDock.cxx b/src/gui/widgets/LogDock.cxx index b8b9214..b4efc1d 100644 --- a/src/gui/widgets/LogDock.cxx +++ b/src/gui/widgets/LogDock.cxx @@ -11,10 +11,31 @@ LogDock::LogDock(FridaDock* parent) horizontalHeader()->setStretchLastSection(true); verticalHeader()->setDefaultSectionSize(18); appender = new LogDockAppender; - appender->setTarget(this); + connect(appender, &LogDockAppender::newLogEntry, + this, &LogDock::handleNewLogEntry); log4cxx::BasicConfigurator::configure(appender); } LogDock::~LogDock() { delete appender; } + +void LogDock::handleNewLogEntry(QColor color, QString timestamp, QString level, QString message) { + int rowcount = rowCount(); + insertRow(rowcount); + setItem(rowcount, 0, new QTableWidgetItem(timestamp)); + setItem(rowcount, 1, new QTableWidgetItem(level)); + setItem(rowcount, 2, new QTableWidgetItem(message)); + item(rowcount, 0)->setBackground(color); + item(rowcount, 1)->setBackground(color); + item(rowcount, 2)->setBackground(color); + resizeColumnsToContents(); + + QTimer *timer = new QTimer(this); + timer->setSingleShot(true); + + QObject::connect(timer, &QTimer::timeout, [=]() { + scrollToItem(item(rowcount, 2), QAbstractItemView::PositionAtTop); + }); + timer->start(2); +} diff --git a/src/gui/widgets/LogDock.hxx b/src/gui/widgets/LogDock.hxx index e710635..7845764 100644 --- a/src/gui/widgets/LogDock.hxx +++ b/src/gui/widgets/LogDock.hxx @@ -15,6 +15,7 @@ public: log4cxx::Appender* getAppender(); private: LogDockAppender* appender; + void handleNewLogEntry(QColor color, QString timestamp, QString level, QString message); friend class LogDockAppender; }; diff --git a/src/gui/widgets/LogDockAppender.cxx b/src/gui/widgets/LogDockAppender.cxx index 321860a..a0db7a4 100644 --- a/src/gui/widgets/LogDockAppender.cxx +++ b/src/gui/widgets/LogDockAppender.cxx @@ -42,28 +42,9 @@ void LogDockAppender::append(const spi::LoggingEventPtr& event, Pool& p) { } else if (log4cxx::Level::getTrace() == event->getLevel()) { rowcolor.setRgb(0xee, 0xff, 0xee); } - - int rowcount = target->rowCount(); - target->insertRow(rowcount); - target->setItem(rowcount, 0, new QTableWidgetItem(timestampencode.c_str())); - target->setItem(rowcount, 1, new QTableWidgetItem(event->getLevel()->toString().c_str())); - target->setItem(rowcount, 2, new QTableWidgetItem(messageencode.c_str())); - target->item(rowcount, 0)->setBackground(rowcolor); - target->item(rowcount, 1)->setBackground(rowcolor); - target->item(rowcount, 2)->setBackground(rowcolor); - target->resizeColumnsToContents(); - - QTimer *timer = new QTimer(target); - timer->setSingleShot(true); - - QObject::connect(timer, &QTimer::timeout, [=]() { - target->scrollToItem(target->item(rowcount, 2), QAbstractItemView::PositionAtTop); - }); - timer->start(10); -} - -void LogDockAppender::setTarget(LogDock *target) { - this->target = target; + emit newLogEntry(rowcolor, timestampencode.c_str(), + event->getLevel()->toString().c_str(), + messageencode.c_str()); } void LogDockAppender::close() { diff --git a/src/gui/widgets/LogDockAppender.hxx b/src/gui/widgets/LogDockAppender.hxx index bfe702f..4acf4f4 100644 --- a/src/gui/widgets/LogDockAppender.hxx +++ b/src/gui/widgets/LogDockAppender.hxx @@ -4,16 +4,19 @@ #include #include #include +#include class LogDock; using namespace log4cxx; -class LogDockAppender : public AppenderSkeleton { +class LogDockAppender : public QObject, public AppenderSkeleton { + Q_OBJECT +signals: + void newLogEntry(QColor color, QString timestamp, QString level, QString message); public: LogDockAppender(); - void setTarget(LogDock* target); void append(const spi::LoggingEventPtr& event, helpers::Pool& p); void close(); bool requiresLayout() const; @@ -24,7 +27,6 @@ public: LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() private: - LogDock* target; helpers::StrftimeDateFormat timeformat; };