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);
|
d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab);
|
||||||
|
|
||||||
// update external variables
|
// update external variables
|
||||||
|
int previousIndex = d->currentIndex;
|
||||||
d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);
|
d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);
|
||||||
|
|
||||||
// If we are in the middle of a drag update the dragStartPosition
|
// 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);
|
d->layoutWidgets(start);
|
||||||
update();
|
update();
|
||||||
emit tabMoved(from, to);
|
emit tabMoved(from, to);
|
||||||
|
if (previousIndex != d->currentIndex)
|
||||||
|
emit currentChanged(d->currentIndex);
|
||||||
emit tabLayoutChange();
|
emit tabLayoutChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ class tst_QTabWidget:public QObject {
|
|||||||
void heightForWidth_data();
|
void heightForWidth_data();
|
||||||
void heightForWidth();
|
void heightForWidth();
|
||||||
void tabBarClicked();
|
void tabBarClicked();
|
||||||
|
void moveCurrentTab();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int addPage();
|
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)
|
QTEST_MAIN(tst_QTabWidget)
|
||||||
#include "tst_qtabwidget.moc"
|
#include "tst_qtabwidget.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user