diff --git a/RecipeDB.pro b/RecipeDB.pro index 0071690..e573956 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -27,7 +27,9 @@ SOURCES += model/recipe/instruction.cpp \ model/database/recipedatabase.cpp \ utils/fileutils.cpp \ gui/newrecipedialog.cpp \ - model/recipe/tags/taglistmodel.cpp + model/recipe/tags/taglistmodel.cpp \ + gui/newDialogs/newingredientdialog.cpp \ + gui/newDialogs/newtagdialog.cpp HEADERS += model/recipe/instruction.h \ model/recipe/recipe.h \ @@ -44,14 +46,19 @@ HEADERS += model/recipe/instruction.h \ model/database/recipedatabase.h \ utils/fileutils.h \ gui/newrecipedialog.h \ - model/recipe/tags/taglistmodel.h + model/recipe/tags/taglistmodel.h \ + gui/newDialogs/newingredientdialog.h \ + gui/newDialogs/newtagdialog.h LIBS += -ldl \ FORMS += gui/mainwindow.ui \ - gui/newrecipedialog.ui + gui/newrecipedialog.ui \ + gui/newDialogs/newingredientdialog.ui \ + gui/newDialogs/newtagdialog.ui DISTFILES += \ .gitignore -RESOURCES += +RESOURCES += \ + images.qrc diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index ae24fae..58638ed 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -25,6 +25,10 @@ RecipeDB + + + :/images/images/icon.png:/images/images/icon.png + 1.000000000000000 @@ -237,40 +241,181 @@ QPushButton#browseButton:pressed{ 0 - - - - - 0 - 0 - - - - - 0 - 80 - - + + - Noto Sans CJK KR Light - 24 50 false false - PreferAntialias - true - background-color: rgb(219, 216, 216); - - - Recipe Name - - - Qt::AlignCenter + background-color: rgb(219, 216, 216); +font: "Noto Sans CJK KR"; + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR Light + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR Light + 12 + + + + Prep Time: + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR Light + 12 + + + + Cook Time: + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR Light + 12 + + + + Servings: + + + + + + + + + + + 0 + 0 + + + + + 0 + 80 + + + + + Noto Sans CJK KR Light + 30 + 50 + false + false + PreferAntialias + + + + Recipe Name + + + Qt::AlignCenter + + + + @@ -413,6 +558,12 @@ QPushButton#browseButton:pressed{ 0 + + + 400 + 0 + + 0 @@ -510,7 +661,7 @@ p, li { white-space: pre-wrap; } - + @@ -543,6 +694,19 @@ p, li { white-space: pre-wrap; } 0 + + + + :/images/images/no_image.png + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -556,6 +720,8 @@ p, li { white-space: pre-wrap; } - + + + diff --git a/gui/newDialogs/newingredientdialog.cpp b/gui/newDialogs/newingredientdialog.cpp new file mode 100644 index 0000000..5b7597a --- /dev/null +++ b/gui/newDialogs/newingredientdialog.cpp @@ -0,0 +1,18 @@ +#include "newingredientdialog.h" +#include "ui_newingredientdialog.h" + +NewIngredientDialog::NewIngredientDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewIngredientDialog) +{ + ui->setupUi(this); +} + +NewIngredientDialog::~NewIngredientDialog() +{ + delete ui; +} + +Ingredient NewIngredientDialog::getIngredient(){ + return Ingredient(ui->nameEdit->text().toLower().toStdString(), ui->foodGroupEdit->text().toLower().toStdString()); +} diff --git a/gui/newDialogs/newingredientdialog.h b/gui/newDialogs/newingredientdialog.h new file mode 100644 index 0000000..4c94275 --- /dev/null +++ b/gui/newDialogs/newingredientdialog.h @@ -0,0 +1,26 @@ +#ifndef NEWINGREDIENTDIALOG_H +#define NEWINGREDIENTDIALOG_H + +#include +#include "model/recipe/ingredients/ingredient.h" + +namespace Ui { +class NewIngredientDialog; +} + +class NewIngredientDialog : public QDialog +{ + Q_OBJECT + + public: + explicit NewIngredientDialog(QWidget *parent = 0); + ~NewIngredientDialog(); + + //Access values. + Ingredient getIngredient(); + + private: + Ui::NewIngredientDialog *ui; +}; + +#endif // NEWINGREDIENTDIALOG_H diff --git a/gui/newDialogs/newingredientdialog.ui b/gui/newDialogs/newingredientdialog.ui new file mode 100644 index 0000000..8f4f268 --- /dev/null +++ b/gui/newDialogs/newingredientdialog.ui @@ -0,0 +1,120 @@ + + + NewIngredientDialog + + + + 0 + 0 + 240 + 320 + + + + New Ingredient + + + + :/images/images/icon.png:/images/images/icon.png + + + true + + + + + + true + + + + + + + + + Name + + + Qt::AlignCenter + + + + + + + + + + + + + + + + Food Group + + + Qt::AlignCenter + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + NewIngredientDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewIngredientDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/newDialogs/newtagdialog.cpp b/gui/newDialogs/newtagdialog.cpp new file mode 100644 index 0000000..dd26afc --- /dev/null +++ b/gui/newDialogs/newtagdialog.cpp @@ -0,0 +1,18 @@ +#include "newtagdialog.h" +#include "ui_newtagdialog.h" + +NewTagDialog::NewTagDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::newTagDialog) +{ + ui->setupUi(this); +} + +NewTagDialog::~NewTagDialog() +{ + delete ui; +} + +RecipeTag NewTagDialog::getTag(){ + return RecipeTag(ui->tagEdit->text().toLower().toStdString()); +} diff --git a/gui/newDialogs/newtagdialog.h b/gui/newDialogs/newtagdialog.h new file mode 100644 index 0000000..e096f21 --- /dev/null +++ b/gui/newDialogs/newtagdialog.h @@ -0,0 +1,26 @@ +#ifndef NEWTAGDIALOG_H +#define NEWTAGDIALOG_H + +#include + +#include "model/recipe/tags/recipetag.h" + +namespace Ui { +class newTagDialog; +} + +class NewTagDialog : public QDialog +{ + Q_OBJECT + + public: + explicit NewTagDialog(QWidget *parent = 0); + ~NewTagDialog(); + + //Access values + RecipeTag getTag(); + private: + Ui::newTagDialog *ui; +}; + +#endif // NEWTAGDIALOG_H diff --git a/gui/newDialogs/newtagdialog.ui b/gui/newDialogs/newtagdialog.ui new file mode 100644 index 0000000..fd77812 --- /dev/null +++ b/gui/newDialogs/newtagdialog.ui @@ -0,0 +1,92 @@ + + + newTagDialog + + + + 0 + 0 + 240 + 320 + + + + Dialog + + + + :/images/images/icon.png:/images/images/icon.png + + + true + + + + + + + + + New Tag + + + Qt::AlignCenter + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + newTagDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + newTagDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp index 7405d09..0517fd9 100644 --- a/gui/newrecipedialog.cpp +++ b/gui/newrecipedialog.cpp @@ -29,12 +29,13 @@ Recipe NewRecipeDialog::getRecipe(){ Recipe r(ui->recipeNameEdit->text().toStdString(), this->ingredientListModel.getIngredients(), ui->instructionsTextEdit->toHtml().toStdString(), - QImage(),//Image + this->img,//Image this->tagsListModel.getTags(),//Tags QDate::currentDate(), ui->prepTimeEdit->time(), ui->cookTimeEdit->time(), (float)ui->servingsSpinBox->value()); + return r; } bool NewRecipeDialog::isAccepted() const{ @@ -101,3 +102,67 @@ 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()]); } + +void NewRecipeDialog::on_deleteTagButton_clicked(){ + QModelIndexList indexList = ui->tagsListView->selectionModel()->selectedIndexes(); + for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){ + QModelIndex i = *it; + this->tagsListModel.deleteTag(i.row()); + } +} + +void NewRecipeDialog::on_selectImageButton_clicked(){ + QString filename = QFileDialog::getOpenFileName(this, "Open Image", QString(), "Image Files (*.png *.jpg *.bmp)"); + if (!filename.isEmpty()){ + this->img = QImage(filename); + ui->imageDisplayLabel->setPixmap(QPixmap(filename)); + } +} + +void NewRecipeDialog::on_deleteIngredientButton_clicked(){ + QModelIndexList indexList = ui->ingredientsListView->selectionModel()->selectedIndexes(); + for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){ + QModelIndex i = *it; + this->ingredientListModel.deleteIngredient(i.row()); + } +} + +void NewRecipeDialog::on_newIngredientButton_clicked(){ + NewIngredientDialog d(this); + d.show(); + if (d.exec() == QDialog::Accepted){ + Ingredient i = d.getIngredient(); + this->recipeDB->storeIngredient(i); + this->populateIngredientsBox(); + } +} + +void NewRecipeDialog::on_newTagButton_clicked(){ + NewTagDialog d(this); + d.show(); + if (d.exec() == QDialog::Accepted){ + RecipeTag tag = d.getTag(); + //Temporarily add this to the tags list, and it will be saved if the recipe is saved. + this->tags.push_back(tag); + ui->tagsComboBox->clear(); + for (unsigned int i = 0; i < this->tags.size(); i++){ + QString s = QString::fromStdString(this->tags[i].getValue()); + ui->tagsComboBox->insertItem(i, s); + } + } + +} + +void NewRecipeDialog::on_removeTagButton_clicked(){ + int index = ui->tagsComboBox->currentIndex(); + if (index < 0 || index >= this->tags.size()){ + return; + } + RecipeTag tag = this->tags[ui->tagsComboBox->currentIndex()]; + string content = "Are you sure you wish to delete the following tag:\n"+tag.getValue(); + QMessageBox::StandardButton reply = QMessageBox::question(this, QString("Delete Tag"), QString(content.c_str())); + if (reply == QMessageBox::Yes){ + this->recipeDB->deleteTag(tag); + this->populateTagsBox(); + } +} diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h index 47cd848..f1c87cb 100644 --- a/gui/newrecipedialog.h +++ b/gui/newrecipedialog.h @@ -3,11 +3,17 @@ #include #include +#include +#include +#include #include "model/database/recipedatabase.h" #include "model/recipe/ingredients/ingredientlistmodel.h" #include "model/recipe/tags/taglistmodel.h" +#include "gui/newDialogs/newingredientdialog.h" +#include "gui/newDialogs/newtagdialog.h" + namespace Ui { class NewRecipeDialog; } @@ -36,6 +42,18 @@ class NewRecipeDialog : public QDialog void on_addTagButton_clicked(); + void on_deleteTagButton_clicked(); + + void on_selectImageButton_clicked(); + + void on_deleteIngredientButton_clicked(); + + void on_newIngredientButton_clicked(); + + void on_newTagButton_clicked(); + + void on_removeTagButton_clicked(); + private: Ui::NewRecipeDialog *ui; RecipeDatabase *recipeDB; @@ -44,6 +62,7 @@ class NewRecipeDialog : public QDialog vector tags; IngredientListModel ingredientListModel; TagListModel tagsListModel; + QImage img; bool accepted = false; //Helper functions to fill fields. diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui index 78e7f57..82afc1d 100644 --- a/gui/newrecipedialog.ui +++ b/gui/newrecipedialog.ui @@ -22,6 +22,13 @@ New Recipe + + + :/images/images/icon.png:/images/images/icon.png + + + true + 0 @@ -272,12 +279,34 @@ 0 - + + + + 0 + 0 + + + - + - - New + + Create a new tag + + + + :/images/images/plus_icon.png:/images/images/plus_icon.png + + + + + + + Permanently delete this tag + + + + :/images/images/minus_icon.png:/images/images/minus_icon.png @@ -327,6 +356,9 @@ QFrame::NoFrame + + QAbstractItemView::MultiSelection + @@ -336,23 +368,11 @@ - - - - 0 - 0 - - - - background-color: rgb(245, 245, 255); - - + + 0 - - QLayout::SetMaximumSize - 0 @@ -366,64 +386,53 @@ 0 - - - Ingredients + + + + 0 + 0 + - - Qt::AlignCenter + + background-color: rgb(245, 245, 255); - - - - - + + + 0 + + + QLayout::SetMaximumSize + + + 0 + + + 0 + + + 0 + + + 0 + - - - background-color: rgb(255, 255, 255); + + + Ingredients - - QFrame::NoFrame - - - 100 + + Qt::AlignCenter - - - - - 5 - - - 0 - - - 0 - - - 0 - - - 0 - + + + - - - Add Ingredient - - - Qt::AlignCenter - - - - - - + + - 2 + 5 0 @@ -438,149 +447,211 @@ 0 - - - - 0 - 0 - + + + Add Ingredient - - + + Qt::AlignCenter - - - New + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + false + + + + + + + + + + Create a new ingredient + + + + :/images/images/plus_icon.png:/images/images/plus_icon.png + + + + + + + + + + + 0 + 36 + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR + 14 + 50 + false + false + + + + Amount + + + + + + + + 0 + 0 + + + + 10000.000000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + + + + + + :/images/images/plus_icon.png:/images/images/plus_icon.png + + + + + + + + + + + 0 + 0 + + + + false + + + Qt::AlignCenter + + + Comments + + + false + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add + + + + + + + Delete + + + + - - - - 0 - 36 - + + + background-color: rgb(255, 255, 255); - - - 2 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - Noto Sans CJK KR - 14 - 50 - false - false - - - - Amount - - - - - - - - 0 - 0 - - - - 10000.000000000000000 - - - 1.000000000000000 - - - - - - - - - - New - - - - - - - - - - - 0 - 0 - + + QFrame::NoFrame - - false + + QAbstractItemView::MultiSelection - - Qt::AlignCenter + + 100 - - Comments - - - false - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Add - - - - - - - Delete - - - - @@ -589,11 +660,64 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 500 + 500 + + + + + + + :/images/images/no_image.png + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Select Image... + + + + + + + + background-color: rgb(250, 250, 255); + @@ -657,6 +781,12 @@ + + background-color: rgb(255, 255, 255); + + + QFrame::NoFrame + Enter instructions here. @@ -670,9 +800,15 @@ Qt::LeftToRight + + false + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + true + @@ -680,6 +816,8 @@ - + + + diff --git a/images.qrc b/images.qrc new file mode 100644 index 0000000..2391914 --- /dev/null +++ b/images.qrc @@ -0,0 +1,8 @@ + + + images/no_image.png + images/icon.png + images/plus_icon.png + images/minus_icon.png + + diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..9a2db3c Binary files /dev/null and b/images/icon.png differ diff --git a/images/minus_icon.png b/images/minus_icon.png new file mode 100644 index 0000000..f806792 Binary files /dev/null and b/images/minus_icon.png differ diff --git a/images/no_image.png b/images/no_image.png new file mode 100644 index 0000000..d9a708d Binary files /dev/null and b/images/no_image.png differ diff --git a/images/plus_icon.png b/images/plus_icon.png new file mode 100644 index 0000000..88d151b Binary files /dev/null and b/images/plus_icon.png differ diff --git a/main.cpp b/main.cpp index 23f8db2..4e49c1e 100644 --- a/main.cpp +++ b/main.cpp @@ -7,49 +7,48 @@ int main(int argc, char *argv[]) { + RecipeDatabase recipeDB("recipes"); QApplication a(argc, argv); - MainWindow w; + MainWindow w(&recipeDB); w.show(); //TESTING CODE +// vector ri; +// ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), "")); +// ri.push_back(RecipeIngredient("baking powder", "additives", 1.0f, UnitOfMeasure("teaspoon", "teaspoons", "tsp", UnitOfMeasure::VOLUME, 1.0), "")); - RecipeDatabase recipeDB("recipes"); +// Recipe rec("Example", +// ri, +// Instruction("BOLDiTaLiCs"), +// QImage(), +// vector({RecipeTag("testing"), +// RecipeTag("fake")}), +// QDate::currentDate(), +// QTime(0, 30), +// QTime(0, 25), +// 10.0f); - //TESTING CODE - vector ri; - ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), "")); - ri.push_back(RecipeIngredient("baking powder", "additives", 1.0f, UnitOfMeasure("teaspoon", "teaspoons", "tsp", UnitOfMeasure::VOLUME, 1.0), "")); +// bool success = recipeDB.storeRecipe(rec); +// printf("Storage successful: %d\n", success); - Recipe rec("Example", - ri, - Instruction("BOLDiTaLiCs"), - QImage(), - vector({RecipeTag("testing"), - RecipeTag("fake")}), - QDate::currentDate(), - QTime(0, 30), - QTime(0, 25), - 10.0f); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0)); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0)); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0)); - bool success = recipeDB.storeRecipe(rec); - printf("Storage successful: %d\n", success); +// Recipe reloadRec = recipeDB.retrieveRecipe("Example"); +// reloadRec.print(); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0)); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0)); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0)); +// w.loadFromRecipe(reloadRec); - Recipe reloadRec = recipeDB.retrieveRecipe("Example"); - reloadRec.print(); +// NewRecipeDialog d(&recipeDB); +// d.show(); +// d.exec(); - w.loadFromRecipe(reloadRec); +// if (d.isAccepted()){ +// printf("Accepted the dialog.\n"); +// } - NewRecipeDialog d(&recipeDB); - d.show(); - d.exec(); - - if (d.isAccepted()){ - printf("Accepted the dialog.\n"); - } + w.loadFromRecipe(recipeDB.retrieveRecipe("Generic Bread")); return a.exec(); } diff --git a/model/database/recipedatabase.cpp b/model/database/recipedatabase.cpp index b64a660..5ab05fd 100644 --- a/model/database/recipedatabase.cpp +++ b/model/database/recipedatabase.cpp @@ -223,6 +223,10 @@ vector RecipeDatabase::retrieveAllTags(){ return tags; } +void RecipeDatabase::deleteTag(RecipeTag tag){ + ResultTable t = this->executeSQL("DELETE FROM recipeTag WHERE tagName="+surroundString(tag.getValue(), "'")); +} + void RecipeDatabase::ensureTablesExist(){ //Make sure that foreign keys are enabled. this->executeSQL("PRAGMA foreign_keys = ON;"); diff --git a/model/database/recipedatabase.h b/model/database/recipedatabase.h index f1d9867..099c233 100644 --- a/model/database/recipedatabase.h +++ b/model/database/recipedatabase.h @@ -37,6 +37,9 @@ class RecipeDatabase : public Database vector retrieveAllUnitsOfMeasure(); vector retrieveTags(int recipeId); vector retrieveAllTags(); + + //Deletion. + void deleteTag(RecipeTag tag); private: //Utility methods. diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp index 1370bc7..7763671 100644 --- a/model/recipe/ingredients/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -53,6 +53,11 @@ bool IngredientListModel::addIngredient(RecipeIngredient ri){ return true; } +void IngredientListModel::deleteIngredient(int index){ + this->ingredients.erase(this->ingredients.begin() + index); + emit dataChanged(createIndex(0, 0), createIndex(this->ingredients.size()-1, 0)); +} + vector IngredientListModel::getIngredients(){ return this->ingredients; } diff --git a/model/recipe/ingredients/ingredientlistmodel.h b/model/recipe/ingredients/ingredientlistmodel.h index 1f3605c..3c3028d 100644 --- a/model/recipe/ingredients/ingredientlistmodel.h +++ b/model/recipe/ingredients/ingredientlistmodel.h @@ -18,6 +18,7 @@ public: //Custom methods to handle ingredient data. void setIngredients(vector ingredients); bool addIngredient(RecipeIngredient ri); + void deleteIngredient(int index); vector getIngredients(); private: diff --git a/model/recipe/tags/taglistmodel.cpp b/model/recipe/tags/taglistmodel.cpp index dd70b3f..149ad3e 100644 --- a/model/recipe/tags/taglistmodel.cpp +++ b/model/recipe/tags/taglistmodel.cpp @@ -39,6 +39,11 @@ bool TagListModel::addTag(RecipeTag tag){ return true; } +void TagListModel::deleteTag(int index){ + this->tags.erase(this->tags.begin() + index); + emit dataChanged(createIndex(0, 0), createIndex(this->tags.size()-1, 0)); +} + vector TagListModel::getTags(){ return this->tags; } diff --git a/model/recipe/tags/taglistmodel.h b/model/recipe/tags/taglistmodel.h index e524e23..5d5f861 100644 --- a/model/recipe/tags/taglistmodel.h +++ b/model/recipe/tags/taglistmodel.h @@ -16,6 +16,7 @@ class TagListModel : public QAbstractListModel void setTags(vector tags); bool addTag(RecipeTag tag); + void deleteTag(int index); vector getTags(); private: vector tags; diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index 69a6189..b39eec6 100644 --- a/userInterface/mainwindow.cpp +++ b/userInterface/mainwindow.cpp @@ -9,6 +9,10 @@ MainWindow::MainWindow(QWidget *parent) : ui->ingredientsListView->setModel(&this->ingredientModel); } +MainWindow::MainWindow(RecipeDatabase *db, QWidget *parent) : MainWindow(parent){ + this->recipeDB = db; +} + MainWindow::~MainWindow(){ delete ui; } @@ -17,6 +21,10 @@ void MainWindow::loadFromRecipe(Recipe recipe){ setRecipeName(recipe.getName()); setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); + setImage(recipe.getImage()); + setPrepTime(recipe.getPrepTime()); + setCookTime(recipe.getCookTime()); + setServings(recipe.getServings()); } void MainWindow::setRecipeName(string name){ @@ -28,5 +36,34 @@ void MainWindow::setInstruction(Instruction instruction){ } void MainWindow::setIngredients(vector ingredients){ - this->ingredientModel.setIngredients(ingredients); + this->ingredientModel.setIngredients(ingredients); +} + +void MainWindow::setImage(QImage img){ + ui->imageLabel->setPixmap(QPixmap::fromImage(img)); +} + +void MainWindow::setPrepTime(QTime prepTime){ + ui->prepTimeLabel->setText(QString("Prep Time: ")+prepTime.toString("hh:mm:ss")); +} + +void MainWindow::setCookTime(QTime cookTime){ + ui->cookTimeLabel->setText(QString("Cook Time: ")+cookTime.toString("hh:mm:ss")); +} + +void MainWindow::setServings(float servings){ + ui->servingsLabel->setText(QString("Servings: ")+QString::fromStdString(toString(servings))); +} + +void MainWindow::on_newButton_clicked(){ + NewRecipeDialog d(this->recipeDB, this); + d.show(); + d.exec(); + if (d.isAccepted()){ + Recipe r = d.getRecipe(); + if (!this->recipeDB->storeRecipe(r)){ + QMessageBox::critical(this, QString("Unable to Save Recipe"), QString("The program was not able to successfully save the recipe.")); + } + this->loadFromRecipe(r); + } } diff --git a/userInterface/mainwindow.h b/userInterface/mainwindow.h index b1b50be..1605311 100644 --- a/userInterface/mainwindow.h +++ b/userInterface/mainwindow.h @@ -7,6 +7,7 @@ #include "model/recipe/recipe.h" #include "model/recipe/ingredients/ingredientlistmodel.h" +#include "gui/newrecipedialog.h" using namespace std; @@ -20,18 +21,27 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); + MainWindow(RecipeDatabase *db, QWidget *parent = 0); ~MainWindow(); //Loads all data from a recipe into the GUI components. void loadFromRecipe(Recipe recipe); -private: + private slots: + void on_newButton_clicked(); + + private: Ui::MainWindow *ui; + RecipeDatabase *recipeDB; IngredientListModel ingredientModel; //Hidden manipulation methods. void setRecipeName(string name); void setInstruction(Instruction instruction); void setIngredients(vector ingredients); + void setImage(QImage img); + void setPrepTime(QTime prepTime); + void setCookTime(QTime cookTime); + void setServings(float servings); }; #endif // MAINWINDOW_H