bool DietWizardDialog::checkLimits( IngredientPropertyList &properties, ConstraintList &constraints ) { for ( ConstraintList::const_iterator ct_it = constraints.constBegin(); ct_it != constraints.constEnd(); ++ct_it ) { if ( (*ct_it).enabled ) { IngredientPropertyList::iterator ip_it = properties.find( (*ct_it).id ); if ( ip_it != properties.end() ) { if ( ( (*ip_it).amount > (*ct_it).max ) || ( (*ip_it).amount < (*ct_it).min ) ) return false; } else return false; } } return true; }
int DietWizardDialog::getNecessaryFlags() const { bool need_ingredients = false; bool need_categories = false; for ( int meal = 0;meal < mealNumber;meal++ ) { int dishNo = ( ( MealInput* ) ( mealTabs->widget( meal ) ) ) ->dishNo(); for ( int dish = 0;dish < dishNo;dish++ ) { if ( !need_categories ) { if ( categoryFiltering( meal, dish ) ) { need_categories = true; } } if ( !need_ingredients ) { ConstraintList constraints; loadConstraints( meal, dish, &constraints ); for ( ConstraintList::const_iterator ct_it = constraints.constBegin(); ct_it != constraints.constEnd(); ++ct_it ) { if ( (*ct_it).enabled ) { need_ingredients = true; break; } } } if ( need_ingredients && need_categories ) break; } if ( need_ingredients && need_categories ) break; } kDebug()<<"Do we need to load ingredients: "<<need_ingredients; kDebug()<<"Do we need to load categories: "<<need_categories; int flags = 0; if ( need_ingredients ) flags |= RecipeDB::Ingredients; if ( need_categories ) flags |= RecipeDB::Categories; return flags; }
bool DietWizardDialog::checkConstraints( Recipe &rec, int meal, int dish ) { // Check if the properties are within the constraints ConstraintList constraints; loadConstraints( meal, dish, &constraints ); //load the constraints bool any_enabled = false; for ( ConstraintList::const_iterator ct_it = constraints.constBegin(); ct_it != constraints.constEnd(); ++ct_it ) { if ( (*ct_it).enabled ) { any_enabled = true; break; } } if ( !any_enabled ) return true; // Calculate properties of the recipe calculateProperties( rec, database ); bool withinLimits = checkLimits( rec.properties, constraints ); return ( withinLimits ); }