Fixed proper selection and deselection of current tab in tabbar

This commit is contained in:
Uwe Kindler 2018-11-03 21:48:35 +01:00
parent 72ec61a043
commit 188624440b
3 changed files with 20 additions and 9 deletions

View File

@ -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);
}
}
@ -351,9 +351,16 @@ int CDockAreaTabBar::currentIndex() const
//===========================================================================
CDockWidgetTab* CDockAreaTabBar::currentTab() const
{
if (d->CurrentIndex < 0)
{
return nullptr;
}
else
{
return qobject_cast<CDockWidgetTab*>(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<CDockWidgetTab*>(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

View File

@ -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;

View File

@ -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));
}