Skip to content
Permalink
Browse files
Implement a QGIS 3.0 TODO for QgsMessageLogViewer, cleanup docs
  • Loading branch information
nyalldawson committed Apr 17, 2017
1 parent 798c318 commit 96d5b9dae64233f37746415bc5d1e8f3c3a61268
Showing with 31 additions and 20 deletions.
  1. +5 −0 doc/api_break.dox
  2. +6 −5 python/gui/qgsmessagelogviewer.sip
  3. +1 −1 src/app/qgisapp.cpp
  4. +11 −9 src/gui/qgsmessagelogviewer.cpp
  5. +8 −5 src/gui/qgsmessagelogviewer.h
@@ -1481,6 +1481,11 @@ QgsMessageLog {#qgis_api_break_3_0_QgsMessageLog}

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::messageLog() to access an application-wide log.

QgsMessageLogViewer {#qgis_api_break_3_0_QgsMessageLogViewer}
---------------------------

- The constructor no longer accepts a QStatusBar argument (this argument was unused).


QgsMimeDataUtils {#qgis_api_break_3_0_QgsMimeDataUtils}
----------------
@@ -21,17 +21,18 @@ class QgsMessageLogViewer: QDialog
%End
public:

QgsMessageLogViewer( QStatusBar *statusBar = 0, QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
QgsMessageLogViewer( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
%Docstring
Create a new message log viewer, it will automatically connect to the system's
QgsMessageLog.instance() singleton.
Create a new message log viewer. The viewer will automatically connect to the system's
QgsApplication.messageLog() instance.
%End

public slots:

void logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level );
%Docstring
TODO QGIS 3.0: remove statusBar (it's unused)
Logs a message to the viewer.
%End
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level );

protected:
void closeEvent( QCloseEvent *e );
@@ -905,7 +905,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

mLastMapToolMessage = nullptr;

mLogViewer = new QgsMessageLogViewer( statusBar(), this );
mLogViewer = new QgsMessageLogViewer( this );

mLogDock = new QgsDockWidget( tr( "Log Messages Panel" ), this );
mLogDock->setObjectName( QStringLiteral( "MessageLog" ) );
@@ -30,14 +30,13 @@
#include <QScrollBar>


QgsMessageLogViewer::QgsMessageLogViewer( QStatusBar *statusBar, QWidget *parent, Qt::WindowFlags fl )
QgsMessageLogViewer::QgsMessageLogViewer( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
Q_UNUSED( statusBar )
setupUi( this );

connect( QgsApplication::messageLog(), static_cast<void ( QgsMessageLog::* )( const QString &, const QString &, QgsMessageLog::MessageLevel )>( &QgsMessageLog::messageReceived ),
this, static_cast<void ( QgsMessageLogViewer::* )( QString, QString, QgsMessageLog::MessageLevel )>( &QgsMessageLogViewer::logMessage ) );
this, static_cast<void ( QgsMessageLogViewer::* )( const QString &, const QString &, QgsMessageLog::MessageLevel )>( &QgsMessageLogViewer::logMessage ) );

connect( tabWidget, &QTabWidget::tabCloseRequested, this, &QgsMessageLogViewer::closeTab );
}
@@ -51,13 +50,14 @@ void QgsMessageLogViewer::reject()
{
}

void QgsMessageLogViewer::logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level )
void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
{
if ( tag.isNull() )
tag = tr( "General" );
QString cleanedTag = tag;
if ( cleanedTag.isNull() )
cleanedTag = tr( "General" );

int i;
for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != tag; i++ )
for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != cleanedTag; i++ )
;

QPlainTextEdit *w = nullptr;
@@ -70,15 +70,17 @@ void QgsMessageLogViewer::logMessage( QString message, QString tag, QgsMessageLo
{
w = new QPlainTextEdit( this );
w->setReadOnly( true );
tabWidget->addTab( w, tag );
tabWidget->addTab( w, cleanedTag );
tabWidget->setCurrentIndex( tabWidget->count() - 1 );
tabWidget->setTabsClosable( true );
}

QString prefix = QStringLiteral( "%1\t%2\t" )
.arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
.arg( level );
w->appendPlainText( message.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) ) );
QString cleanedMessage = message;
cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) );
w->appendPlainText( cleanedMessage );
w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}

@@ -37,14 +37,17 @@ class GUI_EXPORT QgsMessageLogViewer: public QDialog, private Ui::QgsMessageLogV
public:

/**
* Create a new message log viewer, it will automatically connect to the system's
* QgsMessageLog::instance() singleton.
* Create a new message log viewer. The viewer will automatically connect to the system's
* QgsApplication::messageLog() instance.
*/
QgsMessageLogViewer( QStatusBar *statusBar = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
// TODO QGIS 3.0: remove statusBar (it's unused)
QgsMessageLogViewer( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );

public slots:
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level );

/**
* Logs a \a message to the viewer.
*/
void logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level );

protected:
void closeEvent( QCloseEvent *e ) override;

0 comments on commit 96d5b9d

Please sign in to comment.