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/RecipeDB.pro b/RecipeDB.pro index cfc7f09..a84d67e 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -13,24 +13,29 @@ 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 \ + model/recipe/tags/recipetag.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 \ + model/recipe/tags/recipetag.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 63% rename from model/recipe/ingredient.cpp rename to model/recipe/ingredients/ingredient.cpp index 5cdcc53..2ce1d2b 100644 --- a/model/recipe/ingredient.cpp +++ b/model/recipe/ingredients/ingredient.cpp @@ -1,21 +1,15 @@ -#include "headers/ingredient.h" +#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/ingredient.h b/model/recipe/ingredients/ingredient.h similarity index 50% rename from model/recipe/ingredient.h rename to model/recipe/ingredients/ingredient.h index 2f4b0d0..4444ad0 100644 --- a/model/recipe/ingredient.h +++ b/model/recipe/ingredients/ingredient.h @@ -5,21 +5,25 @@ 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: 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/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/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp new file mode 100644 index 0000000..e34d299 --- /dev/null +++ b/model/recipe/ingredients/recipeingredient.cpp @@ -0,0 +1,37 @@ +#include "model/recipe/ingredients/recipeingredient.h" + +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){ + setName(i.getName()); + setFoodGroup(i.getFoodGroup()); + setQuantity(quantity); + setUnit(unit); +} + +float RecipeIngredient::getQuantity(){ + return this->quantity; +} + +UnitOfMeasure RecipeIngredient::getUnit(){ + return this->unit; +} + +string RecipeIngredient::getComment(){ + 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; +} diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h new file mode 100644 index 0000000..ea3ceb5 --- /dev/null +++ b/model/recipe/ingredients/recipeingredient.h @@ -0,0 +1,38 @@ +#ifndef RECIPEINGREDIENT_H +#define RECIPEINGREDIENT_H + +#include + +#include "model/recipe/ingredients/ingredient.h" +#include "model/recipe/ingredients/unitofmeasure.h" + +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: + //Constructor for new RecipeIngredient without starting child ingredient. + RecipeIngredient(string name, string foodGroup, float quantity, UnitOfMeasure unit); + //Constructor using data from a child ingredient. + RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit); + + //Getters + float getQuantity(); + UnitOfMeasure getUnit(); + string getComment(); + + //Setters + void setQuantity(float newQuantity); + void setUnit(UnitOfMeasure newUnit); + void setComment(string newComment); +private: + float quantity; + UnitOfMeasure unit; + string comment; +}; + +#endif // RECIPEINGREDIENT_H diff --git a/model/recipe/ingredients/unitofmeasure.cpp b/model/recipe/ingredients/unitofmeasure.cpp new file mode 100644 index 0000000..77b395e --- /dev/null +++ b/model/recipe/ingredients/unitofmeasure.cpp @@ -0,0 +1,23 @@ +#include "unitofmeasure.h" + +UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){ + this->name = name; + this->plural = plural; + this->abbreviation = abbreviation; +} + +UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){ + //Default constructor initializes all fields to empty strings. +} + +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 new file mode 100644 index 0000000..f835cec --- /dev/null +++ b/model/recipe/ingredients/unitofmeasure.h @@ -0,0 +1,30 @@ +#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: + //Full constructor. + UnitOfMeasure(string name, string plural, string abbreviation); + //Constructor with default values. + UnitOfMeasure(); + + //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. +}; + +#endif // UNITOFMEASURE_H diff --git a/model/recipe/instruction.cpp b/model/recipe/instruction.cpp index 4da0c44..e77d872 100644 --- a/model/recipe/instruction.cpp +++ b/model/recipe/instruction.cpp @@ -1,6 +1,17 @@ -#include "headers/instruction.h" - -Instruction::Instruction() -{ +#include "model/recipe/instruction.h" +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 diff --git a/model/recipe/recipe.cpp b/model/recipe/recipe.cpp index 948e231..4f642f4 100644 --- a/model/recipe/recipe.cpp +++ b/model/recipe/recipe.cpp @@ -1,25 +1,93 @@ #include "model/recipe/recipe.h" -Recipe::Recipe(){ - this->name = "NULL"; - this->ingredients = vector(); - this->instructions = vector(); +Recipe::Recipe(string name, vector ingredients, Instruction instruction, QImage image, vector tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){ + setName(name); + setIngredients(ingredients); + setInstruction(instruction); + setImage(image); + setTags(tags); + setCreatedDate(createdDate); + setPrepTime(prepTime); + setCookTime(cookTime); + setServings(servings); } -Recipe::Recipe(string name, vector ingredients, vector instructions){ - this->name = name; - this->ingredients = ingredients; - this->instructions = instructions; +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; } -vector Recipe::getIngredients(){ +vector Recipe::getIngredients(){ return this->ingredients; } -vector Recipe::getInstructions(){ - return this->instructions; +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; +} + +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 4cf3b9f..84d5fad 100644 --- a/model/recipe/recipe.h +++ b/model/recipe/recipe.h @@ -3,28 +3,73 @@ #include #include -#include +#include +#include +#include -#include "model/recipe/ingredient.h" +#include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/instruction.h" +#include "model/recipe/tags/recipetag.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: + //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(); - Recipe(string name, vector ingredients, vector instructions); + //Getters string getName(); - vector getIngredients(); - vector getInstructions(); -private: - string name; - vector tags; - vector ingredients; - vector instructions; + vector getIngredients(); + Instruction getInstruction(); + QImage getImage(); + vector getTags(); + QDate getCreatedDate(); + QTime getPrepTime(); + QTime getCookTime(); + QTime getTotalTime(); //Derived method to add prep and cook times. + float getServings(); + //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); + 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. + 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 diff --git a/model/recipe/recipeingredient.cpp b/model/recipe/recipeingredient.cpp deleted file mode 100644 index ad43dfa..0000000 --- a/model/recipe/recipeingredient.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "headers/recipeingredient.h" - -RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit) : Ingredient(id, name, foodGroup){ - setQuantity(quantity); - setUnit(unit); -} - -RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, string unit){ - setId(i.getId()); - setName(i.getName()); - setFoodGroup(i.getFoodGroup()); - setQuantity(quantity); - setUnit(unit); -} - -string RecipeIngredient::getComment(){ - return this->comment; -} - -void RecipeIngredient::setQuantity(int newQuantity){ - this->quantity = newQuantity; -} - -void RecipeIngredient::setUnit(string newUnit){ - this->unit = newUnit; -} - -void RecipeIngredient::setComment(string newComment){ - this->comment = newComment; -} diff --git a/model/recipe/recipeingredient.h b/model/recipe/recipeingredient.h deleted file mode 100644 index 388a1a3..0000000 --- a/model/recipe/recipeingredient.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef RECIPEINGREDIENT_H -#define RECIPEINGREDIENT_H - -#include - -#include "headers/ingredient.h" - -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); - - int getQuantity(); - string getUnit(); - string getComment(); - - void setQuantity(int newQuantity); - void setUnit(string newUnit); - void setComment(string newComment); -private: - int quantity; - string unit; - string comment; -}; - -#endif // RECIPEINGREDIENT_H diff --git a/model/recipe/tags/recipetag.cpp b/model/recipe/tags/recipetag.cpp new file mode 100644 index 0000000..22cd27d --- /dev/null +++ b/model/recipe/tags/recipetag.cpp @@ -0,0 +1,17 @@ +#include "recipetag.h" + +RecipeTag::RecipeTag() : RecipeTag(""){ + //Default constructor sets value to empty string. +} + +RecipeTag::RecipeTag(string val){ + this->value = val; +} + +string RecipeTag::getValue(){ + return this->value; +} + +void 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 diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index eacb5ba..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(){ @@ -13,7 +21,7 @@ MainWindow::~MainWindow(){ void MainWindow::loadFromRecipe(Recipe recipe){ setRecipeName(recipe.getName()); - setInstructions(recipe.getInstructions()); + setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); } @@ -21,10 +29,10 @@ void MainWindow::setRecipeName(string name){ ui->recipeNameLabel->setText(QString::fromStdString(name)); } -void MainWindow::setInstructions(vector instructions){ - +void MainWindow::setInstruction(Instruction instruction){ + ui->instructionsTextEdit->setHtml(QString::fromStdString(instruction.getHTML())); } -void MainWindow::setIngredients(vector ingredients){ - +void MainWindow::setIngredients(vector ingredients){ + ///TODO: Implement this. } 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