From 188624440b3f08fea425b573d27d9c03548bdabc Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sat, 3 Nov 2018 21:48:35 +0100 Subject: [PATCH] Fixed proper selection and deselection of current tab in tabbar --- src/DockAreaTabBar.cpp | 21 ++++++++++++++------- src/DockAreaTabBar.h | 4 ++-- src/DockAreaTitleBar.cpp | 4 ++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index e508779..9b3df78 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -244,7 +244,7 @@ void CDockAreaTabBar::setCurrentIndex(int index) return; } - if (index < 0 || index > (count() - 1)) + if (index < -1 || index > (count() - 1)) { qWarning() << Q_FUNC_INFO << "Invalid index" << index; return; @@ -275,7 +275,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab) emit tabInserted(Index); if (Index <= d->CurrentIndex) { - setCurrentIndex(d->CurrentIndex++); + setCurrentIndex(d->CurrentIndex + 1); } } @@ -352,7 +352,14 @@ int CDockAreaTabBar::currentIndex() const //=========================================================================== CDockWidgetTab* CDockAreaTabBar::currentTab() const { - return qobject_cast(d->TabsLayout->itemAt(d->CurrentIndex)->widget()); + if (d->CurrentIndex < 0) + { + return nullptr; + } + else + { + return qobject_cast(d->TabsLayout->itemAt(d->CurrentIndex)->widget()); + } } @@ -378,9 +385,9 @@ void CDockAreaTabBar::onTabClicked() //=========================================================================== CDockWidgetTab* CDockAreaTabBar::tab(int Index) const { - if (Index >= count()) + if (Index >= count() || Index < 0) { - return 0; + return nullptr; } return qobject_cast(d->TabsLayout->itemAt(Index)->widget()); } @@ -456,7 +463,7 @@ void CDockAreaTabBar::closeTab(int Index) } auto Tab = tab(Index); - if (!Tab->isVisibleTo(this)) + if (Tab->isHidden()) { return; } @@ -497,7 +504,7 @@ bool CDockAreaTabBar::isTabOpen(int Index) const return false; } - return tab(Index)->isVisibleTo(this); + return !tab(Index)->isHidden(); } } // namespace ads diff --git a/src/DockAreaTabBar.h b/src/DockAreaTabBar.h index 727ad1d..315092b 100644 --- a/src/DockAreaTabBar.h +++ b/src/DockAreaTabBar.h @@ -120,12 +120,12 @@ public: int count() const; /** - * Returns the current index + * Returns the current index or -1 if no tab is selected */ int currentIndex() const; /** - * Returns the current tab + * Returns the current tab or a nullptr if no tab is selected. */ CDockWidgetTab* currentTab() const; diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index a7c6be2..ace6fdd 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -243,6 +243,10 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action) //============================================================================ void CDockAreaTitleBar::onCurrentTabChanged(int Index) { + if (Index < 0) + { + return; + } CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget(); d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)); }