From 1eed3baee9a2668a828731693a110299c8a4aadd Mon Sep 17 00:00:00 2001 From: alex-z Date: Thu, 27 Oct 2022 16:50:30 +0200 Subject: [PATCH] Fix review comments. Signed-off-by: alex-z --- src/gui/tray/usermodel.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index 492231ce87c41..0f1c6e1a974c2 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -1034,14 +1034,10 @@ void UserModel::setCurrentUserId(const int id) } return; } - _currentUserId = id; - if (_users.isEmpty()) { - emit currentUserChanged(); - return; - } + _currentUserId = id; - if (id >= 0 && id < _users.size()) { + if (!_users.isEmpty() && id >= 0 && id < _users.size()) { for (auto &user : _users) { user->setCurrentUser(false); } @@ -1093,16 +1089,11 @@ void UserModel::removeAccount(const int id) _users.removeAt(id); endRemoveRows(); - if (_users.isEmpty()) { - setCurrentUserId(-1); - } else if (_users.size() == 1) { - setCurrentUserId(0); - } else { - if (currentUserId() != id && currentUserId() < id) { - return; - } - setCurrentUserId(id < _users.size() ? id : id - 1); - } + if (_users.size() <= 1) { + setCurrentUserId(_users.size() - 1); + } else if (currentUserId() == id || currentUserId() >= id) { + setCurrentUserId(id < _users.size() ? id : id - 1); + } } std::shared_ptr UserModel::userStatusConnector(int id)