Improve/redesign ingredients #13
|
@ -15,7 +15,6 @@ NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
||||||
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
||||||
this->recipeDB = db;
|
this->recipeDB = db;
|
||||||
|
|
||||||
|
|
||||||
this->populateIngredientsBox();
|
this->populateIngredientsBox();
|
||||||
this->populateUnitsBox();
|
this->populateUnitsBox();
|
||||||
this->populateTagsBox();
|
this->populateTagsBox();
|
||||||
|
@ -55,24 +54,6 @@ bool NewRecipeDialog::isAccepted() const{
|
||||||
return this->accepted;
|
return this->accepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::populateIngredientsBox(){
|
|
||||||
this->ingredients = this->recipeDB->retrieveAllIngredients();
|
|
||||||
ui->ingredientNameBox->clear();
|
|
||||||
for (unsigned int i = 0; i < this->ingredients.size(); i++){
|
|
||||||
QString s = QString::fromStdString(this->ingredients[i].getName());
|
|
||||||
ui->ingredientNameBox->insertItem(i, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::populateUnitsBox(){
|
|
||||||
this->units = this->recipeDB->retrieveAllUnitsOfMeasure();
|
|
||||||
ui->unitComboBox->clear();
|
|
||||||
for (unsigned int i = 0; i < this->units.size(); i++){
|
|
||||||
QString s = QString::fromStdString(this->units[i].getName());
|
|
||||||
ui->unitComboBox->insertItem(i, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::populateTagsBox(){
|
void NewRecipeDialog::populateTagsBox(){
|
||||||
this->tags = this->recipeDB->retrieveAllTags();
|
this->tags = this->recipeDB->retrieveAllTags();
|
||||||
ui->tagsComboBox->clear();
|
ui->tagsComboBox->clear();
|
||||||
|
@ -83,12 +64,9 @@ void NewRecipeDialog::populateTagsBox(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_addIngredientButton_clicked(){
|
void NewRecipeDialog::on_addIngredientButton_clicked(){
|
||||||
//Construct a recipe ingredient from the supplied data.
|
Ingredient ing(ui->ingredientLineEdit->text().toStdString());
|
||||||
Ingredient i = this->ingredients[ui->ingredientNameBox->currentIndex()];
|
this->ingredientListModel.addIngredient(ing);
|
||||||
UnitOfMeasure u = this->units[ui->unitComboBox->currentIndex()];
|
ui->ingredientLineEdit->clear();
|
||||||
RecipeIngredient ri(i, ui->quantitySpinBox->value(), u, ui->commentsLineEdit->text().toStdString());
|
|
||||||
this->ingredientListModel.addIngredient(ri);
|
|
||||||
ui->commentsLineEdit->clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_italicsButton_clicked(){
|
void NewRecipeDialog::on_italicsButton_clicked(){
|
||||||
|
@ -113,7 +91,6 @@ void NewRecipeDialog::on_buttonBox_rejected(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_addTagButton_clicked(){
|
void NewRecipeDialog::on_addTagButton_clicked(){
|
||||||
//Add a tag to the list of those prepared to be added.
|
|
||||||
this->tagsListModel.addTag(this->tags[ui->tagsComboBox->currentIndex()]);
|
this->tagsListModel.addTag(this->tags[ui->tagsComboBox->currentIndex()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,37 +117,6 @@ void NewRecipeDialog::on_removeIngredientButton_clicked(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_deleteIngredientButton_clicked(){
|
|
||||||
int index = ui->ingredientNameBox->currentIndex();
|
|
||||||
Ingredient ing = this->ingredients.at(index);
|
|
||||||
QMessageBox::StandardButton reply = QMessageBox::question(this,
|
|
||||||
QString::fromStdString("Delete Ingredient"),
|
|
||||||
QString::fromStdString("Are you sure you want to delete the ingredient " + ing.getName() + "?"));
|
|
||||||
if (reply == QMessageBox::Yes){
|
|
||||||
bool success = this->recipeDB->deleteIngredient(ing.getName());
|
|
||||||
if (!success){
|
|
||||||
QMessageBox::critical(this, QString::fromStdString("Error"), QString::fromStdString("Unable to delete ingredient: " + ing.getName() + ", some recipes use it!"));
|
|
||||||
} else {
|
|
||||||
this->populateIngredientsBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::on_newIngredientButton_clicked(){
|
|
||||||
NewIngredientDialog d(this->recipeDB, this);
|
|
||||||
d.show();
|
|
||||||
if (d.exec() == QDialog::Accepted){
|
|
||||||
Ingredient i = d.getIngredient();
|
|
||||||
if (!i.getName().empty() && !i.getFoodGroup().empty() && this->recipeDB->storeIngredient(i)){
|
|
||||||
this->populateIngredientsBox();
|
|
||||||
ui->ingredientNameBox->setCurrentText(QString::fromStdString(i.getName()));
|
|
||||||
} else {
|
|
||||||
QMessageBox::critical(this, "Error", "Unable to add ingredient.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::on_newTagButton_clicked(){
|
void NewRecipeDialog::on_newTagButton_clicked(){
|
||||||
NewTagDialog d(this);
|
NewTagDialog d(this);
|
||||||
d.show();
|
d.show();
|
||||||
|
@ -205,32 +151,3 @@ void NewRecipeDialog::on_removeTagButton_clicked(){
|
||||||
this->populateTagsBox();
|
this->populateTagsBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_newUnitButton_clicked(){
|
|
||||||
NewUnitDialog d(this);
|
|
||||||
d.show();
|
|
||||||
if (d.exec() == QDialog::Accepted){
|
|
||||||
UnitOfMeasure u = d.getUnit();
|
|
||||||
if (u.getName().empty() || u.getNamePlural().empty() || u.getAbbreviation().empty() || !this->recipeDB->storeUnitOfMeasure(u)){
|
|
||||||
QMessageBox::critical(this, "Error", "Unable to store new unit. Make sure all the information is filled in!");
|
|
||||||
} else {
|
|
||||||
this->populateUnitsBox();
|
|
||||||
ui->unitComboBox->setCurrentText(QString::fromStdString(u.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::on_deleteUnitButton_clicked(){
|
|
||||||
int index = ui->unitComboBox->currentIndex();
|
|
||||||
UnitOfMeasure unit = this->units[index];
|
|
||||||
QMessageBox::StandardButton reply = QMessageBox::question(this,
|
|
||||||
QString::fromStdString("Delete Unit Of Measure"),
|
|
||||||
QString::fromStdString("Are you sure you want to delete the unit " + unit.getName() + "?"));
|
|
||||||
if (reply == QMessageBox::Yes){
|
|
||||||
if (!this->recipeDB->deleteUnitOfMeasure(unit.getName())){
|
|
||||||
QMessageBox::critical(this, "Error", "Unable to delete unit. There may be recipes which still use it!");
|
|
||||||
} else {
|
|
||||||
this->populateUnitsBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "model/database/recipedatabase.h"
|
#include "model/database/recipedatabase.h"
|
||||||
#include "model/recipe/ingredients/recipeingredientlistmodel.h"
|
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||||
#include "model/recipe/tags/taglistmodel.h"
|
#include "model/recipe/tags/taglistmodel.h"
|
||||||
|
|
||||||
#include "gui/newDialogs/newingredientdialog.h"
|
#include "gui/newDialogs/newingredientdialog.h"
|
||||||
|
@ -29,6 +29,7 @@ class NewRecipeDialog : public QDialog
|
||||||
NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent = 0);
|
NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent = 0);
|
||||||
~NewRecipeDialog();
|
~NewRecipeDialog();
|
||||||
|
|
||||||
|
//Extracts a recipe from all the information entered in the ui.
|
||||||
Recipe getRecipe();
|
Recipe getRecipe();
|
||||||
bool isAccepted() const;
|
bool isAccepted() const;
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -38,8 +39,10 @@ class NewRecipeDialog : public QDialog
|
||||||
|
|
||||||
void on_boldButton_clicked();
|
void on_boldButton_clicked();
|
||||||
|
|
||||||
|
//Sets the dialog as accepted, as in, the user accepts that they want to create the recipe.
|
||||||
void on_buttonBox_accepted();
|
void on_buttonBox_accepted();
|
||||||
|
|
||||||
|
//The user has rejected the creation of the recipe.
|
||||||
void on_buttonBox_rejected();
|
void on_buttonBox_rejected();
|
||||||
|
|
||||||
void on_addTagButton_clicked();
|
void on_addTagButton_clicked();
|
||||||
|
@ -50,31 +53,20 @@ class NewRecipeDialog : public QDialog
|
||||||
|
|
||||||
void on_removeIngredientButton_clicked();
|
void on_removeIngredientButton_clicked();
|
||||||
|
|
||||||
void on_deleteIngredientButton_clicked();
|
|
||||||
|
|
||||||
void on_newIngredientButton_clicked();
|
|
||||||
|
|
||||||
void on_newTagButton_clicked();
|
void on_newTagButton_clicked();
|
||||||
|
|
||||||
void on_removeTagButton_clicked();
|
void on_removeTagButton_clicked();
|
||||||
|
|
||||||
void on_newUnitButton_clicked();
|
|
||||||
|
|
||||||
void on_deleteUnitButton_clicked();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::NewRecipeDialog *ui;
|
Ui::NewRecipeDialog *ui;
|
||||||
RecipeDatabase *recipeDB;
|
RecipeDatabase *recipeDB;
|
||||||
vector<Ingredient> ingredients;
|
vector<Ingredient> ingredients;
|
||||||
vector<UnitOfMeasure> units;
|
|
||||||
vector<RecipeTag> tags;
|
vector<RecipeTag> tags;
|
||||||
RecipeIngredientListModel ingredientListModel;
|
IngredientListModel ingredientListModel;
|
||||||
TagListModel tagsListModel;
|
TagListModel tagsListModel;
|
||||||
bool accepted = false;
|
bool accepted = false;
|
||||||
|
|
||||||
//Helper functions to fill fields.
|
//Helper functions to fill fields.
|
||||||
void populateIngredientsBox();
|
|
||||||
void populateUnitsBox();
|
|
||||||
void populateTagsBox();
|
void populateTagsBox();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,12 @@
|
||||||
|
|
||||||
#include "model/recipe/ingredients/ingredient.h"
|
#include "model/recipe/ingredients/ingredient.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The IngredientListModel class
|
||||||
|
*
|
||||||
|
* The ingredient list model extends the QAbstractListModel and is used for lists of ingredients,
|
||||||
|
* whether they appear in the NewRecipe dialog or in the main recipe view.
|
||||||
|
*/
|
||||||
class IngredientListModel : public QAbstractListModel
|
class IngredientListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -25,8 +31,6 @@ public:
|
||||||
private:
|
private:
|
||||||
vector<Ingredient> ingredients;
|
vector<Ingredient> ingredients;
|
||||||
|
|
||||||
//Helper for printing.
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INGREDIENTLISTMODEL_H
|
#endif // INGREDIENTLISTMODEL_H
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "model/recipe/recipe.h"
|
#include "model/recipe/recipe.h"
|
||||||
|
|
||||||
Recipe::Recipe(string name, string author, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){
|
Recipe::Recipe(string name, string author, vector<Ingredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings){
|
||||||
setName(name);
|
setName(name);
|
||||||
setAuthor(author);
|
setAuthor(author);
|
||||||
setIngredients(ingredients);
|
setIngredients(ingredients);
|
||||||
|
@ -13,7 +13,7 @@ Recipe::Recipe(string name, string author, vector<RecipeIngredient> ingredients,
|
||||||
setServings(servings);
|
setServings(servings);
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe::Recipe() : Recipe::Recipe("", "", vector<RecipeIngredient>(), Instruction(), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(), QTime(), 1.0f){
|
Recipe::Recipe() : Recipe::Recipe("", "", vector<Ingredient>(), Instruction(), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(), QTime(), 1.0f){
|
||||||
//Set default values when none are specified.
|
//Set default values when none are specified.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,15 +25,15 @@ string Recipe::getAuthor() const{
|
||||||
return this->authorName;
|
return this->authorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<RecipeIngredient> Recipe::getIngredients() const{
|
vector<Ingredient> Recipe::getIngredients() const{
|
||||||
return this->ingredients;
|
return this->ingredients;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> Recipe::getFoodGroups() const{
|
vector<string> Recipe::getFoodGroups() const{
|
||||||
vector<string> foodGroups;
|
vector<string> foodGroups;
|
||||||
for (RecipeIngredient ri : this->ingredients){
|
for (Ingredient i : this->ingredients){
|
||||||
if (find(foodGroups.begin(), foodGroups.end(), ri.getFoodGroup()) == foodGroups.end()){
|
if (find(foodGroups.begin(), foodGroups.end(), i.getFoodGroup()) == foodGroups.end()){
|
||||||
foodGroups.push_back(ri.getFoodGroup());
|
foodGroups.push_back(i.getFoodGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return foodGroups;
|
return foodGroups;
|
||||||
|
@ -83,7 +83,7 @@ void Recipe::setAuthor(string newName){
|
||||||
this->authorName = newName;
|
this->authorName = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Recipe::setIngredients(vector<RecipeIngredient> ingredients){
|
void Recipe::setIngredients(vector<Ingredient> ingredients){
|
||||||
this->ingredients = ingredients;
|
this->ingredients = ingredients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void Recipe::setTags(vector<RecipeTag> tags){
|
||||||
this->tags = tags;
|
this->tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Recipe::addIngredient(RecipeIngredient newIngredient){
|
void Recipe::addIngredient(Ingredient newIngredient){
|
||||||
this->ingredients.push_back(newIngredient);
|
this->ingredients.push_back(newIngredient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,17 +129,11 @@ void Recipe::print(){
|
||||||
this->servings);
|
this->servings);
|
||||||
printf("\tInstruction: %s\n", this->instruction.getHTML().c_str());
|
printf("\tInstruction: %s\n", this->instruction.getHTML().c_str());
|
||||||
printf("\tIngredients:\n");
|
printf("\tIngredients:\n");
|
||||||
for (vector<RecipeIngredient>::iterator it = this->ingredients.begin(); it != this->ingredients.end(); ++it){
|
for (Ingredient i : this->ingredients){
|
||||||
RecipeIngredient ri = *it;
|
printf("\t\t%s\n", i.getContent().c_str());
|
||||||
printf("\t\t%s, Food Group: %s, Quantity: %f, Unit: %s\n",
|
|
||||||
ri.getName().c_str(),
|
|
||||||
ri.getFoodGroup().c_str(),
|
|
||||||
ri.getQuantity(),
|
|
||||||
ri.getUnit().getName().c_str());
|
|
||||||
}
|
}
|
||||||
printf("\tTags:\n");
|
printf("\tTags:\n");
|
||||||
for (vector<RecipeTag>::iterator it = this->tags.begin(); it != this->tags.end(); ++it){
|
for (RecipeTag t : this->tags){
|
||||||
RecipeTag t = *it;
|
|
||||||
printf("\t\t%s\n", t.getValue().c_str());
|
printf("\t\t%s\n", t.getValue().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,14 @@ class Recipe
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Full constructor
|
//Full constructor
|
||||||
Recipe(string name, string author, vector<RecipeIngredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings);
|
Recipe(string name, string author, vector<Ingredient> ingredients, Instruction instruction, QImage image, vector<RecipeTag> tags, QDate createdDate, QTime prepTime, QTime cookTime, float servings);
|
||||||
//Constructor with default values.
|
//Constructor with default values.
|
||||||
Recipe();
|
Recipe();
|
||||||
|
|
||||||
//Getters
|
//Getters
|
||||||
string getName() const;
|
string getName() const;
|
||||||
string getAuthor() const;
|
string getAuthor() const;
|
||||||
vector<RecipeIngredient> getIngredients() const;
|
vector<Ingredient> getIngredients() const;
|
||||||
vector<string> getFoodGroups() const;
|
vector<string> getFoodGroups() const;
|
||||||
Instruction getInstruction() const;
|
Instruction getInstruction() const;
|
||||||
QImage getImage() const;
|
QImage getImage() const;
|
||||||
|
@ -54,9 +54,9 @@ public:
|
||||||
//Setters
|
//Setters
|
||||||
void setName(string newName);
|
void setName(string newName);
|
||||||
void setAuthor(string newName);
|
void setAuthor(string newName);
|
||||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
void setIngredients(vector<Ingredient> ingredients);
|
||||||
void setTags(vector<RecipeTag> tags);
|
void setTags(vector<RecipeTag> tags);
|
||||||
void addIngredient(RecipeIngredient newIngredient);
|
void addIngredient(Ingredient newIngredient);
|
||||||
void setInstruction(Instruction newInstruction);
|
void setInstruction(Instruction newInstruction);
|
||||||
void setImage(QImage newImage);
|
void setImage(QImage newImage);
|
||||||
void setCreatedDate(QDate newDate);
|
void setCreatedDate(QDate newDate);
|
||||||
|
@ -64,12 +64,13 @@ public:
|
||||||
void setCookTime(QTime newTime);
|
void setCookTime(QTime newTime);
|
||||||
void setServings(float newServingsCount);
|
void setServings(float newServingsCount);
|
||||||
|
|
||||||
|
//Prints information about the recipe to the console, for debugging.
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
//Main information.
|
//Main information.
|
||||||
string name; //The name of the recipe.
|
string name; //The name of the recipe.
|
||||||
string authorName; //The name of the author of this recipe.
|
string authorName; //The name of the author of this recipe.
|
||||||
vector<RecipeIngredient> ingredients; //The list of ingredients in the recipe.
|
vector<Ingredient> ingredients; //The list of ingredients in the recipe.
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue