Example #1
0
void DietWizardDialog::createDiet( void )
{
	KApplication::setOverrideCursor( Qt::WaitCursor );

	START_TIMER("Creating the diet");

	RecipeList rlist;
	dietRList->clear();

	// Get the whole list of recipes, detailed
	int flags = RecipeDB::Title | getNecessaryFlags();
	database->loadRecipes( &rlist, flags );

	// temporal iterator list so elements can be removed without reloading them again from the DB
	// this list prevents the same meal from showing up in the same day twice
	Q3ValueList <RecipeList::Iterator> tempRList;

	bool alert = false;

	for ( int day = 0;day < dayNumber;day++ )  // Create the diet for the number of days defined by the user
	{
		populateIteratorList( rlist, &tempRList ); // temporal iterator list so elements can be removed without reloading them again from the DB
		for ( int meal = 0;meal < mealNumber;meal++ )
		{
			int dishNo = ( ( MealInput* ) ( mealTabs->widget( meal ) ) ) ->dishNo();

			for ( int dish = 0;dish < dishNo;dish++ ) {
				bool found = false;
				Q3ValueList <RecipeList::Iterator> tempDishRList = tempRList;
				while ( ( !found ) && !tempDishRList.empty() ) {
					int random_index = ( int ) ( ( float ) ( KRandom::random() ) / ( float ) RAND_MAX * tempDishRList.count() );
					Q3ValueList<RecipeList::Iterator>::Iterator iit = tempDishRList.at( random_index ); // note that at() retrieves an iterator to the iterator list, so we need to use * in order to get the RecipeList::Iterator

					RecipeList::Iterator rit = *iit;
					if ( found = ( ( ( !categoryFiltering( meal, dish ) ) || checkCategories( *rit, meal, dish ) ) && checkConstraints( *rit, meal, dish ) ) )  // Check that the recipe is inside the constraint limits and in the categories specified
					{
						dietRList->append( *rit ); // Add recipe to the diet list
						tempRList.remove( tempRList.find(*iit) ); //can't just remove()... the iterator isn't from this list (its an iterator from tempDishRList)
					}
					else {
						tempDishRList.remove( iit ); // Remove this analized recipe from teh list
					}
				}
				if ( !found )
					alert = true;
			}
		}
	}

	if ( alert ) {
		KApplication::restoreOverrideCursor();
		KMessageBox::sorry( this, i18nc( "@info", "Given the constraints, a full diet list could not be constructed. Either the recipe list is too short or the constraints are too demanding. " ) );
	}

	else // show the resulting diet
	{

		// make a list of dishnumbers
		QList<int> dishNumbers;

		for ( int meal = 0;meal < mealNumber;meal++ ) {
			int dishNo = ( ( MealInput* ) ( mealTabs->widget( meal ) ) ) ->dishNo();
			dishNumbers << dishNo;
		}

		KApplication::restoreOverrideCursor();

		// display the list
		QPointer<DietViewDialog> dietDisplay = new DietViewDialog( this, *dietRList, dayNumber, mealNumber, dishNumbers );
		connect( dietDisplay, SIGNAL( signalOk() ), this, SLOT( createShoppingList() ) );
		dietDisplay->exec();
		delete dietDisplay;
	}

	END_TIMER();
}
Example #2
0
void UmlClass::utilities()
{
    TRACE_FUNCTION;
    const Q3PtrVector<UmlItem> ch = children();
    bool have_constructor = FALSE;
    bool have_destructor = FALSE;
    Q3CString destr = "~" + name();
    bool have_copy = FALSE;
    bool have_const_copy = FALSE;
    bool have_assignment = FALSE;
    bool have_const_assignment = FALSE;

    for (unsigned i = 0; i != ch.size(); i += 1) {
        if (ch[i]->kind() == anOperation) { //[rageek] literal comparison
            Q3CString s = ch[i]->name(); //[rageek]


            if (s == name()) {
                // may be a constructor or a copy constructor
                const Q3ValueList<UmlParameter> params =
                    ((UmlOperation *) ch[i])->params();

                if (params.count() == 1) {
                    const UmlParameter & param = *(params.at(0));

                    if (param.type.type == this) {
                        if (param.dir == InputDirection)
                            have_const_copy = TRUE;
                        else
                            have_copy = TRUE;
                    }
                    else
                        have_constructor = TRUE;
                }
                else
                    have_constructor = TRUE;
            }
            else if (s == destr)
                have_destructor = TRUE;
            else if (s == "operator=") {
                const Q3ValueList<UmlParameter> params =
                    ((UmlOperation *) ch[i])->params();

                if (params.count() == 1) {
                    if ((*(params.at(0))).dir == InputDirection)
                        have_const_assignment = TRUE;
                    else
                        have_assignment = TRUE;
                }
            }
        }
    }

    ConstrDestrCopyDialog d(this, have_constructor, have_destructor,
                            have_copy, have_const_copy,
                            have_assignment, have_const_assignment);

    d.exec();


}