Skip to content
Permalink
Browse files
make log tabs closable
  • Loading branch information
jef-n committed Nov 26, 2011
1 parent 0a49c8c commit 414729c88421c0f75ddb823a4c465b98bdbf80e8
Showing with 27 additions and 14 deletions.
  1. +4 −4 src/core/qgsexpression.cpp
  2. +17 −10 src/gui/qgsmessagelogviewer.cpp
  3. +3 −0 src/gui/qgsmessagelogviewer.h
  4. +3 −0 src/ui/qgsmessagelogviewer.ui
8 src/core/qgsexpression.cpp 100755 → 100644
@@ -392,10 +392,10 @@ FnDef QgsExpression::BuiltinFunctions[] =
FnDef( "toreal", 1, fcnToReal, "Conversions" ),
FnDef( "tostring", 1, fcnToString, "Conversions" ),
// string manipulation
FnDef( "lower", 1, fcnLower, "String"),
FnDef( "upper", 1, fcnUpper, "String"),
FnDef( "length", 1, fcnLength, "String"),
FnDef( "replace", 3, fcnReplace, "String"),
FnDef( "lower", 1, fcnLower, "String" ),
FnDef( "upper", 1, fcnUpper, "String" ),
FnDef( "length", 1, fcnLength, "String" ),
FnDef( "replace", 3, fcnReplace, "String" ),
FnDef( "regexp_replace", 3, fcnRegexpReplace, "String" ),
FnDef( "substr", 3, fcnSubstr, "String" ),
// geometry accessors
@@ -31,6 +31,8 @@ QgsMessageLogViewer::QgsMessageLogViewer( QWidget *parent, Qt::WFlags fl )
setupUi( this );
gmInstance = this;
QgsMessageLog::setLogger( logger );

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

QgsMessageLogViewer::~QgsMessageLogViewer()
@@ -40,47 +42,52 @@ QgsMessageLogViewer::~QgsMessageLogViewer()

void QgsMessageLogViewer::logger( QString message, QString tag, int level )
{
if( !gmInstance )
if ( !gmInstance )
return;

gmInstance->logMessage( message, tag, level );
}

void QgsMessageLogViewer::logMessage( QString message, QString tag, int level )
{
if( tag.isNull() )
if ( tag.isNull() )
tag = tr( "General" );

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

QTableWidget *w;
if( i<tabWidget->count() )
if ( i < tabWidget->count() )
{
w = qobject_cast<QTableWidget *>( tabWidget->widget(i) );
w = qobject_cast<QTableWidget *>( tabWidget->widget( i ) );
}
else
{
w = new QTableWidget( 0, 3, this );
w->verticalHeader()->setDefaultSectionSize( 16 );
w->verticalHeader()->setVisible( false );
w->setGridStyle( Qt::DotLine );
w->setEditTriggers(QAbstractItemView::NoEditTriggers);
w->setHorizontalHeaderLabels( QStringList() << tr( "Timestamp" ) << tr( "Message" ) << "Level" );
w->setEditTriggers( QAbstractItemView::NoEditTriggers );
w->setHorizontalHeaderLabels( QStringList() << tr( "Timestamp" ) << tr( "Message" ) << tr( "Level" ) );
tabWidget->addTab( w, tag );
}

int n = w->rowCount();

QgsDebugMsg( QString( "%1: %2[%3] %4" ).arg( n ).arg( QDateTime::currentDateTime().toString( Qt::ISODate ) ).arg( level ).arg( level ) );

w->setRowCount( n+1 );
w->setRowCount( n + 1 );
QTableWidgetItem *item = new QTableWidgetItem( QDateTime::currentDateTime().toString( Qt::ISODate ) );
w->setItem( n, 0, item );
w->setItem( n, 1, new QTableWidgetItem( message ) );
w->setItem( n, 2, new QTableWidgetItem( level ) );
w->setItem( n, 2, new QTableWidgetItem( QString::number( level ) ) );
w->scrollToItem( item );

w->resizeColumnsToContents();
}

void QgsMessageLogViewer::closeTab( int index )
{
tabWidget->removeTab( index );
}
@@ -37,6 +37,9 @@ class GUI_EXPORT QgsMessageLogViewer: public QDialog, public QgsMessageLog, priv
void logMessage( QString message, QString tag = QString::null, int level = 0 );

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

private slots:
void closeTab( int index );
};

#endif
@@ -28,6 +28,9 @@
<property name="currentIndex">
<number>-1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>

0 comments on commit 414729c

Please sign in to comment.