QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmessagelogviewer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmessagelogviewer.cpp - description
3  -------------------
4  begin : October 2011
5  copyright : (C) 2011 by Juergen E. Fischer
6  email : jef at norbit dot de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsmessagelogviewer.h"
19 #include "qgsmessagelog.h"
20 #include "qgsapplication.h"
21 #include "qgsdockwidget.h"
22 
23 #include <QFile>
24 #include <QDateTime>
25 #include <QTableWidget>
26 #include <QToolButton>
27 #include <QStatusBar>
28 #include <QToolTip>
29 #include <QPlainTextEdit>
30 #include <QScrollBar>
31 
32 
34  : QDialog( parent, fl )
35 {
36  Q_UNUSED( statusBar )
37  setupUi( this );
38 
41 
42  connect( tabWidget, SIGNAL( tabCloseRequested( int ) ), this, SLOT( closeTab( int ) ) );
43 }
44 
46 {
47 }
48 
50 {
51  e->ignore();
52 }
53 
55 {
56 }
57 
59 {
60  if ( tag.isNull() )
61  tag = tr( "General" );
62 
63  int i;
64  for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != tag; i++ )
65  ;
66 
67  QPlainTextEdit *w = nullptr;
68  if ( i < tabWidget->count() )
69  {
70  w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
71  tabWidget->setCurrentIndex( i );
72  }
73  else
74  {
75  w = new QPlainTextEdit( this );
76  w->setReadOnly( true );
77  tabWidget->addTab( w, tag );
78  tabWidget->setCurrentIndex( tabWidget->count() - 1 );
79  tabWidget->setTabsClosable( true );
80  }
81 
82  QString prefix = QString( "%1\t%2\t" )
83  .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
84  .arg( level );
85  w->appendPlainText( message.prepend( prefix ).replace( '\n', "\n\t\t\t" ) );
87 }
88 
89 void QgsMessageLogViewer::closeTab( int index )
90 {
91  tabWidget->removeTab( index );
92  tabWidget->setTabsClosable( tabWidget->count() > 1 );
93 }
static unsigned index
void setupUi(QWidget *widget)
QString & prepend(QChar ch)
void closeEvent(QCloseEvent *e) override
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const
void appendPlainText(const QString &text)
void ignore()
QScrollBar * verticalScrollBar() const
void logMessage(QString message, QString tag, QgsMessageLog::MessageLevel level)
void setValue(int)
QgsMessageLogViewer(QStatusBar *statusBar=nullptr, QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
QString & replace(int position, int n, QChar after)
void setReadOnly(bool ro)
QDateTime currentDateTime()
static QgsMessageLog * instance()
typedef WindowFlags
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const