Merge pull request #2 from andrewlalis/development
Improvements in Code Quality, all basic aspects of a recipe can be displayed.
This commit is contained in:
commit
3ef03e2887
|
@ -30,7 +30,6 @@ HEADERS += SQLite/sqlite3.h \
|
|||
model/recipe/recipe.h \
|
||||
userInterface/mainwindow.h \
|
||||
model/database/database.h \
|
||||
model/recipe/ingredientlistmodel.h \
|
||||
model/recipe/ingredients/unitofmeasure.h \
|
||||
model/recipe/ingredients/ingredient.h \
|
||||
model/recipe/ingredients/ingredientlistmodel.h \
|
||||
|
|
|
@ -315,7 +315,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<widget class="QListView" name="ingredientsListView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
Database::Database(string filename){
|
||||
this->filename = filename;
|
||||
openConnection();
|
||||
//TESTING CODE
|
||||
if (tableExists("ingredients")){
|
||||
printf("Ingredients table already exists.\n");
|
||||
} else {
|
||||
|
|
|
@ -10,11 +10,11 @@ Ingredient::Ingredient(string name, string foodGroup){
|
|||
setFoodGroup(foodGroup);
|
||||
}
|
||||
|
||||
string Ingredient::getName(){
|
||||
string Ingredient::getName() const{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
string Ingredient::getFoodGroup(){
|
||||
string Ingredient::getFoodGroup() const{
|
||||
return this->foodGroup;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ public:
|
|||
Ingredient(string name, string foodGroup);
|
||||
|
||||
//Getters
|
||||
string getName();
|
||||
string getFoodGroup();
|
||||
string getName() const;
|
||||
string getFoodGroup() const;
|
||||
|
||||
//Setters
|
||||
void setName(string newName);
|
||||
|
|
|
@ -1,17 +1,27 @@
|
|||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||
|
||||
IngredientListModel::IngredientListModel(){
|
||||
this->ingredients = vector<Ingredient>();
|
||||
this->ingredients = vector<RecipeIngredient>();
|
||||
}
|
||||
|
||||
int IngredientListModel::rowCount(const QModelIndex &parent){
|
||||
int IngredientListModel::rowCount(const QModelIndex &parent) const{
|
||||
return this->ingredients.size();
|
||||
}
|
||||
|
||||
QVariant IngredientListModel::data(const QModelIndex &index, int role){
|
||||
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
||||
int row = index.row();
|
||||
|
||||
switch(role){
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(ingredients[row].getName());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void IngredientListModel::setIngredients(vector<Ingredient> ingredients){
|
||||
void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
|
||||
this->ingredients = ingredients;
|
||||
QModelIndex index = createIndex(0, 0);
|
||||
QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
|
||||
emit dataChanged(index, bottomIndex);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
#define INGREDIENTLISTMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "model/recipe/ingredients/ingredient.h"
|
||||
#include "model/recipe/ingredients/recipeingredient.h"
|
||||
|
||||
class IngredientListModel : public QAbstractListModel
|
||||
{
|
||||
|
@ -11,14 +12,14 @@ public:
|
|||
IngredientListModel();
|
||||
|
||||
//Overridden methods.
|
||||
int rowCount(const QModelIndex &parent = QModelIndex());
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
//Custom methods to handle ingredient data.
|
||||
void setIngredients(vector<Ingredient> ingredients);
|
||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
||||
|
||||
private:
|
||||
vector<Ingredient> ingredients;
|
||||
vector<RecipeIngredient> ingredients;
|
||||
};
|
||||
|
||||
#endif // INGREDIENTLISTMODEL_H
|
||||
|
|
|
@ -12,15 +12,15 @@ RecipeIngredient::RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure u
|
|||
setUnit(unit);
|
||||
}
|
||||
|
||||
float RecipeIngredient::getQuantity(){
|
||||
float RecipeIngredient::getQuantity() const{
|
||||
return this->quantity;
|
||||
}
|
||||
|
||||
UnitOfMeasure RecipeIngredient::getUnit(){
|
||||
UnitOfMeasure RecipeIngredient::getUnit() const{
|
||||
return this->unit;
|
||||
}
|
||||
|
||||
string RecipeIngredient::getComment(){
|
||||
string RecipeIngredient::getComment() const{
|
||||
return this->comment;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ public:
|
|||
RecipeIngredient(Ingredient i, float quantity, UnitOfMeasure unit);
|
||||
|
||||
//Getters
|
||||
float getQuantity();
|
||||
UnitOfMeasure getUnit();
|
||||
string getComment();
|
||||
float getQuantity() const;
|
||||
UnitOfMeasure getUnit() const;
|
||||
string getComment() const;
|
||||
|
||||
//Setters
|
||||
void setQuantity(float newQuantity);
|
||||
|
|
|
@ -10,14 +10,14 @@ UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){
|
|||
//Default constructor initializes all fields to empty strings.
|
||||
}
|
||||
|
||||
string UnitOfMeasure::getName(){
|
||||
string UnitOfMeasure::getName() const{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
string UnitOfMeasure::getNamePlural(){
|
||||
string UnitOfMeasure::getNamePlural() const{
|
||||
return this->plural;
|
||||
}
|
||||
|
||||
string UnitOfMeasure::getAbbreviation(){
|
||||
string UnitOfMeasure::getAbbreviation() const{
|
||||
return this->abbreviation;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ public:
|
|||
UnitOfMeasure();
|
||||
|
||||
//Getters
|
||||
string getName();
|
||||
string getNamePlural();
|
||||
string getAbbreviation();
|
||||
string getName() const;
|
||||
string getNamePlural() const;
|
||||
string getAbbreviation() const;
|
||||
private:
|
||||
string name; //The name of the unit of measure.
|
||||
string plural; //The plural name.
|
||||
|
|
|
@ -8,7 +8,7 @@ Instruction::Instruction(string text){
|
|||
setHTML(text);
|
||||
}
|
||||
|
||||
string Instruction::getHTML(){
|
||||
string Instruction::getHTML() const{
|
||||
return this->htmlText;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
Instruction(string text);
|
||||
|
||||
//Getters
|
||||
string getHTML();
|
||||
string getHTML() const;
|
||||
|
||||
//Setters
|
||||
void setHTML(string newText);
|
||||
|
|
|
@ -16,39 +16,39 @@ Recipe::Recipe() : Recipe::Recipe("Unnamed Recipe", vector<RecipeIngredient>(),
|
|||
//Set default values when none are specified.
|
||||
}
|
||||
|
||||
string Recipe::getName(){
|
||||
string Recipe::getName() const{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
vector<RecipeIngredient> Recipe::getIngredients(){
|
||||
vector<RecipeIngredient> Recipe::getIngredients() const{
|
||||
return this->ingredients;
|
||||
}
|
||||
|
||||
Instruction Recipe::getInstruction(){
|
||||
Instruction Recipe::getInstruction() const{
|
||||
return this->instruction;
|
||||
}
|
||||
|
||||
QImage Recipe::getImage(){
|
||||
QImage Recipe::getImage() const{
|
||||
return this->image;
|
||||
}
|
||||
|
||||
QDate Recipe::getCreatedDate(){
|
||||
QDate Recipe::getCreatedDate() const{
|
||||
return this->createdDate;
|
||||
}
|
||||
|
||||
QTime Recipe::getPrepTime(){
|
||||
QTime Recipe::getPrepTime() const{
|
||||
return this->prepTime;
|
||||
}
|
||||
|
||||
QTime Recipe::getCookTime(){
|
||||
QTime Recipe::getCookTime() const{
|
||||
return this->cookTime;
|
||||
}
|
||||
|
||||
QTime Recipe::getTotalTime(){
|
||||
QTime Recipe::getTotalTime() const{
|
||||
return QTime(this->cookTime.hour() + this->prepTime.hour(), this->cookTime.minute() + this->prepTime.minute(), this->cookTime.second() + this->prepTime.second());
|
||||
}
|
||||
|
||||
float Recipe::getServings(){
|
||||
float Recipe::getServings() const{
|
||||
return this->servings;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,16 +36,16 @@ public:
|
|||
Recipe();
|
||||
|
||||
//Getters
|
||||
string getName();
|
||||
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();
|
||||
string getName() const;
|
||||
vector<RecipeIngredient> getIngredients() const;
|
||||
Instruction getInstruction() const;
|
||||
QImage getImage() const;
|
||||
vector<RecipeTag> getTags() const;
|
||||
QDate getCreatedDate() const;
|
||||
QTime getPrepTime() const;
|
||||
QTime getCookTime() const;
|
||||
QTime getTotalTime() const; //Derived method to add prep and cook times.
|
||||
float getServings() const;
|
||||
|
||||
//Setters
|
||||
void setName(string newName);
|
||||
|
|
|
@ -6,9 +6,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
ui(new Ui::MainWindow){
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->ingredientsListView->setModel(&this->ingredientModel);
|
||||
|
||||
//TESTING CODE
|
||||
vector<RecipeIngredient> ri;
|
||||
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c")));
|
||||
ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp")));
|
||||
|
||||
Recipe rec("Example", ri, Instruction("<b>BOLD</b><i>iTaLiCs</i>"), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f);
|
||||
|
||||
|
@ -34,5 +37,5 @@ void MainWindow::setInstruction(Instruction instruction){
|
|||
}
|
||||
|
||||
void MainWindow::setIngredients(vector<RecipeIngredient> ingredients){
|
||||
///TODO: Implement this.
|
||||
this->ingredientModel.setIngredients(ingredients);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QAbstractListModel>
|
||||
|
||||
#include "model/recipe/recipe.h"
|
||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -25,7 +26,7 @@ public:
|
|||
void loadFromRecipe(Recipe recipe);
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QAbstractListModel *ingredientsListModel;
|
||||
IngredientListModel ingredientModel;
|
||||
|
||||
//Hidden manipulation methods.
|
||||
void setRecipeName(string name);
|
||||
|
|
Loading…
Reference in New Issue