Skip to content

Commit

Permalink
[FEATURE] add status bar tool button that toggles visibility of messa…
Browse files Browse the repository at this point in the history
…ge log and show tooltips when messages appear while message log is hidden
  • Loading branch information
jef-n authored and alexbruy committed Jan 31, 2012
1 parent 858b4df commit 53ed744
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 6 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion images/themes/default/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

FILE (GLOB IMAGES *.png)

INSTALL (FILES ${IMAGES}
Expand Down
Binary file added images/themes/default/mIconWarn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
84 changes: 81 additions & 3 deletions src/gui/qgsmessagelogviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}

Expand All @@ -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 )
Expand All @@ -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" );

Expand All @@ -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
{
Expand All @@ -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();
Expand All @@ -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 );
}
15 changes: 14 additions & 1 deletion src/gui/qgsmessagelogviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 53ed744

Please sign in to comment.