From 273c32705d9e035bbbafc054c2a8735f3d6dbf4f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 11:52:29 -0400 Subject: [PATCH] [partition] Restore selected bootloader - After the BootLoader model is reset, if a bootloader location has been selected before, try to find it in the (now-reset) model to preserve the selection. --- src/modules/partition/gui/PartitionPage.cpp | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 43db4aa3d..5f16e9dc1 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -506,9 +506,44 @@ PartitionPage::updateSelectedBootLoaderIndex() cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex; } +int +findBootloader( const QAbstractItemModel* model, const QString& path ) +{ + for ( int i = 0; i < model->rowCount(); ++i) + { + const auto index = model->index( i, 0, QModelIndex() ); + cDebug() << i << model->itemData( index ); + QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); + if ( var.isValid() && var.toString() == path ) + return i; + } + + return -1; +} + void PartitionPage::restoreSelectedBootLoader() { + const auto* model = m_ui->bootLoaderComboBox->model(); + if ( model->rowCount() < 1 ) + { + cDebug() << "No items in BootLoaderModel"; + return; + } + + int r = -1; + if ( m_core->bootLoaderInstallPath().isEmpty() ) + { + m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); + } + else if ( (r = findBootloader( model, m_core->bootLoaderInstallPath() )) >= 0 ) + { + m_ui->bootLoaderComboBox->setCurrentIndex( r ); + } + else + { + m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); + } }