2018-02-12 14:15:04 +00:00
|
|
|
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
2018-02-12 13:24:11 +00:00
|
|
|
|
|
|
|
IngredientListModel::IngredientListModel(){
|
2018-02-13 08:48:57 +00:00
|
|
|
this->ingredients = vector<RecipeIngredient>();
|
2018-02-12 13:24:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 08:48:57 +00:00
|
|
|
int IngredientListModel::rowCount(const QModelIndex &parent) const{
|
2018-02-13 09:22:05 +00:00
|
|
|
return this->ingredients.size();
|
2018-02-12 13:24:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 08:48:57 +00:00
|
|
|
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
2018-02-13 09:22:05 +00:00
|
|
|
int row = index.row();
|
|
|
|
|
|
|
|
switch(role){
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return QString::fromStdString(ingredients[row].getName());
|
|
|
|
}
|
2018-02-12 13:24:11 +00:00
|
|
|
|
2018-02-13 09:22:05 +00:00
|
|
|
return QVariant();
|
2018-02-12 13:24:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 08:48:57 +00:00
|
|
|
void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
|
2018-02-12 13:24:11 +00:00
|
|
|
this->ingredients = ingredients;
|
2018-02-13 09:22:05 +00:00
|
|
|
QModelIndex index = createIndex(0, 0);
|
|
|
|
QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
|
|
|
|
emit dataChanged(index, bottomIndex);
|
2018-02-12 13:24:11 +00:00
|
|
|
}
|