qtquick: Fix current tab being current even after removed

Added lots of tests for TabBar.
This commit is contained in:
Sergio Martins
2022-08-14 15:44:38 +01:00
parent d071fc440a
commit 4627571f3f
2 changed files with 95 additions and 0 deletions

View File

@@ -157,6 +157,8 @@ void DockWidgetModel::remove(Controllers::DockWidget *dw)
{
QScopedValueRollback<bool> guard(m_removeGuard, true);
const int row = indexOf(dw);
const bool wasCurrent = dw == m_currentDockWidget;
if (row == -1) {
if (!m_removeGuard) {
// can happen if there's reentrancy. Some user code reacting
@@ -170,6 +172,13 @@ void DockWidgetModel::remove(Controllers::DockWidget *dw)
for (const QMetaObject::Connection &conn : connections)
disconnect(conn);
if (wasCurrent) {
const bool isLast = row == count() - 1;
const int newCurrentIndex = isLast ? row - 1 : row + 1;
if (newCurrentIndex >= 0)
setCurrentIndex(newCurrentIndex);
}
beginRemoveRows(QModelIndex(), row, row);
m_dockWidgets.removeOne(dw);
endRemoveRows();