From 05a18d6a9a34d7ffa69d034c4ba422cb4aab51bf Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 15:15:04 +0100 Subject: [PATCH 01/11] Re-organized ingredient-related objects, added descriptions. --- RecipeDB.pro | 15 ++++++----- gui/mainwindow.ui | 3 +++ model/database/database.h | 2 +- model/recipe/{ => ingredients}/ingredient.cpp | 2 +- model/recipe/{ => ingredients}/ingredient.h | 4 +++ .../{ => ingredients}/ingredientlistmodel.cpp | 2 +- .../{ => ingredients}/ingredientlistmodel.h | 2 +- .../{ => ingredients}/recipeingredient.cpp | 2 +- .../{ => ingredients}/recipeingredient.h | 2 +- model/recipe/ingredients/unitofmeasure.cpp | 6 +++++ model/recipe/ingredients/unitofmeasure.h | 22 +++++++++++++++ model/recipe/instruction.cpp | 2 +- model/recipe/recipe.cpp | 15 ++++++----- model/recipe/recipe.h | 27 ++++++++++++++----- userInterface/mainwindow.cpp | 6 ++--- userInterface/mainwindow.h | 6 +++-- 16 files changed, 86 insertions(+), 32 deletions(-) rename model/recipe/{ => ingredients}/ingredient.cpp (92%) rename model/recipe/{ => ingredients}/ingredient.h (64%) rename model/recipe/{ => ingredients}/ingredientlistmodel.cpp (86%) rename model/recipe/{ => ingredients}/ingredientlistmodel.h (91%) rename model/recipe/{ => ingredients}/recipeingredient.cpp (92%) rename model/recipe/{ => ingredients}/recipeingredient.h (92%) create mode 100644 model/recipe/ingredients/unitofmeasure.cpp create mode 100644 model/recipe/ingredients/unitofmeasure.h diff --git a/RecipeDB.pro b/RecipeDB.pro index cfc7f09..7c40f21 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -13,24 +13,27 @@ TEMPLATE = app SOURCES += SQLite/sqlite3.c \ - model/recipe/ingredient.cpp \ model/recipe/instruction.cpp \ model/recipe/recipe.cpp \ - model/recipe/recipeingredient.cpp \ userInterface/mainwindow.cpp \ main.cpp \ model/database/database.cpp \ - model/recipe/ingredientlistmodel.cpp + model/recipe/ingredients/unitofmeasure.cpp \ + model/recipe/ingredients/ingredient.cpp \ + model/recipe/ingredients/ingredientlistmodel.cpp \ + model/recipe/ingredients/recipeingredient.cpp HEADERS += SQLite/sqlite3.h \ SQLite/sqlite3ext.h \ - model/recipe/ingredient.h \ model/recipe/instruction.h \ model/recipe/recipe.h \ - model/recipe/recipeingredient.h \ userInterface/mainwindow.h \ model/database/database.h \ - model/recipe/ingredientlistmodel.h + model/recipe/ingredientlistmodel.h \ + model/recipe/ingredients/unitofmeasure.h \ + model/recipe/ingredients/ingredient.h \ + model/recipe/ingredients/ingredientlistmodel.h \ + model/recipe/ingredients/recipeingredient.h FORMS += gui/mainwindow.ui diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 2dcf446..8d7b0c5 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -432,6 +432,9 @@ QAbstractScrollArea::AdjustToContents + + QTextEdit::AutoNone + QTextEdit::WidgetWidth diff --git a/model/database/database.h b/model/database/database.h index 12a294e..dce935a 100644 --- a/model/database/database.h +++ b/model/database/database.h @@ -5,7 +5,7 @@ #include #include "SQLite/sqlite3.h" -#include "model/recipe/ingredient.h" +#include "model/recipe/ingredients/ingredient.h" using namespace std; diff --git a/model/recipe/ingredient.cpp b/model/recipe/ingredients/ingredient.cpp similarity index 92% rename from model/recipe/ingredient.cpp rename to model/recipe/ingredients/ingredient.cpp index 5cdcc53..f0d2cf0 100644 --- a/model/recipe/ingredient.cpp +++ b/model/recipe/ingredients/ingredient.cpp @@ -1,4 +1,4 @@ -#include "headers/ingredient.h" +#include "model/recipe/ingredients/ingredient.h" Ingredient::Ingredient(){ setId(-1); diff --git a/model/recipe/ingredient.h b/model/recipe/ingredients/ingredient.h similarity index 64% rename from model/recipe/ingredient.h rename to model/recipe/ingredients/ingredient.h index 2f4b0d0..1b58c49 100644 --- a/model/recipe/ingredient.h +++ b/model/recipe/ingredients/ingredient.h @@ -5,6 +5,10 @@ using namespace std; +/** + * @brief The Ingredient class represents an ingredient, which is classified by a food group, and has a name and an ID. An ingredient cannot be included on its own in a recipe, and must be paired with a Unit in a RecipeIngredient Object. + */ + class Ingredient { public: diff --git a/model/recipe/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp similarity index 86% rename from model/recipe/ingredientlistmodel.cpp rename to model/recipe/ingredients/ingredientlistmodel.cpp index d837125..edf629c 100644 --- a/model/recipe/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -1,4 +1,4 @@ -#include "model/recipe/ingredientlistmodel.h" +#include "model/recipe/ingredients/ingredientlistmodel.h" IngredientListModel::IngredientListModel(){ this->ingredients = vector(); diff --git a/model/recipe/ingredientlistmodel.h b/model/recipe/ingredients/ingredientlistmodel.h similarity index 91% rename from model/recipe/ingredientlistmodel.h rename to model/recipe/ingredients/ingredientlistmodel.h index b71d21c..b995210 100644 --- a/model/recipe/ingredientlistmodel.h +++ b/model/recipe/ingredients/ingredientlistmodel.h @@ -3,7 +3,7 @@ #include -#include "model/recipe/ingredient.h" +#include "model/recipe/ingredients/ingredient.h" class IngredientListModel : public QAbstractListModel { diff --git a/model/recipe/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp similarity index 92% rename from model/recipe/recipeingredient.cpp rename to model/recipe/ingredients/recipeingredient.cpp index ad43dfa..d697293 100644 --- a/model/recipe/recipeingredient.cpp +++ b/model/recipe/ingredients/recipeingredient.cpp @@ -1,4 +1,4 @@ -#include "headers/recipeingredient.h" +#include "model/recipe/ingredients/recipeingredient.h" RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit) : Ingredient(id, name, foodGroup){ setQuantity(quantity); diff --git a/model/recipe/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h similarity index 92% rename from model/recipe/recipeingredient.h rename to model/recipe/ingredients/recipeingredient.h index 388a1a3..be5369d 100644 --- a/model/recipe/recipeingredient.h +++ b/model/recipe/ingredients/recipeingredient.h @@ -3,7 +3,7 @@ #include -#include "headers/ingredient.h" +#include "model/recipe/ingredients/ingredient.h" using namespace std; diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp new file mode 100644 index 0000000..4f5fafe --- /dev/null +++ b/model/recipe/ingredients/unitofmeasure.cpp @@ -0,0 +1,6 @@ +#include "unitofmeasure.h" + +UnitOfMeasure::UnitOfMeasure() +{ + +} diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h new file mode 100644 index 0000000..988618d --- /dev/null +++ b/model/recipe/ingredients/unitofmeasure.h @@ -0,0 +1,22 @@ +#ifndef UNITOFMEASURE_H +#define UNITOFMEASURE_H + +#include + +using namespace std; + +/** + * @brief The UnitOfMeasure class represents a way to measure an ingredient. It contains a name, an abbreviation, plural name, and some information on conversion. + */ + +class UnitOfMeasure +{ +public: + UnitOfMeasure(); +private: + string name; + string plural; + string abbreviation; +}; + +#endif // UNITOFMEASURE_H diff --git a/model/recipe/instruction.cpp b/model/recipe/instruction.cpp index 4da0c44..2914bd7 100644 --- a/model/recipe/instruction.cpp +++ b/model/recipe/instruction.cpp @@ -1,4 +1,4 @@ -#include "headers/instruction.h" +#include "model/recipe/instruction.h" Instruction::Instruction() { diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index 948e231..2b73e5d 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -2,24 +2,25 @@ Recipe::Recipe(){ this->name = "NULL"; - this->ingredients = vector(); - this->instructions = vector(); + this->ingredients = vector(); + this->instruction = Instruction(); } -Recipe::Recipe(string name, vector ingredients, vector instructions){ +Recipe::Recipe(string name, vector ingredients, Instruction instruction) +{ this->name = name; this->ingredients = ingredients; - this->instructions = instructions; + this->instruction = instruction; } string Recipe::getName(){ return this->name; } -vector Recipe::getIngredients(){ +vector Recipe::getIngredients(){ return this->ingredients; } -vector Recipe::getInstructions(){ - return this->instructions; +Instruction Recipe::getInstruction(){ + return this->instruction; } diff --git a/model/recipe/recipe.h b/model/recipe/recipe.h index 4cf3b9f..47b8e32 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -3,27 +3,40 @@ #include #include -#include -#include "model/recipe/ingredient.h" +#include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/instruction.h" using namespace std; +/** + * @brief The Recipe class represents all the data of a recipe: + * - A name. + * - List of ingredients. + * - An instruction object, which represents a block of HTML text which forms the instructions. + * - An image, if possible. + * - Created Date + * - A list of tags. + * - Makes X Servings. + * - Prep time. + * - Cook time. + * The recipe object can be used to populate the window with a full recipe. Prep time, cook time, servings, will be displayed at the beginning of the instructions block. + */ + class Recipe { public: Recipe(); - Recipe(string name, vector ingredients, vector instructions); + Recipe(string name, vector ingredients, Instruction instruction); string getName(); - vector getIngredients(); - vector getInstructions(); + vector getIngredients(); + Instruction getInstruction(); private: string name; vector tags; - vector ingredients; - vector instructions; + vector ingredients; + Instruction instruction; }; diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index eacb5ba..59f2c18 100644 --- a/userInterface/mainwindow.cpp +++ b/userInterface/mainwindow.cpp @@ -13,7 +13,7 @@ MainWindow::~MainWindow(){ void MainWindow::loadFromRecipe(Recipe recipe){ setRecipeName(recipe.getName()); - setInstructions(recipe.getInstructions()); + setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); } @@ -21,10 +21,10 @@ void MainWindow::setRecipeName(string name){ ui->recipeNameLabel->setText(QString::fromStdString(name)); } -void MainWindow::setInstructions(vector instructions){ +void MainWindow::setInstruction(Instruction instruction){ } -void MainWindow::setIngredients(vector ingredients){ +void MainWindow::setIngredients(vector ingredients){ } diff --git a/userInterface/mainwindow.h b/userInterface/mainwindow.h index eae9892..86f7910 100644 --- a/userInterface/mainwindow.h +++ b/userInterface/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include #include "model/recipe/recipe.h" @@ -24,11 +25,12 @@ public: void loadFromRecipe(Recipe recipe); private: Ui::MainWindow *ui; + QAbstractListModel *ingredientsListModel; //Hidden manipulation methods. void setRecipeName(string name); - void setInstructions(vector instructions); - void setIngredients(vector ingredients); + void setInstruction(Instruction instruction); + void setIngredients(vector ingredients); }; #endif // MAINWINDOW_H From 45db82f0d5c1f5a69073609ad01a902b5151cffe Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 16:27:24 +0100 Subject: [PATCH 02/11] Added variables to unit of measure. --- model/recipe/ingredients/ingredient.h | 3 ++- model/recipe/ingredients/recipeingredient.h | 4 ++++ model/recipe/ingredients/unitofmeasure.h | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/model/recipe/ingredients/ingredient.h b/model/recipe/ingredients/ingredient.h index 1b58c49..5aace81 100644 --- a/model/recipe/ingredients/ingredient.h +++ b/model/recipe/ingredients/ingredient.h @@ -6,7 +6,8 @@ using namespace std; /** - * @brief The Ingredient class represents an ingredient, which is classified by a food group, and has a name and an ID. An ingredient cannot be included on its own in a recipe, and must be paired with a Unit in a RecipeIngredient Object. + * @brief The Ingredient class represents an ingredient, which is classified by a food group, and has a name and an ID. + * An ingredient cannot be included on its own in a recipe, and must be paired with a Unit in a RecipeIngredient Object. */ class Ingredient diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h index be5369d..486b5a5 100644 --- a/model/recipe/ingredients/recipeingredient.h +++ b/model/recipe/ingredients/recipeingredient.h @@ -7,6 +7,10 @@ using namespace std; +/** + * @brief The RecipeIngredient class represents both an ingredient and a unit of measure, to be used in a recipe object. + */ + class RecipeIngredient : public Ingredient { public: diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h index 988618d..89bc010 100644 --- a/model/recipe/ingredients/unitofmeasure.h +++ b/model/recipe/ingredients/unitofmeasure.h @@ -14,9 +14,10 @@ class UnitOfMeasure public: UnitOfMeasure(); private: - string name; - string plural; - string abbreviation; + string name; //The name of the unit of measure. + string plural; //The plural name. + string abbreviation; //A short version of the unit. + float siBaseUnitEquivalent; //The ratio when compared to the base SI unit for this unit. For example: 1 cup = 237mL. }; #endif // UNITOFMEASURE_H From c09f29930b0d9e82d0c1078e57bd360f5c96b1cf Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:20:38 +0100 Subject: [PATCH 03/11] Ignoring .autosave files, added fields to recipe object, improved unit of measure. --- .gitignore | 3 +- model/recipe/ingredients/recipeingredient.cpp | 6 ++-- model/recipe/ingredients/recipeingredient.h | 11 +++--- model/recipe/ingredients/unitofmeasure.cpp | 19 +++++++++-- model/recipe/ingredients/unitofmeasure.h | 8 +++-- model/recipe/recipe.cpp | 21 +++++++++++- model/recipe/recipe.h | 34 +++++++++++++++---- 7 files changed, 81 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index b38eccc..b165559 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pro -*.pro.user \ No newline at end of file +*.pro.user +*.autosave \ No newline at end of file diff --git a/model/recipe/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp index d697293..c7d3898 100644 --- a/model/recipe/ingredients/recipeingredient.cpp +++ b/model/recipe/ingredients/recipeingredient.cpp @@ -1,11 +1,11 @@ #include "model/recipe/ingredients/recipeingredient.h" -RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit) : Ingredient(id, name, foodGroup){ +RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, UnitOfMeasure unit) : Ingredient(id, name, foodGroup){ setQuantity(quantity); setUnit(unit); } -RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, string unit){ +RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit){ setId(i.getId()); setName(i.getName()); setFoodGroup(i.getFoodGroup()); @@ -21,7 +21,7 @@ void RecipeIngredient::setQuantity(int newQuantity){ this->quantity = newQuantity; } -void RecipeIngredient::setUnit(string newUnit){ +void RecipeIngredient::setUnit(UnitOfMeasure newUnit){ this->unit = newUnit; } diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h index 486b5a5..8a75c0e 100644 --- a/model/recipe/ingredients/recipeingredient.h +++ b/model/recipe/ingredients/recipeingredient.h @@ -4,6 +4,7 @@ #include #include "model/recipe/ingredients/ingredient.h" +#include "model/recipe/ingredients/unitofmeasure.h" using namespace std; @@ -14,19 +15,19 @@ using namespace std; class RecipeIngredient : public Ingredient { public: - RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit); - RecipeIngredient(Ingredient i, int quantity, string unit); + RecipeIngredient(int id, string name, string foodGroup, int quantity, UnitOfMeasure unit); + RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit); int getQuantity(); - string getUnit(); + UnitOfMeasure getUnit(); string getComment(); void setQuantity(int newQuantity); - void setUnit(string newUnit); + void setUnit(UnitOfMeasure newUnit); void setComment(string newComment); private: int quantity; - string unit; + UnitOfMeasure unit; string comment; }; diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp index 4f5fafe..16d82ef 100644 --- a/model/recipe/ingredients/unitofmeasure.cpp +++ b/model/recipe/ingredients/unitofmeasure.cpp @@ -1,6 +1,19 @@ #include "unitofmeasure.h" -UnitOfMeasure::UnitOfMeasure() -{ - +UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){ + this->name = name; + this->plural = plural; + this->abbreviation = abbreviation; +} + +string UnitOfMeasure::getName(){ + return this->name; +} + +string UnitOfMeasure::getNamePlural(){ + return this->plural; +} + +string UnitOfMeasure::getAbbreviation(){ + return this->abbreviation; } diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h index 89bc010..62c633d 100644 --- a/model/recipe/ingredients/unitofmeasure.h +++ b/model/recipe/ingredients/unitofmeasure.h @@ -12,12 +12,16 @@ using namespace std; class UnitOfMeasure { public: - UnitOfMeasure(); + UnitOfMeasure(string name, string plural, string abbreviation); + + //Getters + string getName(); + string getNamePlural(); + string getAbbreviation(); private: string name; //The name of the unit of measure. string plural; //The plural name. string abbreviation; //A short version of the unit. - float siBaseUnitEquivalent; //The ratio when compared to the base SI unit for this unit. For example: 1 cup = 237mL. }; #endif // UNITOFMEASURE_H diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index 2b73e5d..bd61d8d 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -1,9 +1,28 @@ #include "model/recipe/recipe.h" Recipe::Recipe(){ - this->name = "NULL"; + //Set default values when none are specified. + this->name = "Unnamed Recipe"; this->ingredients = vector(); this->instruction = Instruction(); + this->image = QImage(); + this->tags = vector(); + this->createdDate = QDate.currentDate(); + this->prepTime = QTime(1, 0); + this->cookTime = QTime(0, 30); + this->servings = 10; +} + +Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ + this->name = name; + this->ingredients = ingredients; + this->instruction = instruction; + this->image = image; + this->tags = tags; + this->createdDate = createdDate; + this->prepTime = prepTime; + this->cookTime = cookTime; + this->servings = servings; } Recipe::Recipe(string name, vector ingredients, Instruction instruction) diff --git a/model/recipe/recipe.h b/model/recipe/recipe.h index 47b8e32..9600bd0 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/instruction.h" @@ -27,17 +30,36 @@ class Recipe { public: Recipe(); - Recipe(string name, vector ingredients, Instruction instruction); + //Full constructor + Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags); + //Getters string getName(); vector getIngredients(); Instruction getInstruction(); + QImage getImage(); + vector getTags(); + QDate getCreatedDate(); + QTime getPrepTime(); + QTime getCookTime(); + QTime getTotalTime(); + float getServings(); + //Setters + void setName(string newName); + void addIngredient(RecipeIngredient newIngredient); + void setInstruction(Instruction newInstruction); private: - string name; - vector tags; - vector ingredients; - Instruction instruction; - + //Main information. + string name; //The name of the recipe. + vector ingredients; //The list of ingredients in the recipe. + Instruction instruction; //The instruction HTML document. + QImage image; //An image displayed alongside the recipe. + //Auxiliary Information. + vector tags; //The list of tags which can be used to categorize the recipe. + QDate createdDate; //The date the recipe was created. + QTime prepTime; //The time taken for preparation. + QTime cookTime; //The time taken to cook. + float servings; //The number of servings which this recipe produces. }; #endif // RECIPE_H From c928533e6a1d115a722829e97d76ae57bf8286c0 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:25:48 +0100 Subject: [PATCH 04/11] Added RecipeTag object to replace string in recipe object. --- RecipeDB.pro | 6 ++++-- model/recipe/recipe.cpp | 5 +++++ model/recipe/tags/recipetag.cpp | 17 +++++++++++++++++ model/recipe/tags/recipetag.h | 26 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 model/recipe/tags/recipetag.cpp create mode 100644 model/recipe/tags/recipetag.h diff --git a/RecipeDB.pro b/RecipeDB.pro index 7c40f21..a84d67e 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -21,7 +21,8 @@ SOURCES += SQLite/sqlite3.c \ model/recipe/ingredients/unitofmeasure.cpp \ model/recipe/ingredients/ingredient.cpp \ model/recipe/ingredients/ingredientlistmodel.cpp \ - model/recipe/ingredients/recipeingredient.cpp + model/recipe/ingredients/recipeingredient.cpp \ + model/recipe/tags/recipetag.cpp HEADERS += SQLite/sqlite3.h \ SQLite/sqlite3ext.h \ @@ -33,7 +34,8 @@ HEADERS += SQLite/sqlite3.h \ model/recipe/ingredients/unitofmeasure.h \ model/recipe/ingredients/ingredient.h \ model/recipe/ingredients/ingredientlistmodel.h \ - model/recipe/ingredients/recipeingredient.h + model/recipe/ingredients/recipeingredient.h \ + model/recipe/tags/recipetag.h FORMS += gui/mainwindow.ui diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index bd61d8d..149b3cd 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -2,6 +2,11 @@ Recipe::Recipe(){ //Set default values when none are specified. + this->Recipe("Unnamed Recipe", + vector(), + Instruction(), + QImage(), + vector()) this->name = "Unnamed Recipe"; this->ingredients = vector(); this->instruction = Instruction(); diff --git a/model/recipe/tags/recipetag.cpp b/model/recipe/tags/recipetag.cpp new file mode 100644 index 0000000..c33c6a7 --- /dev/null +++ b/model/recipe/tags/recipetag.cpp @@ -0,0 +1,17 @@ +#include "recipetag.h" + +RecipeTag::RecipeTag(){ + this->RecipeTag(""); +} + +RecipeTag::RecipeTag(string val){ + this->value = val; +} + +RecipeTag::getValue(){ + return this->value; +} + +RecipeTag::setValue(string newValue){ + this->value = newValue; +} diff --git a/model/recipe/tags/recipetag.h b/model/recipe/tags/recipetag.h new file mode 100644 index 0000000..5613af7 --- /dev/null +++ b/model/recipe/tags/recipetag.h @@ -0,0 +1,26 @@ +#ifndef RECIPETAG_H +#define RECIPETAG_H + +#include + +using namespace std; + +/** + * @brief The RecipeTag class is used to represent tags which can be used to categorize recipes for easy retrieval. + */ + +class RecipeTag +{ +public: + RecipeTag(); + RecipeTag(string val); + + //Getters + string getValue(); + //Setters + void setValue(string newValue); +private: + string value; +}; + +#endif // RECIPETAG_H From 7d358d6e55de75838d3dbd74dc1d0eac208767e7 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:37:35 +0100 Subject: [PATCH 05/11] Added getTotalTime() derived getter method. --- model/recipe/recipe.cpp | 48 +++++++++++++++++++++++++---------------- model/recipe/recipe.h | 15 +++++++++---- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index 149b3cd..e468fbc 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -6,19 +6,14 @@ Recipe::Recipe(){ vector(), Instruction(), QImage(), - vector()) - this->name = "Unnamed Recipe"; - this->ingredients = vector(); - this->instruction = Instruction(); - this->image = QImage(); - this->tags = vector(); - this->createdDate = QDate.currentDate(); - this->prepTime = QTime(1, 0); - this->cookTime = QTime(0, 30); - this->servings = 10; + vector(), + QDate.currentDate(), + QTime(1, 0), + QTime(0, 30), + 10.0f); } -Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ +Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ this->name = name; this->ingredients = ingredients; this->instruction = instruction; @@ -30,13 +25,6 @@ Recipe::Recipe(string name, vector ingredients, Instruction in this->servings = servings; } -Recipe::Recipe(string name, vector ingredients, Instruction instruction) -{ - this->name = name; - this->ingredients = ingredients; - this->instruction = instruction; -} - string Recipe::getName(){ return this->name; } @@ -48,3 +36,27 @@ vector Recipe::getIngredients(){ Instruction Recipe::getInstruction(){ return this->instruction; } + +QImage Recipe::getImage(){ + return this->image; +} + +QDate Recipe::getCreatedDate(){ + return this->createdDate; +} + +QTime Recipe::getPrepTime(){ + return this->prepTime; +} + +QTime Recipe::getCookTime(){ + return this->cookTime; +} + +QTime Recipe::getTotalTime(){ + return QTime(this->cookTime.hour() + this->prepTime.hour(), this->cookTime.minute() + this->prepTime.minute(), this->cookTime.second() + this->prepTime.second()); +} + +float Recipe::getServings(){ + return this->servings; +} diff --git a/model/recipe/recipe.h b/model/recipe/recipe.h index 9600bd0..726e5a4 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -9,6 +9,7 @@ #include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/instruction.h" +#include "model/recipe/tags/recipetag.h" using namespace std; @@ -31,23 +32,29 @@ class Recipe public: Recipe(); //Full constructor - Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags); + Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings); //Getters string getName(); vector getIngredients(); Instruction getInstruction(); QImage getImage(); - vector getTags(); + vector getTags(); QDate getCreatedDate(); QTime getPrepTime(); QTime getCookTime(); - QTime getTotalTime(); + QTime getTotalTime(); //Derived method to add prep and cook times. float getServings(); + //Setters void setName(string newName); void addIngredient(RecipeIngredient newIngredient); void setInstruction(Instruction newInstruction); + void setImage(QImage newImage); + void setCreatedDate(QDate newDate); + void setPrepTime(QTime newTime); + void setCookTime(QTime newTime); + void setServings(float newServingsCount); private: //Main information. string name; //The name of the recipe. @@ -55,7 +62,7 @@ private: Instruction instruction; //The instruction HTML document. QImage image; //An image displayed alongside the recipe. //Auxiliary Information. - vector tags; //The list of tags which can be used to categorize the recipe. + vector tags; //The list of tags which can be used to categorize the recipe. QDate createdDate; //The date the recipe was created. QTime prepTime; //The time taken for preparation. QTime cookTime; //The time taken to cook. From cd3f5277853e1f5b26e2da010496ce358cf8e029 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:44:35 +0100 Subject: [PATCH 06/11] Created getters/setters for Recipe Class and cleaned up constructor. --- model/recipe/recipe.cpp | 58 ++++++++++++++++++++++++++++++++++------- model/recipe/recipe.h | 2 ++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index e468fbc..2492254 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -14,15 +14,15 @@ Recipe::Recipe(){ } Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ - this->name = name; - this->ingredients = ingredients; - this->instruction = instruction; - this->image = image; - this->tags = tags; - this->createdDate = createdDate; - this->prepTime = prepTime; - this->cookTime = cookTime; - this->servings = servings; + setName(name); + setIngredients(ingredients); + setInstruction(instruction); + setImage(image); + setTags(tags); + setCreatedDate(createdDate); + setPrepTime(prepTime); + setCookTime(cookTime); + setServings(servings); } string Recipe::getName(){ @@ -60,3 +60,43 @@ QTime Recipe::getTotalTime(){ float Recipe::getServings(){ return this->servings; } + +void Recipe::setName(string newName){ + this->name = newName; +} + +void Recipe::setIngredients(vector ingredients){ + this->ingredients = ingredients; +} + +void Recipe::setTags(vector tags){ + this->tags = tags +} + +void Recipe::addIngredient(RecipeIngredient newIngredient){ + this->ingredients.push_back(newIngredient); +} + +void Recipe::setInstruction(Instruction newInstruction){ + this->instruction = newInstruction; +} + +void Recipe::setImage(QImage newImage){ + this->image = newImage; +} + +void Recipe::setCreatedDate(QDate newDate){ + this->createdDate = newDate; +} + +void Recipe::setPrepTime(QTime newTime){ + this->prepTime = newTime; +} + +void Recipe::setCookTime(QTime newTime){ + this->cookTime = newTime; +} + +void Recipe::setServings(float newServingsCount){ + this->servings = newServingsCount; +} diff --git a/model/recipe/recipe.h b/model/recipe/recipe.h index 726e5a4..df24614 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -48,6 +48,8 @@ public: //Setters void setName(string newName); + void setIngredients(vector ingredients); + void setTags(vector tags); void addIngredient(RecipeIngredient newIngredient); void setInstruction(Instruction newInstruction); void setImage(QImage newImage); From b6093aeee96c304fe757cf236ac64159784e07f4 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:48:22 +0100 Subject: [PATCH 07/11] Cleaned up getters/setters for RecipeIngredient. --- model/recipe/ingredients/recipeingredient.cpp | 14 +++++++++++--- model/recipe/ingredients/recipeingredient.h | 14 +++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/model/recipe/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp index c7d3898..52fe6bc 100644 --- a/model/recipe/ingredients/recipeingredient.cpp +++ b/model/recipe/ingredients/recipeingredient.cpp @@ -1,11 +1,11 @@ #include "model/recipe/ingredients/recipeingredient.h" -RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, UnitOfMeasure unit) : Ingredient(id, name, foodGroup){ +RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, float quantity, UnitOfMeasure unit) : Ingredient(id, name, foodGroup){ setQuantity(quantity); setUnit(unit); } -RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit){ +RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit){ setId(i.getId()); setName(i.getName()); setFoodGroup(i.getFoodGroup()); @@ -13,11 +13,19 @@ RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure uni setUnit(unit); } +float RecipeIngredient::getQuantity(){ + return this->quantity; +} + +UnitOfMeasure RecipeIngredient::getUnit(){ + return this->unit; +} + string RecipeIngredient::getComment(){ return this->comment; } -void RecipeIngredient::setQuantity(int newQuantity){ +void RecipeIngredient::setQuantity(float newQuantity){ this->quantity = newQuantity; } diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h index 8a75c0e..491d20e 100644 --- a/model/recipe/ingredients/recipeingredient.h +++ b/model/recipe/ingredients/recipeingredient.h @@ -15,18 +15,22 @@ using namespace std; class RecipeIngredient : public Ingredient { public: - RecipeIngredient(int id, string name, string foodGroup, int quantity, UnitOfMeasure unit); - RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit); + //Constructor for new RecipeIngredient without starting child ingredient. + RecipeIngredient(int id, string name, string foodGroup, float quantity, UnitOfMeasure unit); + //Constructor using data from a child ingredient. + RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit); - int getQuantity(); + //Getters + float getQuantity(); UnitOfMeasure getUnit(); string getComment(); - void setQuantity(int newQuantity); + //Setters + void setQuantity(float newQuantity); void setUnit(UnitOfMeasure newUnit); void setComment(string newComment); private: - int quantity; + float quantity; UnitOfMeasure unit; string comment; }; From 30df250c7ca6cb2dcd9cbdb7394b33ac256936ce Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 19:53:03 +0100 Subject: [PATCH 08/11] Removed ID from Ingredient. --- model/recipe/ingredients/ingredient.cpp | 12 +----------- model/recipe/ingredients/ingredient.h | 7 +++---- model/recipe/ingredients/recipeingredient.cpp | 3 +-- model/recipe/ingredients/recipeingredient.h | 2 +- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/model/recipe/ingredients/ingredient.cpp b/model/recipe/ingredients/ingredient.cpp index f0d2cf0..2ce1d2b 100644 --- a/model/recipe/ingredients/ingredient.cpp +++ b/model/recipe/ingredients/ingredient.cpp @@ -1,21 +1,15 @@ #include "model/recipe/ingredients/ingredient.h" Ingredient::Ingredient(){ - setId(-1); setName("NULL"); setFoodGroup("NULL"); } -Ingredient::Ingredient(int id, string name, string foodGroup){ - setId(id); +Ingredient::Ingredient(string name, string foodGroup){ setName(name); setFoodGroup(foodGroup); } -int Ingredient::getId(){ - return this->id; -} - string Ingredient::getName(){ return this->name; } @@ -24,10 +18,6 @@ string Ingredient::getFoodGroup(){ return this->foodGroup; } -void Ingredient::setId(int newId){ - this->id = newId; -} - void Ingredient::setName(string newName){ this->name = newName; } diff --git a/model/recipe/ingredients/ingredient.h b/model/recipe/ingredients/ingredient.h index 5aace81..4444ad0 100644 --- a/model/recipe/ingredients/ingredient.h +++ b/model/recipe/ingredients/ingredient.h @@ -14,17 +14,16 @@ class Ingredient { public: Ingredient(); - Ingredient(int id, string name, string foodGroup); + Ingredient(string name, string foodGroup); - int getId(); + //Getters string getName(); string getFoodGroup(); - void setId(int newId); + //Setters void setName(string newName); void setFoodGroup(string newFoodGroup); protected: - int id; string name; string foodGroup; }; diff --git a/model/recipe/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp index 52fe6bc..e34d299 100644 --- a/model/recipe/ingredients/recipeingredient.cpp +++ b/model/recipe/ingredients/recipeingredient.cpp @@ -1,12 +1,11 @@ #include "model/recipe/ingredients/recipeingredient.h" -RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, float quantity, UnitOfMeasure unit) : Ingredient(id, name, foodGroup){ +RecipeIngredient::RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit) : Ingredient(name, foodGroup){ setQuantity(quantity); setUnit(unit); } RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit){ - setId(i.getId()); setName(i.getName()); setFoodGroup(i.getFoodGroup()); setQuantity(quantity); diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h index 491d20e..ea3ceb5 100644 --- a/model/recipe/ingredients/recipeingredient.h +++ b/model/recipe/ingredients/recipeingredient.h @@ -16,7 +16,7 @@ class RecipeIngredient : public Ingredient { public: //Constructor for new RecipeIngredient without starting child ingredient. - RecipeIngredient(int id, string name, string foodGroup, float quantity, UnitOfMeasure unit); + RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit); //Constructor using data from a child ingredient. RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit); From c7072f949f340042f13e4e7a795ea733f9b3da1d Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 20:00:59 +0100 Subject: [PATCH 09/11] Added getters/setters to Instruction. --- model/recipe/instruction.cpp | 17 ++++++++++++++--- model/recipe/instruction.h | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/model/recipe/instruction.cpp b/model/recipe/instruction.cpp index 2914bd7..e77d872 100644 --- a/model/recipe/instruction.cpp +++ b/model/recipe/instruction.cpp @@ -1,6 +1,17 @@ #include "model/recipe/instruction.h" -Instruction::Instruction() -{ - +Instruction::Instruction(){ + setHTML(""); +} + +Instruction::Instruction(string text){ + setHTML(text); +} + +string Instruction::getHTML(){ + return this->htmlText; +} + +void Instruction::setHTML(string newText){ + this->htmlText = newText; } diff --git a/model/recipe/instruction.h b/model/recipe/instruction.h index 3698c64..1749a74 100644 --- a/model/recipe/instruction.h +++ b/model/recipe/instruction.h @@ -1,11 +1,27 @@ #ifndef INSTRUCTION_H #define INSTRUCTION_H +#include + +using namespace std; + +/** + * @brief The Instruction class is meant to hold an HTML document in string form, which holds formatted text as the instructions for the recipe. + */ class Instruction { public: Instruction(); + Instruction(string text); + + //Getters + string getHTML(); + + //Setters + void setHTML(string newText); +private: + string htmlText; }; -#endif // INSTRUCTION_H \ No newline at end of file +#endif // INSTRUCTION_H From 2e42bafae33784cf4ea3cab30606c338c012dc84 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 20:27:27 +0100 Subject: [PATCH 10/11] Fixed default constructors, tested compilability. --- main.cpp | 7 +++++++ model/recipe/ingredients/unitofmeasure.cpp | 4 ++++ model/recipe/ingredients/unitofmeasure.h | 3 +++ model/recipe/recipe.cpp | 19 +++++-------------- model/recipe/recipe.h | 3 ++- model/recipe/tags/recipetag.cpp | 8 ++++---- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/main.cpp b/main.cpp index 4f87ea1..84928f5 100644 --- a/main.cpp +++ b/main.cpp @@ -11,5 +11,12 @@ int main(int argc, char *argv[]) Database db("test.db"); + vector ri; + ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c"))); + + + + Recipe rec("Example", ri, Instruction("Hello world"), QImage(), vector(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f); + return a.exec(); } diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp index 16d82ef..77b395e 100644 --- a/model/recipe/ingredients/unitofmeasure.cpp +++ b/model/recipe/ingredients/unitofmeasure.cpp @@ -6,6 +6,10 @@ UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){ this->abbreviation = abbreviation; } +UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){ + //Default constructor initializes all fields to empty strings. +} + string UnitOfMeasure::getName(){ return this->name; } diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h index 62c633d..f835cec 100644 --- a/model/recipe/ingredients/unitofmeasure.h +++ b/model/recipe/ingredients/unitofmeasure.h @@ -12,7 +12,10 @@ using namespace std; class UnitOfMeasure { public: + //Full constructor. UnitOfMeasure(string name, string plural, string abbreviation); + //Constructor with default values. + UnitOfMeasure(); //Getters string getName(); diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index 2492254..4f642f4 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -1,18 +1,5 @@ #include "model/recipe/recipe.h" -Recipe::Recipe(){ - //Set default values when none are specified. - this->Recipe("Unnamed Recipe", - vector(), - Instruction(), - QImage(), - vector(), - QDate.currentDate(), - QTime(1, 0), - QTime(0, 30), - 10.0f); -} - Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ setName(name); setIngredients(ingredients); @@ -25,6 +12,10 @@ Recipe::Recipe(string name, vector ingredients, Instruction in setServings(servings); } +Recipe::Recipe() : Recipe::Recipe("Unnamed Recipe", vector(), Instruction(), QImage(), vector(), QDate::currentDate(), QTime(1, 0), QTime(0, 30), 10.0f){ + //Set default values when none are specified. +} + string Recipe::getName(){ return this->name; } @@ -70,7 +61,7 @@ void Recipe::setIngredients(vector ingredients){ } void Recipe::setTags(vector tags){ - this->tags = tags + this->tags = tags; } void Recipe::addIngredient(RecipeIngredient newIngredient){ diff --git a/model/recipe/recipe.h b/model/recipe/recipe.h index df24614..84d5fad 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -30,9 +30,10 @@ using namespace std; class Recipe { public: - Recipe(); //Full constructor Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings); + //Constructor with default values. + Recipe(); //Getters string getName(); diff --git a/model/recipe/tags/recipetag.cpp b/model/recipe/tags/recipetag.cpp index c33c6a7..22cd27d 100644 --- a/model/recipe/tags/recipetag.cpp +++ b/model/recipe/tags/recipetag.cpp @@ -1,17 +1,17 @@ #include "recipetag.h" -RecipeTag::RecipeTag(){ - this->RecipeTag(""); +RecipeTag::RecipeTag() : RecipeTag(""){ + //Default constructor sets value to empty string. } RecipeTag::RecipeTag(string val){ this->value = val; } -RecipeTag::getValue(){ +string RecipeTag::getValue(){ return this->value; } -RecipeTag::setValue(string newValue){ +void RecipeTag::setValue(string newValue){ this->value = newValue; } From e4dcd17e3e44c128948042e2e4db7900b3608068 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 20:39:24 +0100 Subject: [PATCH 11/11] Now able to load parts of a Recipe into the user interface. --- main.cpp | 7 ------- userInterface/mainwindow.cpp | 12 ++++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 84928f5..4f87ea1 100644 --- a/main.cpp +++ b/main.cpp @@ -11,12 +11,5 @@ int main(int argc, char *argv[]) Database db("test.db"); - vector ri; - ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c"))); - - - - Recipe rec("Example", ri, Instruction("Hello world"), QImage(), vector(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f); - return a.exec(); } diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index 59f2c18..55c857c 100644 --- a/userInterface/mainwindow.cpp +++ b/userInterface/mainwindow.cpp @@ -5,6 +5,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); + + //TESTING CODE + vector ri; + ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c"))); + + Recipe rec("Example", ri, Instruction("BOLDiTaLiCs"), QImage(), vector(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f); + + this->loadFromRecipe(rec); } MainWindow::~MainWindow(){ @@ -22,9 +30,9 @@ void MainWindow::setRecipeName(string name){ } void MainWindow::setInstruction(Instruction instruction){ - + ui->instructionsTextEdit->setHtml(QString::fromStdString(instruction.getHTML())); } void MainWindow::setIngredients(vector ingredients){ - + ///TODO: Implement this. }