Example #1
0
void DietWizardDialog::populateIteratorList( RecipeList &rl, Q3ValueList <RecipeList::Iterator> *il )
{
	il->clear();
	RecipeList::Iterator it;
	for ( it = rl.begin();it != rl.end(); ++it )
		il->append( it );

}
Example #2
0
void ShoppingListDialog::createShopping( const RecipeList &rlist )
{
	clear();
	RecipeList::const_iterator it;
	for ( it = rlist.begin(); it != rlist.end(); ++it ) {
		new RecipeListItem( shopRecipeListView->listView(), shopRecipeListView->listView() ->lastItem(), *it );
	}
}
Example #3
0
QString MMFExporter::createContent( const RecipeList& recipes )
{
	QString content;

	RecipeList::const_iterator recipe_it;
	for ( recipe_it = recipes.begin(); recipe_it != recipes.end(); ++recipe_it ) {
		writeMMFHeader( content, *recipe_it );
		content += '\n';
		writeMMFIngredients( content, *recipe_it );
		content += '\n';
		writeMMFDirections( content, *recipe_it );
		content += '\n';

		content += "-----\n"; //end of recipe indicator
	}

	return content;
}
void KreSearchResultListWidget::displayRecipes( const RecipeList & recipes )
{
	clear();

	//Allocate memory for the items.
	m_sourceModel->setRowCount( recipes.count() );

	//Display the recipes in the items.
	RecipeList::const_iterator it; 
	QModelIndex index;
	int row_count = 0;
	for ( it = recipes.constBegin(); it != recipes.constEnd(); ++it ) {
		//The "Id" item.
		index = m_sourceModel->index( row_count, 1 );
		m_sourceModel->setData( index, it->recipeID, Qt::EditRole );
		m_sourceModel->setData( index, RecipeItem, ItemTypeRole );
		m_sourceModel->setData( index, it->recipeID, IdRole );
		//m_sourceModel->setData( status, CategorizedRole );
		m_sourceModel->itemFromIndex( index )->setEditable( false );

		//The "Recipe" item.
		index = m_sourceModel->index( row_count, 0 );
		m_sourceModel->setData( index, it->title, Qt::EditRole );
		m_sourceModel->setData( index, KIcon("documentation"), Qt::DecorationRole );
		m_sourceModel->setData( index, RecipeItem, ItemTypeRole );
		m_sourceModel->setData( index, it->recipeID, IdRole );
		//m_sourceModel->setData( status, CategorizedRole );
		m_sourceModel->itemFromIndex( index )->setEditable( false );

		//Update the persistent index map.
		m_recipeIdToIndexMap.insert( it->recipeID, index );

		row_count++;
	}

	//Sort the results.
	m_proxyModel->sort( 0 );
}
Example #5
0
QString RecipeMLExporter::createContent( const RecipeList& recipes )
{
	QDomDocument doc;

	RecipeList::const_iterator recipe_it;
	for ( recipe_it = recipes.begin(); recipe_it != recipes.end(); ++recipe_it ) {
		QDomElement recipe_tag = doc.createElement( "recipe" );

		doc.appendChild(recipe_tag);
		//recipe_root.appendChild( recipe_tag ); //will append to either <menu> if exists or else <recipeml>

		QDomElement head_tag = doc.createElement( "head" );
		recipe_tag.appendChild( head_tag );

		QDomElement title_tag = doc.createElement( "title" );
		title_tag.appendChild( doc.createTextNode( ( *recipe_it ).title ) );
		head_tag.appendChild( title_tag );

		QDomElement source_tag = doc.createElement( "source" );
		for ( ElementList::const_iterator author_it = ( *recipe_it ).authorList.begin(); author_it != ( *recipe_it ).authorList.end(); ++author_it ) {
			QDomElement srcitem_tag = doc.createElement( "srcitem" );
			srcitem_tag.appendChild( doc.createTextNode( ( *author_it ).name ) );
			source_tag.appendChild( srcitem_tag );
		}
		head_tag.appendChild( source_tag );

		QDomElement categories_tag = doc.createElement( "categories" );
		for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
			QDomElement cat_tag = doc.createElement( "cat" );
			cat_tag.appendChild( doc.createTextNode( ( *cat_it ).name ) );
			categories_tag.appendChild( cat_tag );
		}
		head_tag.appendChild( categories_tag );

		QDomElement yield_tag = doc.createElement( "yield" );
		if ( ( *recipe_it ).yield.amountOffset() < 1e-10 )
			yield_tag.appendChild( doc.createTextNode( QString::number( ( *recipe_it ).yield.amount() ) ) );
		else {
			QDomElement range_tag = doc.createElement( "range" );
			yield_tag.appendChild(range_tag);
			
			QDomElement q1_tag = doc.createElement( "q1" );
			q1_tag.appendChild( doc.createTextNode( QString::number(( *recipe_it ).yield.amount() ) ) );
			QDomElement q2_tag = doc.createElement( "q2" );
			q2_tag.appendChild( doc.createTextNode( QString::number( ( *recipe_it ).yield.amount() + ( *recipe_it ).yield.amountOffset() ) ) );

			range_tag.appendChild(q1_tag);
			range_tag.appendChild(q2_tag);
		}
		if ( !( *recipe_it ).yield.type().isEmpty() ) {
			QDomElement yield_unit_tag = doc.createElement( "unit" );
			yield_unit_tag.appendChild( doc.createTextNode(( *recipe_it ).yield.type()) );
			yield_tag.appendChild( yield_unit_tag );
		}

		head_tag.appendChild( yield_tag );

		if ( !( *recipe_it ).prepTime.isNull() ) {
			QDomElement preptime_tag = doc.createElement( "preptime" );
			head_tag.appendChild( preptime_tag );
			preptime_tag.setAttribute( "type", i18nc( "Total preparation time", "Total" ) );

			QDomElement preptime_time_tag = doc.createElement( "time" );
			preptime_tag.appendChild( preptime_time_tag );

			QDomElement preptime_min_qty_tag = doc.createElement( "qty" );
			preptime_time_tag.appendChild( preptime_min_qty_tag );
			preptime_min_qty_tag.appendChild( doc.createTextNode( QString::number( ( *recipe_it ).prepTime.minute() + ( *recipe_it ).prepTime.hour() * 60 ) ) );

			QDomElement preptime_min_unit_tag = doc.createElement( "timeunit" );
			preptime_time_tag.appendChild( preptime_min_unit_tag );
			preptime_min_unit_tag.appendChild( doc.createTextNode( "minutes" ) );
		}

		QDomElement ingredients_tag = doc.createElement( "ingredients" );
		IngredientList list_copy = ( *recipe_it ).ingList;
		for ( IngredientList group_list = list_copy.firstGroup(); group_list.count() != 0; group_list = list_copy.nextGroup() ) {
			QDomElement ing_root;

			QString group = group_list[ 0 ].group; //just use the first's name... they're all the same
			if ( !group.isEmpty() ) {
				QDomElement ingdiv_tag = doc.createElement( "ing-div" );
				QDomElement title_tag = doc.createElement( "title" );
				title_tag.appendChild( doc.createTextNode( group ) );
				ingdiv_tag.appendChild( title_tag );
				ingredients_tag.appendChild( ingdiv_tag );
				ing_root = ingdiv_tag;
			}
			else
				ing_root = ingredients_tag;

			for ( IngredientList::const_iterator ing_it = group_list.begin(); ing_it != group_list.end(); ++ing_it ) {
				QDomElement ing_tag = doc.createElement( "ing" );
				ing_root.appendChild( ing_tag );

				createIngredient( ing_tag, *ing_it, doc );

				for ( Ingredient::SubstitutesList::const_iterator sub_it = (*ing_it).substitutes.begin(); sub_it != (*ing_it).substitutes.end(); ++sub_it ) {
					QDomElement alt_ing_tag = doc.createElement( "alt-ing" );
					ing_tag.appendChild( alt_ing_tag );
					createIngredient( alt_ing_tag, *sub_it, doc );
				}
			}
		}
		recipe_tag.appendChild( ingredients_tag );

		QDomElement directions_tag = doc.createElement( "directions" );
		recipe_tag.appendChild( directions_tag );

		QDomElement step_tag = doc.createElement( "step" ); //we've just got everything in one step
		directions_tag.appendChild( step_tag );
		step_tag.appendChild( doc.createTextNode( ( *recipe_it ).instructions ) );
	}

	return doc.toString();
}
Example #6
0
void IngredientMatcherDialog::findRecipes( void )
{
	KApplication::setOverrideCursor( Qt::WaitCursor );

	START_TIMER("Ingredient Matcher: loading database data");

	RecipeList rlist;
	database->loadRecipes( &rlist, RecipeDB::Title | RecipeDB::NamesOnly | RecipeDB::Ingredients | RecipeDB::IngredientAmounts );

	END_TIMER();
	START_TIMER("Ingredient Matcher: analyzing data for matching recipes");

	// Clear the list
	recipeListView->listView() ->clear();

	// Now show the recipes with ingredients that are contained in the previous set
	// of ingredients
	RecipeList incompleteRecipes;
	QList <int> missingNumbers;
	Q3ValueList <IngredientList> missingIngredients;

	RecipeList::Iterator it;
	for ( it = rlist.begin();it != rlist.end();++it ) {
		IngredientList il = ( *it ).ingList;
		if ( il.isEmpty() )
			continue;

		IngredientList missing;
		if ( m_ingredientList.containsSubSet( il, missing, true, database ) ) {
			new CustomRecipeListItem( recipeListView->listView(), *it );
		}
		else {
			incompleteRecipes.append( *it );
			missingIngredients.append( missing );
			missingNumbers.append( missing.count() );
		}
	}
	END_TIMER();

	//Check if the user wants to show missing ingredients

	if ( missingNumberSpinBox->value() == 0 ) {
		KApplication::restoreOverrideCursor();
		return ;
	} //"None"



	START_TIMER("Ingredient Matcher: searching for and displaying partial matches");

	IngredientList requiredIngredients;
	for ( Q3ListViewItem *it = ingListView->listView()->firstChild(); it; it = it->nextSibling() ) {
		if ( ((Q3CheckListItem*)it)->isOn() )
			requiredIngredients << *m_item_ing_map[it];
	}

	// Classify recipes with missing ingredients in different lists by amount
	QList<int>::Iterator nit;
	Q3ValueList<IngredientList>::Iterator ilit;
	int missingNoAllowed = missingNumberSpinBox->value();

	if ( missingNoAllowed == -1 )  // "Any"
	{
		for ( nit = missingNumbers.begin();nit != missingNumbers.end();++nit )
			if ( ( *nit ) > missingNoAllowed )
				missingNoAllowed = ( *nit );
	}


	for ( int missingNo = 1; missingNo <= missingNoAllowed; missingNo++ ) {
		nit = missingNumbers.begin();
		ilit = missingIngredients.begin();

		bool titleShownYet = false;

		for ( it = incompleteRecipes.begin();it != incompleteRecipes.end();++it, ++nit, ++ilit ) {
			if ( !( *it ).ingList.containsAny( m_ingredientList ) )
				continue;

			if ( !( *it ).ingList.containsSubSet( requiredIngredients ) )
				continue;

			if ( ( *nit ) == missingNo ) {
				if ( !titleShownYet ) {
					new SectionItem( recipeListView->listView(), i18ncp( "@label:textbox", "You are missing 1 ingredient for:", "You are missing %1 ingredients for:", missingNo ) );
					titleShownYet = true;
				}
				new CustomRecipeListItem( recipeListView->listView(), *it, *ilit );
			}
		}
	}
	END_TIMER();

	KApplication::restoreOverrideCursor();
}