[welcome] Hoist checking for requirements-satisfied

- lift it out of the loop that creates the widgets
 - some lambda-wankery, but the compiler hammers this down to
   simple loops and you can read the resulting code as

	none_of  [the list]  isUnSatisfied
	none_of  [the list]  isMandatoryAndUnSatisfied
This commit is contained in:
Adriaan de Groot 2020-01-28 13:07:57 +01:00
parent f5c0e57f17
commit ecc7719abd

View File

@ -157,8 +157,12 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem
spacerLayout->addSpacing( paddingSize ); spacerLayout->addSpacing( paddingSize );
CalamaresUtils::unmarginLayout( spacerLayout ); CalamaresUtils::unmarginLayout( spacerLayout );
bool requirementsSatisfied = true; // Give a warning // Check that all are satisfied (gives warnings if not) and
bool mandatorySatisfied = true; // Give an error // all *mandatory* entries are satisfied (gives errors if not).
auto isUnSatisfied = [](const Calamares::RequirementEntry& e){ return !e.satisfied; };
auto isMandatoryAndUnSatisfied = [](const Calamares::RequirementEntry& e){ return e.mandatory && !e.satisfied; };
const bool requirementsSatisfied = std::none_of(checkEntries.begin(), checkEntries.end(), isUnSatisfied);
const bool mandatorySatisfied = std::none_of(checkEntries.begin(), checkEntries.end(), isMandatoryAndUnSatisfied);
for ( const auto& entry : checkEntries ) for ( const auto& entry : checkEntries )
{ {
@ -168,13 +172,6 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem
CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); ) CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); )
entriesLayout->addWidget( ciw ); entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
requirementsSatisfied = false;
if ( entry.mandatory )
{
mandatorySatisfied = false;
}
ciw->setAutoFillBackground( true ); ciw->setAutoFillBackground( true );
QPalette pal( ciw->palette() ); QPalette pal( ciw->palette() );
QColor bgColor = pal.window().color(); QColor bgColor = pal.window().color();