diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-02-04 14:47:39 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-05 23:04:04 +0100 |
commit | 65bd80ebfc1be81a196a861ade40ff874a3554f0 (patch) | |
tree | 1585c1d738c6e5c1676d4967aa17ff5fb7153991 | |
parent | 2c1e77506ccd22f9d9be4f79875539a630f4f576 (diff) |
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>
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 3 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index dfd1f1022c..b47d65f561 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -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(); } diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp index fa518e6afd..e6fe5f92c7 100644 --- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp +++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp @@ -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" |