diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp index bbafe66..e3b4f63 100644 --- a/model/recipe/ingredients/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -30,13 +30,14 @@ void IngredientListModel::setIngredients(vector ingredients){ emit dataChanged(index, bottomIndex); } -bool IngredientListModel::addIngredient(Ingredient ri){ +bool IngredientListModel::addIngredient(Ingredient i){ //Add only if it doesn't exist already. - for (unsigned int i = 0; i < this->ingredients.size(); i++){ - if (!this->ingredients[i].getName().compare(ri.getName())){ + for (Ingredient ing : this->ingredients){ + if (!ing.getContent().compare(i.getContent())){ return false; } } + //The ingredient doesn't exist already, so we'll add it. this->ingredients.push_back(ri); QModelIndex index = createIndex(this->ingredients.size()-1, 0); QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0); diff --git a/model/recipe/ingredients/ingredientlistmodel.h b/model/recipe/ingredients/ingredientlistmodel.h index 31dd94d..32bc65d 100644 --- a/model/recipe/ingredients/ingredientlistmodel.h +++ b/model/recipe/ingredients/ingredientlistmodel.h @@ -3,8 +3,9 @@ #include #include +#include -#include "model/recipe/ingredients/recipeingredient.h" +#include "model/recipe/ingredients/ingredient.h" class IngredientListModel : public QAbstractListModel { @@ -17,7 +18,7 @@ public: //Custom methods to handle ingredient data. void setIngredients(vector ingredients); - bool addIngredient(Ingredient ri); + bool addIngredient(Ingredient i); void deleteIngredient(int index); vector getIngredients();