QTabWidget: fix moving of the current tab
Task-number: QTBUG-36455 Change-Id: I38687283d60fe38a4b586b064d5ddd4ed3be06b6 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: Ivan Komissarov <ABBAPOH@me.com>
This commit is contained in:
parent
2c1e77506c
commit
65bd80ebfc
@ -1681,6 +1681,7 @@ void QTabBar::moveTab(int from, int to)
|
||||
d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab);
|
||||
|
||||
// update external variables
|
||||
int previousIndex = d->currentIndex;
|
||||
d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);
|
||||
|
||||
// If we are in the middle of a drag update the dragStartPosition
|
||||
@ -1699,6 +1700,8 @@ void QTabBar::moveTab(int from, int to)
|
||||
d->layoutWidgets(start);
|
||||
update();
|
||||
emit tabMoved(from, to);
|
||||
if (previousIndex != d->currentIndex)
|
||||
emit currentChanged(d->currentIndex);
|
||||
emit tabLayoutChange();
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,7 @@ class tst_QTabWidget:public QObject {
|
||||
void heightForWidth_data();
|
||||
void heightForWidth();
|
||||
void tabBarClicked();
|
||||
void moveCurrentTab();
|
||||
|
||||
private:
|
||||
int addPage();
|
||||
@ -709,5 +710,27 @@ void tst_QTabWidget::tabBarClicked()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTabWidget::moveCurrentTab()
|
||||
{
|
||||
QTabWidget tabWidget;
|
||||
QWidget* firstTab = new QWidget(&tabWidget);
|
||||
QWidget* secondTab = new QWidget(&tabWidget);
|
||||
tabWidget.addTab(firstTab, "0");
|
||||
tabWidget.addTab(secondTab, "1");
|
||||
|
||||
QCOMPARE(tabWidget.currentIndex(), 0);
|
||||
QCOMPARE(tabWidget.currentWidget(), firstTab);
|
||||
|
||||
tabWidget.setCurrentIndex(1);
|
||||
|
||||
QCOMPARE(tabWidget.currentIndex(), 1);
|
||||
QCOMPARE(tabWidget.currentWidget(), secondTab);
|
||||
|
||||
tabWidget.tabBar()->moveTab(1, 0);
|
||||
|
||||
QCOMPARE(tabWidget.currentIndex(), 0);
|
||||
QCOMPARE(tabWidget.currentWidget(), secondTab);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTabWidget)
|
||||
#include "tst_qtabwidget.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user