Skip to content

Commit 1886244

Browse files
author
Uwe Kindler
committed
Fixed proper selection and deselection of current tab in tabbar
1 parent 72ec61a commit 1886244

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/DockAreaTabBar.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
244244
return;
245245
}
246246

247-
if (index < 0 || index > (count() - 1))
247+
if (index < -1 || index > (count() - 1))
248248
{
249249
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
250250
return;
@@ -275,7 +275,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
275275
emit tabInserted(Index);
276276
if (Index <= d->CurrentIndex)
277277
{
278-
setCurrentIndex(d->CurrentIndex++);
278+
setCurrentIndex(d->CurrentIndex + 1);
279279
}
280280
}
281281

@@ -352,7 +352,14 @@ int CDockAreaTabBar::currentIndex() const
352352
//===========================================================================
353353
CDockWidgetTab* CDockAreaTabBar::currentTab() const
354354
{
355-
return qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(d->CurrentIndex)->widget());
355+
if (d->CurrentIndex < 0)
356+
{
357+
return nullptr;
358+
}
359+
else
360+
{
361+
return qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(d->CurrentIndex)->widget());
362+
}
356363
}
357364

358365

@@ -378,9 +385,9 @@ void CDockAreaTabBar::onTabClicked()
378385
//===========================================================================
379386
CDockWidgetTab* CDockAreaTabBar::tab(int Index) const
380387
{
381-
if (Index >= count())
388+
if (Index >= count() || Index < 0)
382389
{
383-
return 0;
390+
return nullptr;
384391
}
385392
return qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(Index)->widget());
386393
}
@@ -456,7 +463,7 @@ void CDockAreaTabBar::closeTab(int Index)
456463
}
457464

458465
auto Tab = tab(Index);
459-
if (!Tab->isVisibleTo(this))
466+
if (Tab->isHidden())
460467
{
461468
return;
462469
}
@@ -497,7 +504,7 @@ bool CDockAreaTabBar::isTabOpen(int Index) const
497504
return false;
498505
}
499506

500-
return tab(Index)->isVisibleTo(this);
507+
return !tab(Index)->isHidden();
501508
}
502509
} // namespace ads
503510

src/DockAreaTabBar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ private slots:
120120
int count() const;
121121

122122
/**
123-
* Returns the current index
123+
* Returns the current index or -1 if no tab is selected
124124
*/
125125
int currentIndex() const;
126126

127127
/**
128-
* Returns the current tab
128+
* Returns the current tab or a nullptr if no tab is selected.
129129
*/
130130
CDockWidgetTab* currentTab() const;
131131

src/DockAreaTitleBar.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
243243
//============================================================================
244244
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
245245
{
246+
if (Index < 0)
247+
{
248+
return;
249+
}
246250
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
247251
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
248252
}

0 commit comments

Comments
 (0)