From 28d91979c3e0c31680eb03314d7b6b7d207f61bd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jan 2020 13:50:23 +0100 Subject: [PATCH] [welcome] Make resultWidgets less error-prone - instead of counting and needing to keep track of the predicate applied while creating the widgets, push nullptrs to the widget list instead reflecting "this entry did not satisfy the predicate for widget creation". --- .../welcome/checker/ResultsListWidget.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/modules/welcome/checker/ResultsListWidget.cpp b/src/modules/welcome/checker/ResultsListWidget.cpp index db28d079b..f8fe5d1a6 100644 --- a/src/modules/welcome/checker/ResultsListWidget.cpp +++ b/src/modules/welcome/checker/ResultsListWidget.cpp @@ -34,16 +34,29 @@ #include #include +/** @brief Add widgets to @p layout for the list @p checkEntries + * + * The @p resultWidgets is filled with pointers to the widgets; + * for each entry in @p checkEntries that satisfies @p predicate, + * a widget is created, otherwise a nullptr is added instead. + * + * Adds all the widgets to the given @p layout. + * + * Afterwards, @p resultWidgets has a length equal to @p checkEntries. + */ static void createResultWidgets( QLayout* layout, QList< ResultWidget* >& resultWidgets, const Calamares::RequirementsList& checkEntries, std::function< bool( const Calamares::RequirementEntry& ) > predicate ) { + resultWidgets.clear(); + resultWidgets.reserve( checkEntries.count() ); for ( const auto& entry : checkEntries ) { if ( !predicate( entry ) ) { + resultWidgets.append( nullptr ); continue; } @@ -127,11 +140,10 @@ ResultsListDialog::retranslate() int i = 0; for ( const auto& entry : m_entries ) { - if ( !entry.hasDetails() ) + if ( m_resultWidgets[ i ] ) { - continue; + m_resultWidgets[ i ]->setText( entry.enumerationText() ); } - m_resultWidgets[ i ]->setText( entry.enumerationText() ); i++; } } @@ -241,7 +253,7 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem { mainLayout->addStretch(); } - + CALAMARES_RETRANSLATE_SLOT( &ResultsListWidget::retranslate ) retranslate(); } @@ -264,11 +276,10 @@ ResultsListWidget::retranslate() int i = 0; for ( const auto& entry : m_entries ) { - if ( entry.satisfied ) + if ( m_resultWidgets[ i ] ) { - continue; + m_resultWidgets[ i ]->setText( entry.negatedText() ); } - m_resultWidgets[ i ]->setText( entry.negatedText() ); i++; } }