Skip to content

Commit

Permalink
[feature][gui] add "close all tabs" to QgsMessageLogViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and nyalldawson committed Oct 26, 2020
1 parent 0ad1738 commit e248fff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
25 changes: 21 additions & 4 deletions src/gui/qgsmessagelogviewer.cpp
Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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 )
Expand Down
27 changes: 23 additions & 4 deletions src/ui/qgsmessagelogviewer.ui
Expand Up @@ -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>
Expand All @@ -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"/>
Expand Down

0 comments on commit e248fff

Please sign in to comment.