mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-12 16:20:25 +08:00
Fixed proper selection and deselection of current tab in tabbar
This commit is contained in:
parent
72ec61a043
commit
188624440b
@ -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<CDockWidgetTab*>(d->TabsLayout->itemAt(d->CurrentIndex)->widget());
|
||||
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
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user