QTabBar: update index of last visible tab in insertTab
Index of the last visible tab was not updated, if a new tab was inserted after the current tab and before the last tab. When the new tab is inserted before the last visible tab, the index of the last tab increments by one. When the new tab is inserted after the last visible tab, then the newly inserted tab becomes the last visible. Fixes: QTBUG-86898 Change-Id: I2f4b7f705261ec35a5aa7b883ecdddba25f007b7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9f9275f82f
commit
b39b018f4a
@ -990,14 +990,16 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text)
|
||||
d->tabList.at(index)->shortcutId = grabShortcut(QKeySequence::mnemonic(text));
|
||||
#endif
|
||||
d->firstVisible = qMax(qMin(index, d->firstVisible), 0);
|
||||
d->lastVisible = qMax(index, d->lastVisible);
|
||||
d->refresh();
|
||||
if (d->tabList.count() == 1)
|
||||
setCurrentIndex(index);
|
||||
else if (index <= d->currentIndex) {
|
||||
else if (index <= d->currentIndex)
|
||||
++d->currentIndex;
|
||||
|
||||
if (index <= d->lastVisible)
|
||||
++d->lastVisible;
|
||||
}
|
||||
else
|
||||
d->lastVisible = index;
|
||||
|
||||
if (d->closeButtonOnTabs) {
|
||||
QStyleOptionTab opt;
|
||||
|
@ -59,6 +59,7 @@ private slots:
|
||||
void testCurrentChanged();
|
||||
|
||||
void insertAtCurrentIndex();
|
||||
void insertAfterCurrentIndex();
|
||||
|
||||
void removeTab_data();
|
||||
void removeTab();
|
||||
@ -236,6 +237,31 @@ void tst_QTabBar::insertAtCurrentIndex()
|
||||
QCOMPARE(tabBar.currentIndex(), 3);
|
||||
}
|
||||
|
||||
void tst_QTabBar::insertAfterCurrentIndex()
|
||||
{
|
||||
TabBar tabBar;
|
||||
|
||||
tabBar.addTab("Tab10");
|
||||
checkPositions(tabBar, { QStyleOptionTab::OnlyOneTab });
|
||||
|
||||
tabBar.addTab("Tab20");
|
||||
checkPositions(tabBar, { QStyleOptionTab::Beginning, QStyleOptionTab::End });
|
||||
|
||||
tabBar.insertTab(1, "Tab15");
|
||||
checkPositions(tabBar,
|
||||
{ QStyleOptionTab::Beginning, QStyleOptionTab::Middle, QStyleOptionTab::End });
|
||||
|
||||
tabBar.insertTab(3, "Tab30");
|
||||
checkPositions(tabBar,
|
||||
{ QStyleOptionTab::Beginning, QStyleOptionTab::Middle, QStyleOptionTab::Middle,
|
||||
QStyleOptionTab::End });
|
||||
|
||||
tabBar.insertTab(3, "Tab25");
|
||||
checkPositions(tabBar,
|
||||
{ QStyleOptionTab::Beginning, QStyleOptionTab::Middle, QStyleOptionTab::Middle,
|
||||
QStyleOptionTab::Middle, QStyleOptionTab::End });
|
||||
}
|
||||
|
||||
void tst_QTabBar::removeTab_data()
|
||||
{
|
||||
QTest::addColumn<int>("currentIndex");
|
||||
|
Loading…
Reference in New Issue
Block a user