Added getTotalTime() derived getter method.

This commit is contained in:
Andrew Lalis 2018-02-12 19:37:35 +01:00
parent c928533e6a
commit 7d358d6e55
2 changed files with 41 additions and 22 deletions

View File

@ -6,19 +6,14 @@ Recipe::Recipe(){
vector<RecipeIngredient>(), vector<RecipeIngredient>(),
Instruction(), Instruction(),
QImage(), QImage(),
vector<string>()) vector<RecipeTag>(),
this->name = "Unnamed Recipe"; QDate.currentDate(),
this->ingredients = vector<RecipeIngredient>(); QTime(1, 0),
this->instruction = Instruction(); QTime(0, 30),
this->image = QImage(); 10.0f);
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){ Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){
this->name = name; this->name = name;
this->ingredients = ingredients; this->ingredients = ingredients;
this->instruction = instruction; this->instruction = instruction;
@ -30,13 +25,6 @@ Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction in
this->servings = servings; this->servings = servings;
} }
Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction)
{
this->name = name;
this->ingredients = ingredients;
this->instruction = instruction;
}
string Recipe::getName(){ string Recipe::getName(){
return this->name; return this->name;
} }
@ -48,3 +36,27 @@ vector<RecipeIngredient> Recipe::getIngredients(){
Instruction Recipe::getInstruction(){ Instruction Recipe::getInstruction(){
return this->instruction; 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;
}

View File

@ -9,6 +9,7 @@
#include "model/recipe/ingredients/recipeingredient.h" #include "model/recipe/ingredients/recipeingredient.h"
#include "model/recipe/instruction.h" #include "model/recipe/instruction.h"
#include "model/recipe/tags/recipetag.h"
using namespace std; using namespace std;
@ -31,23 +32,29 @@ class Recipe
public: public:
Recipe(); Recipe();
//Full constructor //Full constructor
Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<string> tags); Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings);
//Getters //Getters
string getName(); string getName();
vector<RecipeIngredient> getIngredients(); vector<RecipeIngredient> getIngredients();
Instruction getInstruction(); Instruction getInstruction();
QImage getImage(); QImage getImage();
vector<string> getTags(); vector<RecipeTag> getTags();
QDate getCreatedDate(); QDate getCreatedDate();
QTime getPrepTime(); QTime getPrepTime();
QTime getCookTime(); QTime getCookTime();
QTime getTotalTime(); QTime getTotalTime(); //Derived method to add prep and cook times.
float getServings(); float getServings();
//Setters //Setters
void setName(string newName); void setName(string newName);
void addIngredient(RecipeIngredient newIngredient); void addIngredient(RecipeIngredient newIngredient);
void setInstruction(Instruction newInstruction); 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: private:
//Main information. //Main information.
string name; //The name of the recipe. string name; //The name of the recipe.
@ -55,7 +62,7 @@ private:
Instruction instruction; //The instruction HTML document. Instruction instruction; //The instruction HTML document.
QImage image; //An image displayed alongside the recipe. QImage image; //An image displayed alongside the recipe.
//Auxiliary Information. //Auxiliary Information.
vector<string> tags; //The list of tags which can be used to categorize the recipe. vector<RecipeTag> tags; //The list of tags which can be used to categorize the recipe.
QDate createdDate; //The date the recipe was created. QDate createdDate; //The date the recipe was created.
QTime prepTime; //The time taken for preparation. QTime prepTime; //The time taken for preparation.
QTime cookTime; //The time taken to cook. QTime cookTime; //The time taken to cook.