Improve/redesign ingredients #13

Merged
andrewlalis merged 13 commits from improve/redesignIngredients into development 2018-05-22 21:29:25 +00:00
2 changed files with 7 additions and 5 deletions
Showing only changes of commit a790128646 - Show all commits

View File

@ -30,13 +30,14 @@ void IngredientListModel::setIngredients(vector<Ingredient> 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);

View File

@ -3,8 +3,9 @@
#include <QAbstractListModel>
#include <QModelIndex>
#include <vector>
#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<Ingredient> ingredients);
bool addIngredient(Ingredient ri);
bool addIngredient(Ingredient i);
void deleteIngredient(int index);
vector<Ingredient> getIngredients();