Properly handle the edge case of a PCM::revert and null deviceModel.
This commit is contained in:
parent
9b2f04daf6
commit
391b52427a
@ -62,6 +62,7 @@ ChoicePage::ChoicePage( bool compactMode, QWidget* parent )
|
|||||||
, m_eraseButton( nullptr )
|
, m_eraseButton( nullptr )
|
||||||
, m_replaceButton( nullptr )
|
, m_replaceButton( nullptr )
|
||||||
, m_somethingElseButton( nullptr )
|
, m_somethingElseButton( nullptr )
|
||||||
|
, m_lastSelectedDeviceIndex( -1 )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
if ( m_compactMode )
|
if ( m_compactMode )
|
||||||
@ -129,13 +130,29 @@ ChoicePage::init( PartitionCoreModule* core,
|
|||||||
|
|
||||||
if ( compact() )
|
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() );
|
drivesCombo->setModel( core->deviceModel() );
|
||||||
|
|
||||||
connect( drivesCombo,
|
connect( drivesCombo,
|
||||||
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
||||||
this, &ChoicePage::applyDeviceChoice );
|
this, &ChoicePage::applyDeviceChoice );
|
||||||
}
|
}
|
||||||
else
|
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() );
|
drivesList->setModel( core->deviceModel() );
|
||||||
connect( drivesList->selectionModel(),
|
connect( drivesList->selectionModel(),
|
||||||
&QItemSelectionModel::currentChanged,
|
&QItemSelectionModel::currentChanged,
|
||||||
@ -335,10 +352,21 @@ ChoicePage::applyDeviceChoice()
|
|||||||
{
|
{
|
||||||
Device* currd = selectedDevice();
|
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 );
|
updateDeviceStatePreview( currd );
|
||||||
// Preview setup done. Now we show/hide choices as needed.
|
// Preview setup done. Now we show/hide choices as needed.
|
||||||
|
|
||||||
setupActions( currd );
|
setupActions( currd );
|
||||||
|
|
||||||
|
if ( compact() )
|
||||||
|
m_lastSelectedDeviceIndex = drivesCombo->currentIndex();
|
||||||
|
else
|
||||||
|
m_lastSelectedDeviceIndex = drivesList->selectionModel()->currentIndex().row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,6 +88,8 @@ private:
|
|||||||
PrettyRadioButton* m_eraseButton;
|
PrettyRadioButton* m_eraseButton;
|
||||||
PrettyRadioButton* m_replaceButton;
|
PrettyRadioButton* m_replaceButton;
|
||||||
PrettyRadioButton* m_somethingElseButton;
|
PrettyRadioButton* m_somethingElseButton;
|
||||||
|
|
||||||
|
int m_lastSelectedDeviceIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHOICEPAGE_H
|
#endif // CHOICEPAGE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user