From 2e42bafae33784cf4ea3cab30606c338c012dc84 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 12 Feb 2018 20:27:27 +0100 Subject: [PATCH] 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; }