From 17aeaa134a2e4490387d913c58d7eb19e95dc0df Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 10:54:04 -0400 Subject: [PATCH 1/5] [partition] Simplify display-role code for bootloader --- src/modules/partition/core/BootLoaderModel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index e10a7c930..0598a4f31 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -119,12 +119,12 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const { if ( role == Qt::DisplayRole ) { - if ( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString().isEmpty() ) - return QStandardItemModel::data( index, Qt::DisplayRole ).toString(); + QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString(); + QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString(); + if ( pathRole.isEmpty() ) + return displayRole; - return tr( "%1 (%2)" ) - .arg( QStandardItemModel::data( index, Qt::DisplayRole ).toString() ) - .arg( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString() ); + return tr( "%1 (%2)" ).arg( displayRole, pathRole ); } return QStandardItemModel::data( index, role ); } From dc04aa999de08bdb302b60ac5603128620ab98fc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 11:33:40 -0400 Subject: [PATCH 2/5] [partition] Introduce post-reset slot for boot loader selection --- src/modules/partition/gui/PartitionPage.cpp | 7 +++++++ src/modules/partition/gui/PartitionPage.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index ba6845020..43db4aa3d 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -79,6 +79,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) value( "alwaysShowPartitionLabels" ).toBool() ); m_ui->deviceComboBox->setModel( m_core->deviceModel() ); m_ui->bootLoaderComboBox->setModel( m_core->bootLoaderModel() ); + connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, this, &PartitionPage::restoreSelectedBootLoader ); PartitionBarsView::NestedPartitionsMode mode = Calamares::JobQueue::instance()->globalStorage()-> value( "drawNestedPartitions" ).toBool() ? PartitionBarsView::DrawNestedPartitions : @@ -505,6 +506,12 @@ PartitionPage::updateSelectedBootLoaderIndex() cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex; } +void +PartitionPage::restoreSelectedBootLoader() +{ +} + + void PartitionPage::updateFromCurrentDevice() { diff --git a/src/modules/partition/gui/PartitionPage.h b/src/modules/partition/gui/PartitionPage.h index 75d39c9dc..9999c334d 100644 --- a/src/modules/partition/gui/PartitionPage.h +++ b/src/modules/partition/gui/PartitionPage.h @@ -57,6 +57,8 @@ private slots: void updateBootLoaderInstallPath(); /// @brief Explicitly selected boot loader path void updateSelectedBootLoaderIndex(); + /// @brief After boot loader model changes, try to preserve previously set value + void restoreSelectedBootLoader(); private: QScopedPointer< Ui_PartitionPage > m_ui; From 3eae445eadb3218d4af307e54287d68365783682 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 11:37:26 -0400 Subject: [PATCH 3/5] [partition] Don't signal changes from model before they're done - clear() signals modelReset(), which is true, but inconvenient when we do a bunch of changes afterwards. Block signals, and rely on own signaling when all of the changes are done. - Keep blocking signals while updating the model, since the row appends otherwise trigger a change in the connected combo box. --- src/modules/partition/core/BootLoaderModel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index 0598a4f31..f0661d8b0 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -67,6 +67,8 @@ BootLoaderModel::createMbrItems() void BootLoaderModel::update() { + beginResetModel(); + blockSignals( true ); clear(); createMbrItems(); @@ -111,6 +113,8 @@ BootLoaderModel::update() createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) ); } + blockSignals( false ); + endResetModel(); } From 273c32705d9e035bbbafc054c2a8735f3d6dbf4f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 11:52:29 -0400 Subject: [PATCH 4/5] [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 ); + } } From 97eda698fccdd619757cb2d0076a563fcc7d28f5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Mar 2019 12:06:10 -0400 Subject: [PATCH 5/5] Changes: document fixed behavior --- CHANGES | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index f70fb5a44..00184df4d 100644 --- a/CHANGES +++ b/CHANGES @@ -31,8 +31,10 @@ This release contains contributions from (alphabetically by first name): display-managers. * *Partition* module: it is now possible to build without libparted. Since KPMCore may not need this library anymore, it is a dependency that will - be dropped as soon as it is feasible. Add `-DCMAKE_DISABLE_FIND_PACKAGE_LIBPARTED=ON` - to the CMake flags to do so. + be dropped as soon as it is feasible. Add this to the CMake flags: + `-DCMAKE_DISABLE_FIND_PACKAGE_LIBPARTED=ON` + * *Partition* module: the location that is selected for the bootloader, + no longer changes when a new partition is created. #1098 * Python modules: several modules have had translations added. This is usually only visible when the module runs as part of the *exec* step, when the module's *pretty name* is displayed. In addition, some error