Improve/redesign ingredients #13
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue