Skip to content
Permalink
Browse files

add colors in the log panel for critical and warning levels

  • Loading branch information
Gustry authored and nyalldawson committed Mar 19, 2018
1 parent 57e1982 commit 648ce14d4fc580f1afe283422bc5c8525b66a7ad
Showing with 20 additions and 4 deletions.
  1. +8 −0 resources/qgis_global_settings.ini
  2. +12 −4 src/gui/qgsmessagelogviewer.cpp
@@ -29,6 +29,14 @@ connections-xyz\OpenStreetMap\username=
connections-xyz\OpenStreetMap\zmax=19
connections-xyz\OpenStreetMap\zmin=0

[colors]
# These colors are used in logs.
default=
info=
success=
warning=#dc7d00
critical=#c80000

[help]
# Default help location to include
# for now this is online version of the User Guide for latest (LTR) release
@@ -17,6 +17,7 @@

#include "qgsmessagelogviewer.h"
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgsapplication.h"
#include "qgsdockwidget.h"

@@ -74,30 +75,37 @@ void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag
}

QString levelString;
QgsSettings settings;
QColor color;
switch ( level )
{
case Qgis::Info:
levelString = QStringLiteral( "INFO" );
color = QColor( settings.value( QStringLiteral( "colors/info" ), QStringLiteral( "#000000" ) ).toString() );
break;
case Qgis::Warning:
levelString = QStringLiteral( "WARNING" );
color = QColor( settings.value( QStringLiteral( "colors/warning" ), QStringLiteral( "#000000" ) ).toString() );
break;
case Qgis::Critical:
levelString = QStringLiteral( "CRITICAL" );
color = QColor( settings.value( QStringLiteral( "colors/critical" ), QStringLiteral( "#000000" ) ).toString() );
break;
case Qgis::Success:
levelString = QStringLiteral( "SUCCESS" );
color = QColor( settings.value( QStringLiteral( "colors/success" ), QStringLiteral( "#000000" ) ).toString() );
break;
case Qgis::None:
levelString = QStringLiteral( "NONE" );
color = QColor( settings.value( QStringLiteral( "colors/default" ), QStringLiteral( "#000000" ) ).toString() );
break;
}

QString prefix = QStringLiteral( "%1\t%2\t" )
.arg( QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
QString prefix = QStringLiteral( "<font color=\"%1\">%2 &nbsp;&nbsp;&nbsp; %3 &nbsp;&nbsp;&nbsp;</font>" )
.arg( color.name(), QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
QString cleanedMessage = message;
cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) );
w->appendPlainText( cleanedMessage );
cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" ) );
w->appendHtml( cleanedMessage );
w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}

0 comments on commit 648ce14

Please sign in to comment.
You can’t perform that action at this time.