Fixed default constructors, tested compilability.

This commit is contained in:
Andrew Lalis 2018-02-12 20:27:27 +01:00
parent c7072f949f
commit 2e42bafae3
6 changed files with 25 additions and 19 deletions

View File

@ -11,5 +11,12 @@ int main(int argc, char *argv[])
Database db("test.db"); Database db("test.db");
vector<RecipeIngredient> ri;
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c")));
Recipe rec("Example", ri, Instruction("Hello world"), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f);
return a.exec(); return a.exec();
} }

View File

@ -6,6 +6,10 @@ UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){
this->abbreviation = abbreviation; this->abbreviation = abbreviation;
} }
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){
//Default constructor initializes all fields to empty strings.
}
string UnitOfMeasure::getName(){ string UnitOfMeasure::getName(){
return this->name; return this->name;
} }

View File

@ -12,7 +12,10 @@ using namespace std;
class UnitOfMeasure class UnitOfMeasure
{ {
public: public:
//Full constructor.
UnitOfMeasure(string name, string plural, string abbreviation); UnitOfMeasure(string name, string plural, string abbreviation);
//Constructor with default values.
UnitOfMeasure();
//Getters //Getters
string getName(); string getName();

View File

@ -1,18 +1,5 @@
#include "model/recipe/recipe.h" #include "model/recipe/recipe.h"
Recipe::Recipe(){
//Set default values when none are specified.
this->Recipe("Unnamed Recipe",
vector<RecipeIngredient>(),
Instruction(),
QImage(),
vector<RecipeTag>(),
QDate.currentDate(),
QTime(1, 0),
QTime(0, 30),
10.0f);
}
Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> 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){
setName(name); setName(name);
setIngredients(ingredients); setIngredients(ingredients);
@ -25,6 +12,10 @@ Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction in
setServings(servings); setServings(servings);
} }
Recipe::Recipe() : Recipe::Recipe("Unnamed Recipe", vector<RecipeIngredient>(), Instruction(), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(1, 0), QTime(0, 30), 10.0f){
//Set default values when none are specified.
}
string Recipe::getName(){ string Recipe::getName(){
return this->name; return this->name;
} }
@ -70,7 +61,7 @@ void Recipe::setIngredients(vector<RecipeIngredient> ingredients){
} }
void Recipe::setTags(vector<RecipeTag> tags){ void Recipe::setTags(vector<RecipeTag> tags){
this->tags = tags this->tags = tags;
} }
void Recipe::addIngredient(RecipeIngredient newIngredient){ void Recipe::addIngredient(RecipeIngredient newIngredient){

View File

@ -30,9 +30,10 @@ using namespace std;
class Recipe class Recipe
{ {
public: public:
Recipe();
//Full constructor //Full constructor
Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings); Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings);
//Constructor with default values.
Recipe();
//Getters //Getters
string getName(); string getName();

View File

@ -1,17 +1,17 @@
#include "recipetag.h" #include "recipetag.h"
RecipeTag::RecipeTag(){ RecipeTag::RecipeTag() : RecipeTag(""){
this->RecipeTag(""); //Default constructor sets value to empty string.
} }
RecipeTag::RecipeTag(string val){ RecipeTag::RecipeTag(string val){
this->value = val; this->value = val;
} }
RecipeTag::getValue(){ string RecipeTag::getValue(){
return this->value; return this->value;
} }
RecipeTag::setValue(string newValue){ void RecipeTag::setValue(string newValue){
this->value = newValue; this->value = newValue;
} }