Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement a QGIS 3.0 TODO for QgsMessageLogViewer, cleanup docs
  • Loading branch information
nyalldawson committed Apr 17, 2017
1 parent 798c318 commit 96d5b9d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
5 changes: 5 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
----------------
Expand Down
11 changes: 6 additions & 5 deletions python/gui/qgsmessagelogviewer.sip
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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" ) );
Expand Down
20 changes: 11 additions & 9 deletions src/gui/qgsmessagelogviewer.cpp
Expand Up @@ -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 );
}
Expand All @@ -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;
Expand All @@ -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() );
}

Expand Down
13 changes: 8 additions & 5 deletions src/gui/qgsmessagelogviewer.h
Expand Up @@ -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;
Expand Down

0 comments on commit 96d5b9d

Please sign in to comment.