qtquick: Fix current tab being current even after removed
Added lots of tests for TabBar.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user