QGIS API Documentation  2.11.0-Master
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 
22 #include <QFile>
23 #include <QDateTime>
24 #include <QTableWidget>
25 #include <QToolButton>
26 #include <QStatusBar>
27 #include <QToolTip>
28 #include <QDockWidget>
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  if ( tag.isNull() )
52  tag = tr( "General" );
53 
54  int i;
55  for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != tag; i++ )
56  ;
57 
58  QPlainTextEdit *w;
59  if ( i < tabWidget->count() )
60  {
61  w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
62  tabWidget->setCurrentIndex( i );
63  }
64  else
65  {
66  w = new QPlainTextEdit( this );
67  w->setReadOnly( true );
68  tabWidget->addTab( w, tag );
69  tabWidget->setCurrentIndex( tabWidget->count() - 1 );
70  }
71 
72  QString prefix = QString( "%1\t%2\t" )
73  .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
74  .arg( level );
75  w->appendPlainText( message.prepend( prefix ).replace( "\n", "\n\t\t\t" ) );
77 }
78 
79 void QgsMessageLogViewer::closeTab( int index )
80 {
81  tabWidget->removeTab( index );
82 }
static unsigned index
void setupUi(QWidget *widget)
QString & prepend(QChar ch)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const
void appendPlainText(const QString &text)
QgsMessageLogViewer(QStatusBar *statusBar=0, QWidget *parent=0, Qt::WindowFlags fl=QgisGui::ModalDialogFlags)
QScrollBar * verticalScrollBar() const
void logMessage(QString message, QString tag, QgsMessageLog::MessageLevel level)
void setValue(int)
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