From 82da5fca6f952c68fb25278dfab677ca0f58f4a7 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 22 Oct 2014 23:12:20 +0100 Subject: [PATCH] refs #338 Convenience methods. --- src/blackmisc/loghandler.h | 26 +++++++++++++++++++++++ src/swiftgui_standard/mainwindow_init.cpp | 3 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/loghandler.h b/src/blackmisc/loghandler.h index 5e586fcfc..ce2247ccc 100644 --- a/src/blackmisc/loghandler.h +++ b/src/blackmisc/loghandler.h @@ -46,6 +46,13 @@ namespace BlackMisc //! \warning This must only be called from the main thread. CLogPatternHandler *handlerForPattern(const CLogPattern &pattern); + //! Return a pattern handler for subscribing to all validation warnings and errors. + //! \warning This must only be called from the main thread. + CLogPatternHandler *handlerForValidation() + { + return handlerForPattern(CLogPattern::exactMatch(CLogCategory::validation()).withSeverityAtOrAbove(CStatusMessage::SeverityWarning)); + } + signals: //! Emitted when a message is logged in this process. void localMessageLogged(const BlackMisc::CStatusMessage &message); @@ -128,6 +135,25 @@ namespace BlackMisc */ void messageLogged(const CStatusMessage &message); + public: + /*! + * Convenience method to connect the messageLogged signal to a slot in the given receiver object. + */ + template + QMetaObject::Connection subscribe(T *receiver, F slot) + { + return connect(this, &CLogPatternHandler::messageLogged, receiver, slot); + } + + /*! + * Convenience method to connect the messageLogged signal to a functor. + */ + template + QMetaObject::Connection subscribe(F slot) + { + return connect(this, &CLogPatternHandler::messageLogged, slot); + } + private: friend class CLogHandler; CLogPatternHandler(QObject *parent) : QObject(parent) {} diff --git a/src/swiftgui_standard/mainwindow_init.cpp b/src/swiftgui_standard/mainwindow_init.cpp index 8905fcdb3..99c569716 100644 --- a/src/swiftgui_standard/mainwindow_init.cpp +++ b/src/swiftgui_standard/mainwindow_init.cpp @@ -112,8 +112,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds); // log messages - auto *logHandler = CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo)); - this->connect(logHandler, &CLogPatternHandler::messageLogged, this, &MainWindow::ps_displayStatusMessageInGui); + CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo))->subscribe(this, &MainWindow::ps_displayStatusMessageInGui); Q_ASSERT(connect); Q_UNUSED(connect); // suppress GCC warning in release build