26 #include <QTableWidget> 27 #include <QToolButton> 30 #include <QPlainTextEdit> 35 : QDialog( parent, fl )
42 connect( tabWidget, &QTabWidget::tabCloseRequested,
this, &QgsMessageLogViewer::closeTab );
56 QString cleanedTag = tag;
57 if ( cleanedTag.isNull() )
58 cleanedTag = tr(
"General" );
61 for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ).remove( QChar(
'&' ) ) != cleanedTag; i++ );
63 QPlainTextEdit *w =
nullptr;
64 if ( i < tabWidget->count() )
66 w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
67 tabWidget->setCurrentIndex( i );
71 w =
new QPlainTextEdit(
this );
72 w->setReadOnly(
true );
73 tabWidget->addTab( w, cleanedTag );
74 tabWidget->setCurrentIndex( tabWidget->count() - 1 );
83 levelString = QStringLiteral(
"INFO" );
84 color = QColor( settings.
value( QStringLiteral(
"colors/info" ), QStringLiteral(
"#000000" ) ).toString() );
87 levelString = QStringLiteral(
"WARNING" );
88 color = QColor( settings.
value( QStringLiteral(
"colors/warning" ), QStringLiteral(
"#000000" ) ).toString() );
91 levelString = QStringLiteral(
"CRITICAL" );
92 color = QColor( settings.
value( QStringLiteral(
"colors/critical" ), QStringLiteral(
"#000000" ) ).toString() );
95 levelString = QStringLiteral(
"SUCCESS" );
96 color = QColor( settings.
value( QStringLiteral(
"colors/success" ), QStringLiteral(
"#000000" ) ).toString() );
99 levelString = QStringLiteral(
"NONE" );
100 color = QColor( settings.
value( QStringLiteral(
"colors/default" ), QStringLiteral(
"#000000" ) ).toString() );
104 QString prefix = QStringLiteral(
"<font color=\"%1\">%2 %3 </font>" )
105 .arg( color.name(), QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
106 QString cleanedMessage = message;
107 cleanedMessage = cleanedMessage.prepend( prefix ).replace(
'\n', QLatin1String(
"<br> " ) );
108 w->appendHtml( cleanedMessage );
109 w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
112 void QgsMessageLogViewer::closeTab(
int index )
114 if ( tabWidget->count() == 1 )
115 qobject_cast<QPlainTextEdit *>( tabWidget->widget( 0 ) )->clear();
117 tabWidget->removeTab( index );
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
Emitted whenever the log receives a message.
void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Logs a message to the viewer.
void closeEvent(QCloseEvent *e) override
MessageLevel
Level for messages This will be used both for message log and message bar in application.
A generic dialog widget for displaying QGIS log messages.
static QgsMessageLog * messageLog()
Returns the application's message log.
QgsMessageLogViewer(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Create a new message log viewer.
Interface for logging messages from QGIS in GUI independent way.