Ignoring .autosave files, added fields to recipe object, improved unit of measure.

This commit is contained in:
Andrew Lalis 2018-02-12 19:20:38 +01:00
parent 45db82f0d5
commit c09f29930b
7 changed files with 81 additions and 21 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.pro *.pro
*.pro.user *.pro.user
*.autosave

View File

@ -1,11 +1,11 @@
#include "model/recipe/ingredients/recipeingredient.h" #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); setQuantity(quantity);
setUnit(unit); setUnit(unit);
} }
RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, string unit){ RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit){
setId(i.getId()); setId(i.getId());
setName(i.getName()); setName(i.getName());
setFoodGroup(i.getFoodGroup()); setFoodGroup(i.getFoodGroup());
@ -21,7 +21,7 @@ void RecipeIngredient::setQuantity(int newQuantity){
this->quantity = newQuantity; this->quantity = newQuantity;
} }
void RecipeIngredient::setUnit(string newUnit){ void RecipeIngredient::setUnit(UnitOfMeasure newUnit){
this->unit = newUnit; this->unit = newUnit;
} }

View File

@ -4,6 +4,7 @@
#include <string> #include <string>
#include "model/recipe/ingredients/ingredient.h" #include "model/recipe/ingredients/ingredient.h"
#include "model/recipe/ingredients/unitofmeasure.h"
using namespace std; using namespace std;
@ -14,19 +15,19 @@ using namespace std;
class RecipeIngredient : public Ingredient class RecipeIngredient : public Ingredient
{ {
public: public:
RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit); RecipeIngredient(int id, string name, string foodGroup, int quantity, UnitOfMeasure unit);
RecipeIngredient(Ingredient i, int quantity, string unit); RecipeIngredient(Ingredient i, int quantity, UnitOfMeasure unit);
int getQuantity(); int getQuantity();
string getUnit(); UnitOfMeasure getUnit();
string getComment(); string getComment();
void setQuantity(int newQuantity); void setQuantity(int newQuantity);
void setUnit(string newUnit); void setUnit(UnitOfMeasure newUnit);
void setComment(string newComment); void setComment(string newComment);
private: private:
int quantity; int quantity;
string unit; UnitOfMeasure unit;
string comment; string comment;
}; };

View File

@ -1,6 +1,19 @@
#include "unitofmeasure.h" #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;
} }

View File

@ -12,12 +12,16 @@ using namespace std;
class UnitOfMeasure class UnitOfMeasure
{ {
public: public:
UnitOfMeasure(); UnitOfMeasure(string name, string plural, string abbreviation);
//Getters
string getName();
string getNamePlural();
string getAbbreviation();
private: private:
string name; //The name of the unit of measure. string name; //The name of the unit of measure.
string plural; //The plural name. string plural; //The plural name.
string abbreviation; //A short version of the unit. 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 #endif // UNITOFMEASURE_H

View File

@ -1,9 +1,28 @@
#include "model/recipe/recipe.h" #include "model/recipe/recipe.h"
Recipe::Recipe(){ Recipe::Recipe(){
this->name = "NULL"; //Set default values when none are specified.
this->name = "Unnamed Recipe";
this->ingredients = vector<RecipeIngredient>(); this->ingredients = vector<RecipeIngredient>();
this->instruction = Instruction(); this->instruction = Instruction();
this->image = QImage();
this->tags = vector<string>();
this->createdDate = QDate.currentDate();
this->prepTime = QTime(1, 0);
this->cookTime = QTime(0, 30);
this->servings = 10;
}
Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<string> 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<RecipeIngredient> ingredients, Instruction instruction) Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction)

View File

@ -3,6 +3,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <QDate>
#include <QTime>
#include <QImage>
#include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/ingredients/recipeingredient.h"
#include "model/recipe/instruction.h" #include "model/recipe/instruction.h"
@ -27,17 +30,36 @@ class Recipe
{ {
public: public:
Recipe(); Recipe();
Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction); //Full constructor
Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<string> tags);
//Getters
string getName(); string getName();
vector<RecipeIngredient> getIngredients(); vector<RecipeIngredient> getIngredients();
Instruction getInstruction(); Instruction getInstruction();
QImage getImage();
vector<string> 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: private:
string name; //Main information.
vector<string> tags; string name; //The name of the recipe.
vector<RecipeIngredient> ingredients; vector<RecipeIngredient> ingredients; //The list of ingredients in the recipe.
Instruction instruction; Instruction instruction; //The instruction HTML document.
QImage image; //An image displayed alongside the recipe.
//Auxiliary Information.
vector<string> 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 #endif // RECIPE_H