From 07774cc349e82379b6f096615f95074cadc01f5d Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 22 May 2018 21:09:14 +0200 Subject: [PATCH] Removed recipeingredient files, and unitofmeasure. These are too restrictive. --- RecipeDB.pro | 5 +- model/recipe/ingredients/recipeingredient.cpp | 60 ------------------- .../ingredients/recipeingredientlistmodel.cpp | 54 ----------------- model/recipe/ingredients/unitofmeasure.cpp | 42 ------------- 4 files changed, 1 insertion(+), 160 deletions(-) delete mode 100644 model/recipe/ingredients/recipeingredient.cpp delete mode 100644 model/recipe/ingredients/recipeingredientlistmodel.cpp delete mode 100644 model/recipe/ingredients/unitofmeasure.cpp diff --git a/RecipeDB.pro b/RecipeDB.pro index fdcef14..a07dd60 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -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 \ diff --git a/model/recipe/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp deleted file mode 100644 index 6e7d775..0000000 --- a/model/recipe/ingredients/recipeingredient.cpp +++ /dev/null @@ -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; -} diff --git a/model/recipe/ingredients/recipeingredientlistmodel.cpp b/model/recipe/ingredients/recipeingredientlistmodel.cpp deleted file mode 100644 index 18cdaa6..0000000 --- a/model/recipe/ingredients/recipeingredientlistmodel.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "recipeingredientlistmodel.h" - -RecipeIngredientListModel::RecipeIngredientListModel(){ - this->ingredients = vector(); -} - -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 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 RecipeIngredientListModel::getIngredients(){ - return this->ingredients; -} diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp deleted file mode 100644 index dedcb75..0000000 --- a/model/recipe/ingredients/unitofmeasure.cpp +++ /dev/null @@ -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; -}