Skip to content
Permalink
Browse files

[FEATURE] add status bar tool button that toggles visibility of messa…

…ge log and show tooltips when messages appear while message log is hidden
  • Loading branch information
jef-n committed Jan 10, 2012
1 parent ff6a46e commit 325df2697bda8ed61acd3788e13a4118cd8e83bc
@@ -182,6 +182,7 @@
<file>themes/default/mIconWaitingForLayerType.png</file>
<file>themes/default/mIconWms.png</file>
<file>themes/default/mIconWmsLayer.png</file>
<file>themes/default/mIconWarn.png</file>
<file>themes/default/mMapserverExport.png</file>
<file>themes/default/plugin.png</file>
<file>themes/default/propertyicons/action.png</file>
@@ -1,4 +1,3 @@

FILE (GLOB IMAGES *.png)

INSTALL (FILES ${IMAGES}
Binary file not shown.
@@ -173,6 +173,14 @@ void myMessageOutput( QtMsgType type, const char *msg )
|| 0 == strncmp( msg, "QWidget::", 9 )
|| 0 == strncmp( msg, "QPainter::", 10 ) )
{
#if 0
#ifdef linux
fprintf( stderr, "Stacktrace (run through c++filt):\n" );
void *buffer[256];
int nptrs = backtrace( buffer, sizeof( buffer ) / sizeof( *buffer ) );
backtrace_symbols_fd( buffer, nptrs, STDERR_FILENO );
#endif
#endif
QgsMessageLog::logMessage( msg, "Qt" );
}
#endif
@@ -479,7 +479,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mpGpsDock->setWidget( mpGpsWidget );
mpGpsDock->hide();

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

mLogDock = new QDockWidget( tr( "Log Messages" ), this );
mLogDock->setObjectName( "MessageLog" );
@@ -17,20 +17,52 @@

#include "qgsmessagelogviewer.h"
#include "qgsmessagelog.h"
#include "qgsapplication.h"

#include <QSettings>
#include <QTableWidget>
#include <QFile>
#include <QDateTime>
#include <QTableWidget>
#include <QToolButton>
#include <QStatusBar>
#include <QToolTip>
#include <QDockWidget>

static QgsMessageLogViewer *gmInstance = 0;

QgsMessageLogViewer::QgsMessageLogViewer( QWidget *parent, Qt::WFlags fl )
static QIcon icon( QString icon )
{
// try active theme
QString path = QgsApplication::activeThemePath();
if ( QFile::exists( path + icon ) )
path += icon;
else
path = QgsApplication::defaultThemePath() + icon;

return QIcon( path );
}

QgsMessageLogViewer::QgsMessageLogViewer( QStatusBar *statusBar, QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mButton( 0 )
, mCount( 0 )
{
setupUi( this );
gmInstance = this;
QgsMessageLog::setLogger( logger );

if ( statusBar )
{
mButton = new QToolButton( parent );
mButton->setObjectName( "mMessageLogViewerButton" );
mButton->setMaximumWidth( 20 );
mButton->setMaximumHeight( 20 );
mButton->setIcon( icon( "/mIconWarn.png" ) );
mButton->setToolTip( tr( "No messages." ) );
mButton->setCheckable( true );
connect( mButton, SIGNAL( toggled( bool ) ), this, SLOT( buttonToggled( bool ) ) );
statusBar->addPermanentWidget( mButton, 0 );
}

connect( tabWidget, SIGNAL( tabCloseRequested( int ) ), this, SLOT( closeTab( int ) ) );
}

@@ -39,6 +71,35 @@ QgsMessageLogViewer::~QgsMessageLogViewer()
QgsMessageLog::setLogger( 0 );
}

void QgsMessageLogViewer::hideEvent( QHideEvent * )
{
if ( mButton )
{
mButton->setChecked( false );
}
}

void QgsMessageLogViewer::showEvent( QShowEvent * )
{
if ( mButton )
{
mButton->setChecked( true );
}
}

void QgsMessageLogViewer::buttonToggled( bool checked )
{
QWidget *w = qobject_cast<QDockWidget *>( parent() );

if ( !w )
w = this;

if ( checked )
w->show();
else
w->hide();
}

void QgsMessageLogViewer::logger( QString message, QString tag, int level )
{
if ( !gmInstance )
@@ -49,6 +110,13 @@ void QgsMessageLogViewer::logger( QString message, QString tag, int level )

void QgsMessageLogViewer::logMessage( QString message, QString tag, int level )
{
mButton->setToolTip( tr( "%1 message(s) logged." ).arg( mCount++ ) );

if ( mButton && !isVisible() )
{
QToolTip::showText( mButton->mapToGlobal( QPoint( 0, 0 ) ), mButton->toolTip() );
}

if ( tag.isNull() )
tag = tr( "General" );

@@ -60,6 +128,7 @@ void QgsMessageLogViewer::logMessage( QString message, QString tag, int level )
if ( i < tabWidget->count() )
{
w = qobject_cast<QTableWidget *>( tabWidget->widget( i ) );
tabWidget->setCurrentIndex( i );
}
else
{
@@ -72,6 +141,8 @@ void QgsMessageLogViewer::logMessage( QString message, QString tag, int level )
w->setHorizontalHeaderLabels( QStringList() << tr( "Timestamp" ) << tr( "Message" ) << tr( "Level" ) );
w->horizontalHeader()->setResizeMode( QHeaderView::ResizeToContents );
tabWidget->addTab( w, tag );

tabWidget->setCurrentIndex( tabWidget->count() - 1 );
}

int n = w->rowCount();
@@ -86,5 +157,12 @@ void QgsMessageLogViewer::logMessage( QString message, QString tag, int level )

void QgsMessageLogViewer::closeTab( int index )
{
QTableWidget *w = qobject_cast<QTableWidget *>( tabWidget->widget( index ) );
if ( w )
{
mCount -= w->rowCount();
if ( mButton )
mButton->setToolTip( tr( "%1 message(s) logged." ).arg( mCount++ ) );
}
tabWidget->removeTab( index );
}
@@ -23,6 +23,11 @@

#include <QString>

class QStatusBar;
class QToolButton;
class QShowEvent;
class QHideEvent;

/** \ingroup gui
* A generic message for displaying QGIS log messages.
* \note added in 1.8
@@ -31,15 +36,23 @@ class GUI_EXPORT QgsMessageLogViewer: public QDialog, public QgsMessageLog, priv
{
Q_OBJECT
public:
QgsMessageLogViewer( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
QgsMessageLogViewer( QStatusBar *statusBar = 0, QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
~QgsMessageLogViewer();

void logMessage( QString message, QString tag = QString::null, int level = 0 );

static void logger( QString message, QString tag, int level );

private:
void showEvent( QShowEvent * );
void hideEvent( QHideEvent * );

QToolButton *mButton;
int mCount;

private slots:
void closeTab( int index );
void buttonToggled( bool checked );
};

#endif

0 comments on commit 325df26

Please sign in to comment.
You can’t perform that action at this time.