LCOV - code coverage report
Current view: top level - gui/source - logwidget.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 0 34 0.0 %
Date: 2020-10-20 00:45:57 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Rimco Boudewijns
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : 
       9             : #include "mcrl2/gui/logwidget.h"
      10             : #include "ui_logwidget.h"
      11             : 
      12             : using namespace mcrl2::gui;
      13             : using namespace mcrl2::gui::qt;
      14             : 
      15           0 : void LogRelay::output(const log_level_t level, 
      16             :                       const std::string& hint, 
      17             :                       const time_t timestamp, 
      18             :                       const std::string& msg, 
      19             :                       const bool /* print_time_information */)
      20             : {
      21           0 :   emit logMessage(QString::fromStdString(log_level_to_string(level)), 
      22           0 :                   QString::fromStdString(hint), 
      23           0 :                   QDateTime::fromTime_t(timestamp), 
      24           0 :                   QString::fromStdString(msg));
      25           0 : }
      26             : 
      27           0 : LogWidget::LogWidget(QWidget *parent)
      28             :   : QWidget(parent),
      29           0 :     m_ui(new Ui::LogWidget)
      30             : {
      31           0 :   m_ui->setupUi(this);
      32           0 :   connect(&m_relay, SIGNAL(logMessage(QString, QString, QDateTime, QString)), this, SLOT(writeMessage(QString, QString, QDateTime, QString)));
      33           0 :   mcrl2_logger::register_output_policy(m_relay);
      34           0 : }
      35             : 
      36           0 : LogWidget::~LogWidget()
      37             : {
      38           0 :   delete m_ui;
      39           0 : }
      40             : 
      41           0 : void LogWidget::writeMessage(QString level, QString hint, QDateTime timestamp, QString message)
      42             : {
      43           0 :   message = message.trimmed();
      44           0 :   if (!message.isEmpty())
      45             :   {
      46           0 :     if (!hint.isEmpty())
      47           0 :       hint.append("::");
      48           0 :     QString formattedMessage = QString("[%1 %2%3] %4").arg(timestamp.toString("hh:mm:ss")).arg(hint).arg(level).arg(message).trimmed();
      49           0 :     switch (log_level_from_string(level.toStdString()))
      50             :     {
      51           0 :       case error:
      52           0 :         m_ui->editOutput->setTextColor(Qt::red);
      53           0 :         break;
      54           0 :       case warning:
      55           0 :         m_ui->editOutput->setTextColor(QColor("orange"));
      56           0 :         break;
      57           0 :       default:
      58           0 :         setTextEditTextColor(m_ui->editOutput, Qt::black, Qt::white);
      59           0 :         break;
      60             :     }
      61             : 
      62           0 :     m_ui->editOutput->append(formattedMessage);
      63           0 :     emit logMessage(level, hint, timestamp, message, formattedMessage);
      64             :   }
      65           0 : }

Generated by: LCOV version 1.13