EWAHTMLSelector::EWAHTMLSelector( QWidget *pParent ) :QWidget( pParent ) { m_pDlg = new EWAHtmlSelectorDlg( this ); connect( m_pDlg, SIGNAL( signalOk() ), this, SIGNAL ( signalAccepted() ) ); connect( m_pDlg, SIGNAL( signalCancel() ), this, SIGNAL ( signalReject() ) ); m_webViewPtr = 0; m_messagePtr = 0; m_bkgndPen = QPen( Qt::gray ); m_markerPen = QPen( Qt::yellow ); setMouseTracking( true ); }
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(); }