Improve/redesign ingredients #13

Merged
andrewlalis merged 13 commits from improve/redesignIngredients into development 2018-05-22 21:29:25 +00:00
4 changed files with 1 additions and 160 deletions
Showing only changes of commit 07774cc349 - Show all commits

View File

@ -16,10 +16,8 @@ SOURCES += model/recipe/instruction.cpp \
model/recipe/recipe.cpp \
main.cpp \
model/database/database.cpp \
model/recipe/ingredients/unitofmeasure.cpp \
model/recipe/ingredients/ingredient.cpp \
model/recipe/ingredients/ingredientlistmodel.cpp \
model/recipe/ingredients/recipeingredient.cpp \
model/recipe/tags/recipetag.cpp \
SQLite/sqlite3.c \
model/database/resulttable.cpp \
@ -35,8 +33,7 @@ SOURCES += model/recipe/instruction.cpp \
gui/openrecipedialog.cpp \
model/recipe/recipetablemodel.cpp \
gui/mainwindow.cpp \
gui/newDialogs/newfoodgroupdialog.cpp \
model/recipe/ingredients/recipeingredientlistmodel.cpp
gui/newDialogs/newfoodgroupdialog.cpp
HEADERS += model/recipe/instruction.h \
model/recipe/recipe.h \

View File

@ -1,60 +0,0 @@
#include "model/recipe/ingredients/recipeingredient.h"
RecipeIngredient::RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit, string comment) : Ingredient(name, foodGroup){
setQuantity(quantity);
setUnit(unit);
setComment(comment);
}
RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit, string comment){
setName(i.getName());
setFoodGroup(i.getFoodGroup());
setQuantity(quantity);
setUnit(unit);
setComment(comment);
}
RecipeIngredient::RecipeIngredient(Ingredient &i) : RecipeIngredient(i, 0.0f, UnitOfMeasure("bleh"), "Fuck"){
//Constructs recipe ingredient from ingredient which is a hidden recipe ingredient.
}
RecipeIngredient::RecipeIngredient(){
}
float RecipeIngredient::getQuantity() const{
return this->quantity;
}
UnitOfMeasure RecipeIngredient::getUnit() const{
return this->unit;
}
string RecipeIngredient::getComment() const{
return this->comment;
}
void RecipeIngredient::setQuantity(float newQuantity){
this->quantity = newQuantity;
}
void RecipeIngredient::setUnit(UnitOfMeasure newUnit){
this->unit = newUnit;
}
void RecipeIngredient::setComment(string newComment){
this->comment = newComment;
}
string RecipeIngredient::toString(){
string result;
if (std::ceil(this->getQuantity()) == this->getQuantity()){
result += std::to_string((int)this->getQuantity());
} else {
result += StringUtils::toString(this->getQuantity());
}
result += " " + this->getUnit().getAbbreviation() + " " + this->getName();
if (!this->getComment().empty()) result += " (" + this->getComment() + ")";
return result;
}

View File

@ -1,54 +0,0 @@
#include "recipeingredientlistmodel.h"
RecipeIngredientListModel::RecipeIngredientListModel(){
this->ingredients = vector<RecipeIngredient>();
}
int RecipeIngredientListModel::rowCount(const QModelIndex &parent) const{
Q_UNUSED(parent);
return this->ingredients.size();
}
QVariant RecipeIngredientListModel::data(const QModelIndex &index, int role) const{
int row = index.row();
RecipeIngredient i = this->ingredients[row];
string displayStr = i.toString();
switch(role){
case Qt::DisplayRole:
return QString::fromStdString(displayStr);
}
return QVariant();
}
void RecipeIngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
this->ingredients = ingredients;
QModelIndex index = createIndex(0, 0);
QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
emit dataChanged(index, bottomIndex);
}
bool RecipeIngredientListModel::addIngredient(RecipeIngredient ri){
//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())){
return false;
}
}
this->ingredients.push_back(ri);
QModelIndex index = createIndex(this->ingredients.size()-1, 0);
QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
emit dataChanged(index, bottomIndex);
return true;
}
void RecipeIngredientListModel::deleteIngredient(int index){
this->ingredients.erase(this->ingredients.begin() + index);
emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0));
}
vector<RecipeIngredient> RecipeIngredientListModel::getIngredients(){
return this->ingredients;
}

View File

@ -1,42 +0,0 @@
#include "unitofmeasure.h"
UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation, int type, double coef){
this->name = name;
this->plural = plural;
this->abbreviation = abbreviation;
this->type = type;
this->metricCoefficient = coef;
}
UnitOfMeasure::UnitOfMeasure(string name){
this->name = name;
this->plural = name + "s";
this->abbreviation = "NULL";
this->type = MISC;
this->metricCoefficient = 1;
///TODO: Make actual guessing of this stuff.
}
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", "", MISC, 1.0){
//Default constructor initializes all fields to empty strings.
}
string UnitOfMeasure::getName() const{
return this->name;
}
string UnitOfMeasure::getNamePlural() const{
return this->plural;
}
string UnitOfMeasure::getAbbreviation() const{
return this->abbreviation;
}
int UnitOfMeasure::getType() const{
return this->type;
}
double UnitOfMeasure::getMetricCoefficient() const{
return this->metricCoefficient;
}