From 4973d00aceea35cc6a676386298fc94278e54e86 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Dec 2018 13:52:23 +0100 Subject: [PATCH] [partition] Only create drop-down if there is something to select - Swap choices may be 0 (then choose none), 1 (choose that one) or more (currently undecided) --- src/modules/partition/gui/ChoicePage.cpp | 18 +++++++++++++++--- src/modules/partition/gui/ChoicePage.h | 7 ++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 8c22dac29..1321e0d5c 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -65,6 +65,14 @@ using PartitionActions::Choices::SwapChoice; +SwapChoice pickOne( const SwapChoiceSet& s ) +{ + if ( s.count() == 1 ) + for ( auto i = s.begin(); i != s.end(); ++i ) + return *i; // That's the only element + return SwapChoice::NoSwap; +} + /** * @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of * the module loading code path. @@ -90,7 +98,8 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) , m_bootloaderComboBox( nullptr ) , m_lastSelectedDeviceIndex( -1 ) , m_enableEncryptionWidget( true ) - , m_swapChoices( swapChoices ) + , m_availableSwapChoices( swapChoices ) + , m_eraseSwapChoice( pickOne( swapChoices ) ) { setupUi( this ); @@ -258,8 +267,11 @@ ChoicePage::setupChoices() // Fill up swap options // .. TODO: only if enabled in the config - m_eraseSwapChoices = createCombo( m_swapChoices ); - m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); + if ( m_availableSwapChoices.count() > 1 ) + { + m_eraseSwapChoices = createCombo( m_availableSwapChoices ); + m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); + } m_itemsLayout->addWidget( m_alongsideButton ); m_itemsLayout->addWidget( m_replaceButton ); diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index f4cb5fce5..762903987 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -45,7 +45,7 @@ class DeviceInfoWidget; class Device; -using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice>; +using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice >; /** * @brief The ChoicePage class is the first page of the partitioning interface. @@ -151,7 +151,7 @@ private: PrettyRadioButton* m_eraseButton; PrettyRadioButton* m_replaceButton; PrettyRadioButton* m_somethingElseButton; - QComboBox* m_eraseSwapChoices; + QComboBox* m_eraseSwapChoices; // UI, see also m_swapChoices DeviceInfoWidget* m_deviceInfoWidget; @@ -168,7 +168,8 @@ private: QString m_defaultFsType; bool m_enableEncryptionWidget; - SwapChoiceSet m_swapChoices; + SwapChoiceSet m_availableSwapChoices; // What is available + PartitionActions::Choices::SwapChoice m_eraseSwapChoice; // what is selected QMutex m_coreMutex; };