26 #include <QTableWidget> 27 #include <QToolButton> 30 #include <QPlainTextEdit> 33 #include <QDesktopServices> 36 : QDialog( parent, fl )
43 connect( tabWidget, &QTabWidget::tabCloseRequested,
this, &QgsMessageLogViewer::closeTab );
57 QString cleanedTag = tag;
58 if ( cleanedTag.isNull() )
59 cleanedTag = tr(
"General" );
62 for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ).remove( QChar(
'&' ) ) != cleanedTag; i++ );
64 QPlainTextEdit *w =
nullptr;
65 if ( i < tabWidget->count() )
67 w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
68 tabWidget->setCurrentIndex( i );
72 w =
new QPlainTextEdit(
this );
73 w->setReadOnly(
true );
74 w->viewport()->installEventFilter(
this );
75 tabWidget->addTab( w, cleanedTag );
76 tabWidget->setCurrentIndex( tabWidget->count() - 1 );
85 levelString = QStringLiteral(
"INFO" );
86 color = QColor( settings.
value( QStringLiteral(
"colors/info" ), QStringLiteral(
"#000000" ) ).toString() );
89 levelString = QStringLiteral(
"WARNING" );
90 color = QColor( settings.
value( QStringLiteral(
"colors/warning" ), QStringLiteral(
"#000000" ) ).toString() );
93 levelString = QStringLiteral(
"CRITICAL" );
94 color = QColor( settings.
value( QStringLiteral(
"colors/critical" ), QStringLiteral(
"#000000" ) ).toString() );
97 levelString = QStringLiteral(
"SUCCESS" );
98 color = QColor( settings.
value( QStringLiteral(
"colors/success" ), QStringLiteral(
"#000000" ) ).toString() );
101 levelString = QStringLiteral(
"NONE" );
102 color = QColor( settings.
value( QStringLiteral(
"colors/default" ), QStringLiteral(
"#000000" ) ).toString() );
106 QString prefix = QStringLiteral(
"<font color=\"%1\">%2 %3 </font>" )
107 .arg( color.name(), QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
108 QString cleanedMessage = message;
109 cleanedMessage = cleanedMessage.prepend( prefix ).replace(
'\n', QLatin1String(
"<br> " ) );
110 w->appendHtml( cleanedMessage );
111 w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
114 void QgsMessageLogViewer::closeTab(
int index )
116 if ( tabWidget->count() == 1 )
117 qobject_cast<QPlainTextEdit *>( tabWidget->widget( 0 ) )->clear();
119 tabWidget->removeTab( index );
124 switch ( event->type() )
126 case QEvent::MouseButtonPress:
128 if ( QPlainTextEdit *te = qobject_cast<QPlainTextEdit *>( object->parent() ) )
130 QMouseEvent *me =
static_cast< QMouseEvent *
>( event );
131 mClickedAnchor = ( me->button() & Qt::LeftButton ) ? te->anchorAt( me->pos() ) :
133 if ( !mClickedAnchor.isEmpty() )
139 case QEvent::MouseButtonRelease:
141 if ( QPlainTextEdit *te = qobject_cast<QPlainTextEdit *>( object->parent() ) )
143 QMouseEvent *me =
static_cast< QMouseEvent *
>( event );
144 QString clickedAnchor = ( me->button() & Qt::LeftButton ) ? te->anchorAt( me->pos() ) :
146 if ( !clickedAnchor.isEmpty() && clickedAnchor == mClickedAnchor )
148 QDesktopServices::openUrl( mClickedAnchor );
159 return QDialog::eventFilter(
object, event );
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.
bool eventFilter(QObject *obj, QEvent *ev) override
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.