Skip to content
Permalink
Browse files

[feature][gui] add "close all tabs" to QgsMessageLogViewer

  • Loading branch information
olivierdalang authored and nyalldawson committed Oct 26, 2020
1 parent 0ad1738 commit e248ffff53af6d823979d4ed87ba52d712f20ccc
Showing with 44 additions and 8 deletions.
  1. +21 −4 src/gui/qgsmessagelogviewer.cpp
  2. +23 −4 src/ui/qgsmessagelogviewer.ui
@@ -82,6 +82,19 @@ void QgsMessageLogViewer::showContextMenuForTabBar( QPoint point )
);
mTabBarContextMenu->addAction( actionCloseOtherTabs );

QAction *actionCloseAllTabs = new QAction( tr( "Close All Tabs" ), mTabBarContextMenu );
actionCloseAllTabs->setEnabled( tabWidget->tabBar()->count() > 0 );
connect( actionCloseAllTabs, &QAction::triggered, this, [this]
{
int i;
for ( i = tabWidget->tabBar()->count() - 1; i >= 0; i-- )
{
closeTab( i );
}
}
);
mTabBarContextMenu->addAction( actionCloseAllTabs );

mTabBarContextMenu->exec( tabWidget->tabBar()->mapToGlobal( point ) );
}

@@ -154,14 +167,18 @@ void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag
cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" ) );
w->appendHtml( cleanedMessage );
w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
tabWidget->show();
emptyLabel->hide();
}

void QgsMessageLogViewer::closeTab( int index )
{
if ( tabWidget->count() == 1 )
qobject_cast<QPlainTextEdit *>( tabWidget->widget( 0 ) )->clear();
else
tabWidget->removeTab( index );
tabWidget->removeTab( index );
if ( tabWidget->count() == 0 )
{
tabWidget->hide();
emptyLabel->show();
}
}

bool QgsMessageLogViewer::eventFilter( QObject *object, QEvent *event )
@@ -16,14 +16,20 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<property name="margin">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="spacing">
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="0">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
@@ -33,6 +39,19 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="emptyLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Message log empty</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>

0 comments on commit e248fff

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