Merge branch 'fix-swap-choice-nullptr'

FIXES #1084
This commit is contained in:
Adriaan de Groot 2019-02-12 07:31:52 -05:00
commit cf39d312fe
2 changed files with 30 additions and 13 deletions

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
* Copyright 2019, Collabora Ltd
*
* Calamares is free software: you can redistribute it and/or modify
@ -100,7 +100,7 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent )
, m_eraseButton( nullptr )
, m_replaceButton( nullptr )
, m_somethingElseButton( nullptr )
, m_eraseSwapChoices( nullptr )
, m_eraseSwapChoiceComboBox( nullptr )
, m_deviceInfoWidget( nullptr )
, m_beforePartitionBarsView( nullptr )
, m_beforePartitionLabelsView( nullptr )
@ -201,15 +201,21 @@ ChoicePage::init( PartitionCoreModule* core )
/** @brief Creates a combobox with the given choices in it.
*
* Pre-selects the choice given by @p dflt.
* No texts are set -- that happens later by the translator functions.
*/
static inline QComboBox*
createCombo( const QSet< SwapChoice >& s )
createCombo( const QSet< SwapChoice >& s, SwapChoice dflt )
{
QComboBox* box = new QComboBox;
for ( SwapChoice c : { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap, SwapChoice::ReuseSwap, SwapChoice::SwapFile } )
if ( s.contains( c ) )
box->addItem( QString(), c );
int dfltIndex = box->findData( dflt );
if ( dfltIndex >= 0 )
box->setCurrentIndex( dfltIndex );
return box;
}
@ -270,8 +276,8 @@ ChoicePage::setupChoices()
// .. TODO: only if enabled in the config
if ( m_availableSwapChoices.count() > 1 )
{
m_eraseSwapChoices = createCombo( m_availableSwapChoices );
m_eraseButton->addOptionsComboBox( m_eraseSwapChoices );
m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices, m_eraseSwapChoice );
m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox );
}
m_itemsLayout->addWidget( m_alongsideButton );
@ -316,14 +322,14 @@ ChoicePage::setupChoices()
connect( this, &ChoicePage::actionChosen,
this, &ChoicePage::onActionChanged );
if ( m_eraseSwapChoices )
connect( m_eraseSwapChoices, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &ChoicePage::onActionChanged );
if ( m_eraseSwapChoiceComboBox )
connect( m_eraseSwapChoiceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &ChoicePage::onEraseSwapChoiceChanged );
CALAMARES_RETRANSLATE(
m_somethingElseButton->setText( tr( "<strong>Manual partitioning</strong><br/>"
"You can create or resize partitions yourself." ) );
updateSwapChoicesTr( m_eraseSwapChoices );
updateSwapChoicesTr( m_eraseSwapChoiceComboBox );
)
}
@ -428,6 +434,15 @@ ChoicePage::onActionChanged()
}
}
void
ChoicePage::onEraseSwapChoiceChanged()
{
if ( m_eraseSwapChoiceComboBox )
{
m_eraseSwapChoice = static_cast<PartitionActions::Choices::SwapChoice>( m_eraseSwapChoiceComboBox->currentData().toInt() );
onActionChanged();
}
}
void
ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
@ -448,7 +463,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
m_encryptWidget->passphrase(),
gs->value( "efiSystemPartition" ).toString(),
CalamaresUtils::GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() ),
static_cast<PartitionActions::Choices::SwapChoice>( m_eraseSwapChoices->currentData().toInt() )
m_eraseSwapChoice
};
if ( m_core->isDirty() )

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot@kde.org>
* Copyright 2018-2019, Adriaan de Groot <groot@kde.org>
* Copyright 2019, Collabora Ltd
*
* Calamares is free software: you can redistribute it and/or modify
@ -116,8 +116,10 @@ private slots:
void onEncryptWidgetStateChanged();
void onHomeCheckBoxStateChanged();
/** @brief Calls applyActionChoice() as needed. */
/// @brief Calls applyActionChoice() as needed.
void onActionChanged();
/// @brief Calls onActionChanged() as needed.
void onEraseSwapChoiceChanged();
private:
void updateNextEnabled();
@ -155,7 +157,7 @@ private:
PrettyRadioButton* m_eraseButton;
PrettyRadioButton* m_replaceButton;
PrettyRadioButton* m_somethingElseButton;
QComboBox* m_eraseSwapChoices; // UI, see also m_swapChoices
QComboBox* m_eraseSwapChoiceComboBox; // UI, see also m_eraseSwapChoice
DeviceInfoWidget* m_deviceInfoWidget;