#ifndef LOGGERUI_H #define LOGGERUI_H #include #include "debug/InfoWidget.h" #include /** send all log-messages to the UI */ class LoggerUI : public Logger { private: InfoWidget* iw; const int numLines = 5; std::vector lines; public: /** ctor with the main-menu to show the log within */ LoggerUI(InfoWidget* iw) : iw(iw) { lines.push_back(""); } void add(const std::string& str, const bool nl) override { lines.back() += QString(str.c_str()); if (nl) {lines.push_back("");} while(lines.size() > numLines) {lines.erase(lines.begin());} QString qs = getStr(); QMetaObject::invokeMethod(iw, "showLog", Qt::QueuedConnection, Q_ARG(const QString&, qs)); QApplication::processEvents(); //mm->showActivity(getStr()); } private: QString getStr() const { QString str; for (const QString& line : lines) {str += line + "\n";} str.remove(str.length()-1, 1); return str; } }; #endif // LOGGERUI_H