From 391b52427a27035f1a97197c4473ce8bd95c4a75 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 30 Oct 2015 17:32:00 +0100 Subject: [PATCH] Properly handle the edge case of a PCM::revert and null deviceModel. --- src/modules/partition/gui/ChoicePage.cpp | 28 ++++++++++++++++++++++++ src/modules/partition/gui/ChoicePage.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 9e3837340..fffe9f3fb 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -62,6 +62,7 @@ ChoicePage::ChoicePage( bool compactMode, QWidget* parent ) , m_eraseButton( nullptr ) , m_replaceButton( nullptr ) , m_somethingElseButton( nullptr ) + , m_lastSelectedDeviceIndex( -1 ) { setupUi( this ); if ( m_compactMode ) @@ -129,13 +130,29 @@ ChoicePage::init( PartitionCoreModule* core, if ( compact() ) { + // We need to do this because a PCM revert invalidates the deviceModel. + connect( core, &PartitionCoreModule::reverted, + this, [=] + { + drivesCombo->setModel( core->deviceModel() ); + drivesCombo->setCurrentIndex( m_lastSelectedDeviceIndex ); + } ); drivesCombo->setModel( core->deviceModel() ); + connect( drivesCombo, static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), this, &ChoicePage::applyDeviceChoice ); } else { + // Same as above. + connect( core, &PartitionCoreModule::reverted, + this, [=] + { + drivesList->setModel( core->deviceModel() ); + drivesList->selectionModel()->setCurrentIndex( + core->deviceModel()->index( m_lastSelectedDeviceIndex ), QItemSelectionModel::ClearAndSelect ); + } ); drivesList->setModel( core->deviceModel() ); connect( drivesList->selectionModel(), &QItemSelectionModel::currentChanged, @@ -335,10 +352,21 @@ ChoicePage::applyDeviceChoice() { Device* currd = selectedDevice(); + // The device should only be nullptr immediately after a PCM reset. + // applyDeviceChoice() will be called again momentarily as soon as we handle the + // PartitionCoreModule::reverted signal. + if ( !currd ) + return; + updateDeviceStatePreview( currd ); // Preview setup done. Now we show/hide choices as needed. setupActions( currd ); + + if ( compact() ) + m_lastSelectedDeviceIndex = drivesCombo->currentIndex(); + else + m_lastSelectedDeviceIndex = drivesList->selectionModel()->currentIndex().row(); } diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 37e7c17d2..44c565b19 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -88,6 +88,8 @@ private: PrettyRadioButton* m_eraseButton; PrettyRadioButton* m_replaceButton; PrettyRadioButton* m_somethingElseButton; + + int m_lastSelectedDeviceIndex; }; #endif // CHOICEPAGE_H