Updated ingredientlistmodel for new ingredients model.
This commit is contained in:
parent
cd501d27cb
commit
a790128646
|
@ -30,13 +30,14 @@ void IngredientListModel::setIngredients(vector<Ingredient> ingredients){
|
||||||
emit dataChanged(index, bottomIndex);
|
emit dataChanged(index, bottomIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IngredientListModel::addIngredient(Ingredient ri){
|
bool IngredientListModel::addIngredient(Ingredient i){
|
||||||
//Add only if it doesn't exist already.
|
//Add only if it doesn't exist already.
|
||||||
for (unsigned int i = 0; i < this->ingredients.size(); i++){
|
for (Ingredient ing : this->ingredients){
|
||||||
if (!this->ingredients[i].getName().compare(ri.getName())){
|
if (!ing.getContent().compare(i.getContent())){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//The ingredient doesn't exist already, so we'll add it.
|
||||||
this->ingredients.push_back(ri);
|
this->ingredients.push_back(ri);
|
||||||
QModelIndex index = createIndex(this->ingredients.size()-1, 0);
|
QModelIndex index = createIndex(this->ingredients.size()-1, 0);
|
||||||
QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
|
QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "model/recipe/ingredients/recipeingredient.h"
|
#include "model/recipe/ingredients/ingredient.h"
|
||||||
|
|
||||||
class IngredientListModel : public QAbstractListModel
|
class IngredientListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -17,7 +18,7 @@ public:
|
||||||
|
|
||||||
//Custom methods to handle ingredient data.
|
//Custom methods to handle ingredient data.
|
||||||
void setIngredients(vector<Ingredient> ingredients);
|
void setIngredients(vector<Ingredient> ingredients);
|
||||||
bool addIngredient(Ingredient ri);
|
bool addIngredient(Ingredient i);
|
||||||
void deleteIngredient(int index);
|
void deleteIngredient(int index);
|
||||||
vector<Ingredient> getIngredients();
|
vector<Ingredient> getIngredients();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue