25 #include <QTableWidget> 26 #include <QToolButton> 29 #include <QPlainTextEdit> 34 : QDialog( parent, fl )
41 connect( tabWidget, &QTabWidget::tabCloseRequested,
this, &QgsMessageLogViewer::closeTab );
55 QString cleanedTag = tag;
56 if ( cleanedTag.isNull() )
57 cleanedTag = tr(
"General" );
60 for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ).remove( QChar(
'&' ) ) != cleanedTag; i++ );
62 QPlainTextEdit *w =
nullptr;
63 if ( i < tabWidget->count() )
65 w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
66 tabWidget->setCurrentIndex( i );
70 w =
new QPlainTextEdit(
this );
71 w->setReadOnly(
true );
72 tabWidget->addTab( w, cleanedTag );
73 tabWidget->setCurrentIndex( tabWidget->count() - 1 );
80 levelString = QStringLiteral(
"INFO" );
83 levelString = QStringLiteral(
"WARNING" );
86 levelString = QStringLiteral(
"CRITICAL" );
89 levelString = QStringLiteral(
"SUCCESS" );
92 levelString = QStringLiteral(
"NONE" );
96 QString prefix = QStringLiteral(
"%1\t%2\t" )
97 .arg( QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
98 QString cleanedMessage = message;
99 cleanedMessage = cleanedMessage.prepend( prefix ).replace(
'\n', QLatin1String(
"\n\t\t\t" ) );
100 w->appendPlainText( cleanedMessage );
101 w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
104 void QgsMessageLogViewer::closeTab(
int index )
106 if ( tabWidget->count() == 1 )
107 qobject_cast<QPlainTextEdit *>( tabWidget->widget( 0 ) )->clear();
109 tabWidget->removeTab( index );
void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
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.