Fix current index in main menu after a setup is aborted

This commit is contained in:
Michael Zanetti 2021-08-10 23:43:31 +02:00
parent f813685ab6
commit 9e62540f0f

View File

@ -17,8 +17,8 @@ ConfiguredHostsModel::ConfiguredHostsModel(QObject *parent) : QAbstractListModel
host->setName(cachedName); host->setName(cachedName);
addHost(host); addHost(host);
settings.endGroup(); settings.endGroup();
m_currentIndex = settings.value("currentIndex", 0).toInt();
} }
m_currentIndex = settings.value("currentIndex", 0).toInt();
settings.endGroup(); settings.endGroup();
// If there aren't any in the config, try migrating settings from old tab model // If there aren't any in the config, try migrating settings from old tab model
@ -42,6 +42,11 @@ ConfiguredHostsModel::ConfiguredHostsModel(QObject *parent) : QAbstractListModel
if (m_list.isEmpty()) { if (m_list.isEmpty()) {
createHost(); createHost();
} }
// Make sure the currentIndex from the config isn't out of place
if (m_currentIndex >= m_list.count()) {
m_currentIndex = m_list.count()-1;
}
} }
int ConfiguredHostsModel::rowCount(const QModelIndex &parent) const int ConfiguredHostsModel::rowCount(const QModelIndex &parent) const