First Interaction with User Interface #1

Merged
andrewlalis merged 11 commits from development into master 2018-02-12 19:40:45 +00:00
22 changed files with 383 additions and 118 deletions

1
.gitignore vendored
View File

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

View File

@ -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

View File

@ -432,6 +432,9 @@
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="autoFormatting">
<set>QTextEdit::AutoNone</set>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::WidgetWidth</enum>
</property>

View File

@ -5,7 +5,7 @@
#include <vector>
#include "SQLite/sqlite3.h"
#include "model/recipe/ingredient.h"
#include "model/recipe/ingredients/ingredient.h"
using namespace std;

View File

@ -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;
}

View File

@ -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;
};

View File

@ -1,4 +1,4 @@
#include "model/recipe/ingredientlistmodel.h"
#include "model/recipe/ingredients/ingredientlistmodel.h"
IngredientListModel::IngredientListModel(){
this->ingredients = vector<Ingredient>();

View File

@ -3,7 +3,7 @@
#include <QAbstractListModel>
#include "model/recipe/ingredient.h"
#include "model/recipe/ingredients/ingredient.h"
class IngredientListModel : public QAbstractListModel
{

View File

@ -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;
}

View File

@ -0,0 +1,38 @@
#ifndef RECIPEINGREDIENT_H
#define RECIPEINGREDIENT_H
#include <string>
#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

View File

@ -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;
}

View File

@ -0,0 +1,30 @@
#ifndef UNITOFMEASURE_H
#define UNITOFMEASURE_H
#include <string>
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

View File

@ -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;
}

View File

@ -1,11 +1,27 @@
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
#include <string>
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

View File

@ -1,25 +1,93 @@
#include "model/recipe/recipe.h"
Recipe::Recipe(){
this->name = "NULL";
this->ingredients = vector<Ingredient>();
this->instructions = vector<Instruction>();
Recipe::Recipe(string name, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> 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<Ingredient> ingredients, vector<Instruction> instructions){
this->name = name;
this->ingredients = ingredients;
this->instructions = instructions;
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(){
return this->name;
}
vector<Ingredient> Recipe::getIngredients(){
vector<RecipeIngredient> Recipe::getIngredients(){
return this->ingredients;
}
vector<Instruction> 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<RecipeIngredient> ingredients){
this->ingredients = ingredients;
}
void Recipe::setTags(vector<RecipeTag> 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;
}

View File

@ -3,28 +3,73 @@
#include <vector>
#include <string>
#include <hash_map>
#include <QDate>
#include <QTime>
#include <QImage>
#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<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings);
//Constructor with default values.
Recipe();
Recipe(string name, vector<Ingredient> ingredients, vector<Instruction> instructions);
//Getters
string getName();
vector<Ingredient> getIngredients();
vector<Instruction> getInstructions();
private:
string name;
vector<string> tags;
vector<Ingredient> ingredients;
vector<Instruction> instructions;
vector<RecipeIngredient> getIngredients();
Instruction getInstruction();
QImage getImage();
vector<RecipeTag> 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<RecipeIngredient> ingredients);
void setTags(vector<RecipeTag> 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<RecipeIngredient> 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<RecipeTag> 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

View File

@ -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;
}

View File

@ -1,29 +0,0 @@
#ifndef RECIPEINGREDIENT_H
#define RECIPEINGREDIENT_H
#include <string>
#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

View File

@ -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;
}

View File

@ -0,0 +1,26 @@
#ifndef RECIPETAG_H
#define RECIPETAG_H
#include <string>
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

View File

@ -5,6 +5,14 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
ui->setupUi(this);
//TESTING CODE
vector<RecipeIngredient> ri;
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c")));
Recipe rec("Example", ri, Instruction("<b>BOLD</b><i>iTaLiCs</i>"), QImage(), vector<RecipeTag>(), 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<Instruction> instructions){
void MainWindow::setInstruction(Instruction instruction){
ui->instructionsTextEdit->setHtml(QString::fromStdString(instruction.getHTML()));
}
void MainWindow::setIngredients(vector<Ingredient> ingredients){
void MainWindow::setIngredients(vector<RecipeIngredient> ingredients){
///TODO: Implement this.
}

View File

@ -3,6 +3,7 @@
#include <QMainWindow>
#include <string>
#include <QAbstractListModel>
#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<Instruction> instructions);
void setIngredients(vector<Ingredient> ingredients);
void setInstruction(Instruction instruction);
void setIngredients(vector<RecipeIngredient> ingredients);
};
#endif // MAINWINDOW_H