From a4e6d4cd3548217fd6a843d0b47dbbb1c12e9c15 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Feb 2019 05:38:53 -0500 Subject: [PATCH 1/3] [partition] Rename combo box - Too much confusion possible between the different members all named variations of *SwapChoice* - Update copyright years, too --- src/modules/partition/gui/ChoicePage.cpp | 16 ++++++++-------- src/modules/partition/gui/ChoicePage.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 10ffbcee3..f62af013f 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2017, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * 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 ) @@ -270,8 +270,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_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox ); } m_itemsLayout->addWidget( m_alongsideButton ); @@ -316,14 +316,14 @@ ChoicePage::setupChoices() connect( this, &ChoicePage::actionChosen, this, &ChoicePage::onActionChanged ); - if ( m_eraseSwapChoices ) - connect( m_eraseSwapChoices, QOverload::of(&QComboBox::currentIndexChanged), + if ( m_eraseSwapChoiceComboBox ) + connect( m_eraseSwapChoiceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &ChoicePage::onActionChanged ); CALAMARES_RETRANSLATE( m_somethingElseButton->setText( tr( "Manual partitioning
" "You can create or resize partitions yourself." ) ); - updateSwapChoicesTr( m_eraseSwapChoices ); + updateSwapChoicesTr( m_eraseSwapChoiceComboBox ); ) } @@ -448,7 +448,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) m_encryptWidget->passphrase(), gs->value( "efiSystemPartition" ).toString(), CalamaresUtils::GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() ), - static_cast( m_eraseSwapChoices->currentData().toInt() ) + static_cast( m_eraseSwapChoiceComboBox->currentData().toInt() ) }; if ( m_core->isDirty() ) diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 0d25c61ee..527a59e1a 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify @@ -155,7 +155,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; From 5f20eedb6e0f11731848f4252d778cacebfd4459 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Feb 2019 07:21:35 -0500 Subject: [PATCH 2/3] [partition] Use swap-choice member, not the combobox pointer - Store changes to the selected swap-choice when the combobox changes - Use that member instead of dereferencing the combobox This avoids nullptr crashes when the combobox isn't even created (e.g. when there is only one swap choice). --- src/modules/partition/gui/ChoicePage.cpp | 13 +++++++++++-- src/modules/partition/gui/ChoicePage.h | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index f62af013f..ee7905c33 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -318,7 +318,7 @@ ChoicePage::setupChoices() this, &ChoicePage::onActionChanged ); if ( m_eraseSwapChoiceComboBox ) connect( m_eraseSwapChoiceComboBox, QOverload::of(&QComboBox::currentIndexChanged), - this, &ChoicePage::onActionChanged ); + this, &ChoicePage::onEraseSwapChoiceChanged ); CALAMARES_RETRANSLATE( m_somethingElseButton->setText( tr( "Manual partitioning
" @@ -428,6 +428,15 @@ ChoicePage::onActionChanged() } } +void +ChoicePage::onEraseSwapChoiceChanged() +{ + if ( m_eraseSwapChoiceComboBox ) + { + m_eraseSwapChoice = static_cast( m_eraseSwapChoiceComboBox->currentData().toInt() ); + onActionChanged(); + } +} void ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) @@ -448,7 +457,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) m_encryptWidget->passphrase(), gs->value( "efiSystemPartition" ).toString(), CalamaresUtils::GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() ), - static_cast( m_eraseSwapChoiceComboBox->currentData().toInt() ) + m_eraseSwapChoice }; if ( m_core->isDirty() ) diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 527a59e1a..baf575d49 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -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(); From 2a8960cd0ff5f7b4472935cd5601bc193baa2a3b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Feb 2019 07:30:34 -0500 Subject: [PATCH 3/3] [partition] Ensure combobox pre-selects consistently - Match the selected item in the combobox with a given default, which should be whatever is selected from the available set of choices. --- src/modules/partition/gui/ChoicePage.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index ee7905c33..7c980cf49 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -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,7 +276,7 @@ ChoicePage::setupChoices() // .. TODO: only if enabled in the config if ( m_availableSwapChoices.count() > 1 ) { - m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices ); + m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices, m_eraseSwapChoice ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox ); }