Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 648ce14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions resources/qgis_global_settings.ini
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/gui/qgsmessagelogviewer.cpp
Expand Up @@ -17,6 +17,7 @@

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

Expand Down Expand Up @@ -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() );
}

Expand Down

0 comments on commit 648ce14

Please sign in to comment.