This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
fanny-app/sources/foodplanmodel.cpp
dorian c6e1e12cfe Finished up foodplan Display:
- now using QAbstractItem model
- added error handling so the app doesn't crash anymore when the data is invalid
2018-12-23 21:07:10 +01:00

59 lines
1.9 KiB
C++

#include "headers/foodplanmodel.h"
FoodPlanModel::FoodPlanModel(QObject *parent) : QAbstractListModel(parent)
{
//m_foodPlan.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993", "uhj", "iuij" });
qDebug() << "foodplan Konstructor";
m_foodPlan.clear();
foreach(QList<QString>day, pGlobalServConn->m_weekplan){
m_foodPlan.append({day[0], day[1], day[2], day[3], day[4], day[5]});
}
qDebug() << "end1";
//qDebug() << pGlobalServConn->m_weekplan;
}
int FoodPlanModel::rowCount(const QModelIndex &) const
{
return m_foodPlan.count();
}
QVariant FoodPlanModel::data(const QModelIndex &index, int role) const
{
if (index.row() < rowCount())
switch (role) {
case CookteamRole: return m_foodPlan.at(index.row()).cookteam;
case DateRole: return m_foodPlan.at(index.row()).date;
case MainDishRole: return m_foodPlan.at(index.row()).mainDish;
case MainDishVegRole: return m_foodPlan.at(index.row()).mainDishVeg;
case GarnishRole: return m_foodPlan.at(index.row()).garnish;
case DessertRole: return m_foodPlan.at(index.row()).dessert;
default: return QVariant();
}
return QVariant();
}
QHash<int, QByteArray> FoodPlanModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
{ CookteamRole, "cookteam" },
{ DateRole, "date" },
{ MainDishRole, "mainDish" },
{ MainDishVegRole, "mainDishVeg" },
{ GarnishRole, "garnish" },
{ DessertRole, "dessert" }
};
return roles;
}
QVariantMap FoodPlanModel::get(int row) const
{
const Dish foodPlan = m_foodPlan.value(row);
return { {"cookteam", foodPlan.cookteam}, {"date", foodPlan.date}, {"mainDish", foodPlan.mainDish}, {"mainDishVeg", foodPlan.mainDishVeg}, {"garnish", foodPlan.garnish}, {"dessert", foodPlan.dessert} };
}
FoodPlanModel::~FoodPlanModel(){
}