From 041d56e1a9a2628fc3dfeb62967b0eaeb28f72d8 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 12:58:31 +0100 Subject: [PATCH 1/6] Adding support for image selection in add recipe dialog. --- RecipeDB.pro | 3 +- gui/newrecipedialog.cpp | 8 + gui/newrecipedialog.ui | 437 ++++++++++-------- images.qrc | 5 + images/no_image.png | Bin 0 -> 3079 bytes .../ingredients/ingredientlistmodel.cpp | 4 + model/recipe/tags/taglistmodel.cpp | 4 + 7 files changed, 269 insertions(+), 192 deletions(-) create mode 100644 images.qrc create mode 100644 images/no_image.png diff --git a/RecipeDB.pro b/RecipeDB.pro index 0071690..c2c8a98 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -54,4 +54,5 @@ FORMS += gui/mainwindow.ui \ DISTFILES += \ .gitignore -RESOURCES += +RESOURCES += \ + images.qrc diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp index 7405d09..2b4123f 100644 --- a/gui/newrecipedialog.cpp +++ b/gui/newrecipedialog.cpp @@ -101,3 +101,11 @@ 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->selectedIndexes(); + for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){ + QModelIndex i = *it; + this->tagsListModel.deleteTag(i.row()); + } +} diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui index 78e7f57..0a0875c 100644 --- a/gui/newrecipedialog.ui +++ b/gui/newrecipedialog.ui @@ -336,23 +336,11 @@ - - - - 0 - 0 - - - - background-color: rgb(245, 245, 255); - - + + 0 - - QLayout::SetMaximumSize - 0 @@ -366,64 +354,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 +415,193 @@ 0 - - - - 0 - 0 - + + + Add Ingredient - - + + Qt::AlignCenter - - - New + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + + + + New + + + + + + + + + + + 0 + 36 + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Noto Sans CJK KR + 14 + 50 + false + false + + + + Amount + + + + + + + + 0 + 0 + + + + 10000.000000000000000 + + + 1.000000000000000 + + + + + + + + + + New + + + + + + + + + + + 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 + + 100 - - Qt::AlignCenter - - - Comments - - - false - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Add - - - - - - - Delete - - - - @@ -589,6 +610,40 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + diff --git a/images.qrc b/images.qrc new file mode 100644 index 0000000..6634926 --- /dev/null +++ b/images.qrc @@ -0,0 +1,5 @@ + + + images/no_image.png + + diff --git a/images/no_image.png b/images/no_image.png new file mode 100644 index 0000000000000000000000000000000000000000..d9a708d29045595ae77cedc07b3de6234c49855a GIT binary patch literal 3079 zcmeH}`9GWK8pe%kIh=Hv8Prx?LJiVX32jmhYH6&EJwbJfsJ*t(L}HB5sWE7yXsj)| z*q0!dkWNcmdmFLDT1AP*R=Wo0@fVyw;GFmKdEe)U_gSy|y1(}mf8E*)A}KE^A|e98 zTr;)>?fd;#;t=?jI+x{uMl93_V=n=oC<)K|A|g`F7-K{G$gKGxie;ad^1J083|7nT zwfNDid8g?|T2pM|kslq~N?Ki!zV&jNAzfW~-{NNvTo4e~nyTkz@u@yuU0HreU#oO$ z%bAu!j|+S6uRXln9vkx8;*QzMNPYubyvty*$vs+&I^#MJet3q`9Zp4y5(uJ8%s~Fa zK@q(RqCY5#iC&ZtyK_|H)5)W+3{U|OXez5Q z{R~F(P%LS8YergGxm+j|F5Iwwu~Qtw+WL}dZfR+M^5}S`T*;nEx5fPnemQ;F7LVbwX*Z6AcLZhL0~`BJv`UX>Dx_!yev>B0=0zayAx zOVJIPy5<)c*c`Z`bUE?^ls6p2ri{K7_`+bYw3HN&;NW25=azqIYojRJ)ew1|_su)& z!`6w*JnvjO6h#yahU0qcLuUkIkQd#~~1ijDmt+=uCIhIlnncx2o2Ri@|yK z4l5PCer?p(*B9RUNUtX4tW8l~p3%XB2hA~Ae_*MYd;kPcYv)4MBQ3ZwUS=Xi`4<`x#HDB&WHVRq!o<`Y$`jDotl zi(a0dvn}yIO-zP|hm$_XpVgrXBOwa9mOy;U_9_;S&#=x$K70Gt6o#+9hQVMOCX-P6 zeHV60(6axxRgAjA!109Ww&d?KHtf{NZ{L6neO(H>t2RXvh2a6{RjryxPx_%8Q+Y(POtv z8f?^lt^!(cX*8NZz+?1txt?HajEOgYx`c)@q@|^CVPRpB3DQ2S+FD%=HMNStL1$FR z)P4GBmP^Swsg}-?+S>kGw{B_v@=M$A|9o;6Ei5U~!PJIKw=eCuxVQwo{^MV|kxQTM z!!;S~y~E!+wR@b|)ScJSBR9|AZX&H!<>loq1?UD0dC~;4AM*(W;?_5>;kw}b`N7IJ zot;C&!}~K3$0-{)u+gC*e2QmlYwLv8mrl9|<@@@+>jz^Fh+EPE#+&t{gqcCjTA13P z@#g!<`GtjTX>j*Iu*e0BjI6A8E_J)GhRKZZ6`;j`^h`5ykYpH9btU;2J2oe#`AS8b2&MqEsk9IRLF;Pld9A~@J9zA?` zY}YOMg#LamG?6#vR{6aX`djE@5@OtZv*g3Vv<*$h) z76%>{@EG12dU{U9j-{Ns;7O!nEh}4WlY3=i@!0hAG{~z}hb}ieyL>BO_xglBX?AC0 z+zAj=nHUA< z1E|#c^YX+`L>l<`_yAIK=K6|jZvG>RiFQqRP_W3}+bxOKAldd6_ht`&qXJF92%0RuKcAl_7a;9#WWJ<=T_x|j7LLMD4RKYn$=Z_1HUL%njPLO6#mAcm3*3{I{3Y4jvhTqrc?J$`5z^1i+>z-vBbX-|yAD0Wo zAVa@&x?6{?FOIu|zWBO3Pj!RFN?zoU)T88yBXz+U7rg$u5w&a*Fvh}lb#)=b=N|o) zkg(QkgEq-xH#Fb@A|?<|Lmc;e*Ey^CP=sHsVUEn&dzFVzA5hR-FlEw zW?AJd)(EHvmNdxm^RIF!>p1d!&4B-_-+oYS+fP(LGhOn!U@4%#%*`(~H8m|G!uaY3tj!8Bhx=s~Qf6b6?i{=pax7`x_$`mzF^-dIh*%T2*yHc-cBbr!7hG(vQKc z$#==agOwguG>Gz*5g@Lns_I+P#sa0+^*!YAsO6>ci`1Ppr|GFFH8k2?N=Ea#l~p1j z$#WX*$F5908|7$Wa0L9=fMI$xW-oeqZNU92n2oehKcjQ!lL18W;&l+lp&CD@P0gPI zsY1O)gt@sn4H__5afs~uNUG;G~(UDPQ_J!V{o$ingredients.erase(this->ingredients.begin() + index); +} + vector IngredientListModel::getIngredients(){ return this->ingredients; } diff --git a/model/recipe/tags/taglistmodel.cpp b/model/recipe/tags/taglistmodel.cpp index dd70b3f..4555cd7 100644 --- a/model/recipe/tags/taglistmodel.cpp +++ b/model/recipe/tags/taglistmodel.cpp @@ -39,6 +39,10 @@ bool TagListModel::addTag(RecipeTag tag){ return true; } +void TagListModel::deleteTag(int index){ + this->tags.erase(this->tags.begin() + index); +} + vector TagListModel::getTags(){ return this->tags; } -- 2.34.1 From cbb2079a7fe7d7de9359a3216c8dfa2b59a6f50d Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 13:22:04 +0100 Subject: [PATCH 2/6] Added support for custom images. --- gui/newrecipedialog.cpp | 13 ++++++++++-- gui/newrecipedialog.h | 7 +++++++ gui/newrecipedialog.ui | 20 ++++++++++++++++++- .../recipe/ingredients/ingredientlistmodel.h | 1 + model/recipe/tags/taglistmodel.h | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp index 2b4123f..058b0dd 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{ @@ -103,9 +104,17 @@ void NewRecipeDialog::on_addTagButton_clicked(){ } void NewRecipeDialog::on_deleteTagButton_clicked(){ - QModelIndexList indexList = ui->tagsListView->selectedIndexes(); + 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)); + } +} diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h index 47cd848..6e14097 100644 --- a/gui/newrecipedialog.h +++ b/gui/newrecipedialog.h @@ -3,6 +3,8 @@ #include #include +#include +#include #include "model/database/recipedatabase.h" #include "model/recipe/ingredients/ingredientlistmodel.h" @@ -36,6 +38,10 @@ class NewRecipeDialog : public QDialog void on_addTagButton_clicked(); + void on_deleteTagButton_clicked(); + + void on_selectImageButton_clicked(); + private: Ui::NewRecipeDialog *ui; RecipeDatabase *recipeDB; @@ -44,6 +50,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 0a0875c..25ffbbc 100644 --- a/gui/newrecipedialog.ui +++ b/gui/newrecipedialog.ui @@ -630,9 +630,18 @@ + + + 500 + 500 + + + + :/images/images/no_image.png + true @@ -641,6 +650,13 @@ + + + + Select Image... + + + @@ -735,6 +751,8 @@ - + + + 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.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; -- 2.34.1 From 4f78b374609cb3a3d7985f26f3fc528c541ba6d6 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 14:06:24 +0100 Subject: [PATCH 3/6] Added window icons, add new ingredient and add new tag dialogs. --- RecipeDB.pro | 12 +- gui/mainwindow.ui | 8 +- gui/newDialogs/newingredientdialog.cpp | 18 +++ gui/newDialogs/newingredientdialog.h | 26 ++++ gui/newDialogs/newingredientdialog.ui | 120 ++++++++++++++++++ gui/newDialogs/newtagdialog.cpp | 18 +++ gui/newDialogs/newtagdialog.h | 26 ++++ gui/newDialogs/newtagdialog.ui | 92 ++++++++++++++ gui/newrecipedialog.cpp | 24 ++++ gui/newrecipedialog.h | 9 ++ gui/newrecipedialog.ui | 30 ++++- images.qrc | 1 + images/icon.png | Bin 0 -> 912 bytes .../ingredients/ingredientlistmodel.cpp | 1 + model/recipe/tags/taglistmodel.cpp | 1 + 15 files changed, 381 insertions(+), 5 deletions(-) create mode 100644 gui/newDialogs/newingredientdialog.cpp create mode 100644 gui/newDialogs/newingredientdialog.h create mode 100644 gui/newDialogs/newingredientdialog.ui create mode 100644 gui/newDialogs/newtagdialog.cpp create mode 100644 gui/newDialogs/newtagdialog.h create mode 100644 gui/newDialogs/newtagdialog.ui create mode 100644 images/icon.png diff --git a/RecipeDB.pro b/RecipeDB.pro index c2c8a98..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,12 +46,16 @@ 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 diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index ae24fae..252d695 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -25,6 +25,10 @@ RecipeDB + + + :/images/images/icon.png:/images/images/icon.png + 1.000000000000000 @@ -556,6 +560,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 058b0dd..4cfaeea 100644 --- a/gui/newrecipedialog.cpp +++ b/gui/newrecipedialog.cpp @@ -118,3 +118,27 @@ void NewRecipeDialog::on_selectImageButton_clicked(){ 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.show(); + +} diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h index 6e14097..43ff140 100644 --- a/gui/newrecipedialog.h +++ b/gui/newrecipedialog.h @@ -10,6 +10,9 @@ #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; } @@ -42,6 +45,12 @@ class NewRecipeDialog : public QDialog void on_selectImageButton_clicked(); + void on_deleteIngredientButton_clicked(); + + void on_newIngredientButton_clicked(); + + void on_newTagButton_clicked(); + private: Ui::NewRecipeDialog *ui; RecipeDatabase *recipeDB; diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui index 25ffbbc..9a72e5e 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 @@ -327,6 +334,9 @@ QFrame::NoFrame + + QAbstractItemView::MultiSelection + @@ -599,6 +609,9 @@ QFrame::NoFrame + + QAbstractItemView::MultiSelection + 100 @@ -610,7 +623,7 @@ - + @@ -665,6 +678,9 @@ + + background-color: rgb(250, 250, 255); + @@ -728,6 +744,12 @@ + + background-color: rgb(255, 255, 255); + + + QFrame::NoFrame + Enter instructions here. @@ -741,9 +763,15 @@ Qt::LeftToRight + + false + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + true + diff --git a/images.qrc b/images.qrc index 6634926..5f9348c 100644 --- a/images.qrc +++ b/images.qrc @@ -1,5 +1,6 @@ images/no_image.png + images/icon.png diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9a2db3c33ebcf57ecdf1bc565dc7773efe8eb524 GIT binary patch literal 912 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIE+9%l7&9>S(9P*t)Fc{f3hMWqbx2UKLX|J~|UpFxl6yta{%ys|jCsSl3^D zx<|I}vT}nZ6GP%C8juiJ{{6Z6-bTmmugj~LoWIq6XLOj!;4otp(LDriY`Yc(%nFkA YXGHkTHi-Eo0J9i_r>mdKI;Vst0F?>R`Tzg` literal 0 HcmV?d00001 diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp index 360d48c..7763671 100644 --- a/model/recipe/ingredients/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -55,6 +55,7 @@ bool IngredientListModel::addIngredient(RecipeIngredient ri){ 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(){ diff --git a/model/recipe/tags/taglistmodel.cpp b/model/recipe/tags/taglistmodel.cpp index 4555cd7..149ad3e 100644 --- a/model/recipe/tags/taglistmodel.cpp +++ b/model/recipe/tags/taglistmodel.cpp @@ -41,6 +41,7 @@ bool TagListModel::addTag(RecipeTag tag){ 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(){ -- 2.34.1 From b4ce47aad5dd2938a169f06b253d02eb79171c94 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 14:56:43 +0100 Subject: [PATCH 4/6] Added icons to add and delete buttons, fixed out of bounds error on deletion. --- gui/newrecipedialog.cpp | 26 +++++++++++++- gui/newrecipedialog.h | 3 ++ gui/newrecipedialog.ui | 57 ++++++++++++++++++++++++------ images.qrc | 2 ++ images/minus_icon.png | Bin 0 -> 480 bytes images/plus_icon.png | Bin 0 -> 912 bytes model/database/recipedatabase.cpp | 4 +++ model/database/recipedatabase.h | 3 ++ 8 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 images/minus_icon.png create mode 100644 images/plus_icon.png diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp index 4cfaeea..0517fd9 100644 --- a/gui/newrecipedialog.cpp +++ b/gui/newrecipedialog.cpp @@ -138,7 +138,31 @@ void NewRecipeDialog::on_newIngredientButton_clicked(){ } void NewRecipeDialog::on_newTagButton_clicked(){ - newTagDialog + 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 43ff140..f1c87cb 100644 --- a/gui/newrecipedialog.h +++ b/gui/newrecipedialog.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "model/database/recipedatabase.h" #include "model/recipe/ingredients/ingredientlistmodel.h" @@ -51,6 +52,8 @@ class NewRecipeDialog : public QDialog void on_newTagButton_clicked(); + void on_removeTagButton_clicked(); + private: Ui::NewRecipeDialog *ui; RecipeDatabase *recipeDB; diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui index 9a72e5e..82afc1d 100644 --- a/gui/newrecipedialog.ui +++ b/gui/newrecipedialog.ui @@ -279,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 @@ -460,6 +482,9 @@ 0 + + false + @@ -467,8 +492,12 @@ - - New + + Create a new ingredient + + + + :/images/images/plus_icon.png:/images/images/plus_icon.png @@ -532,12 +561,20 @@ - + + + + 0 + 0 + + + - + - - New + + + :/images/images/plus_icon.png:/images/images/plus_icon.png diff --git a/images.qrc b/images.qrc index 5f9348c..2391914 100644 --- a/images.qrc +++ b/images.qrc @@ -2,5 +2,7 @@ images/no_image.png images/icon.png + images/plus_icon.png + images/minus_icon.png diff --git a/images/minus_icon.png b/images/minus_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f8067928e904e6ee2bd1ffd2807a0a9221a978ac GIT binary patch literal 480 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIGw`>7Fi* zAr*7pUU3vWpuliogJJK9Bg)1Hd) 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. -- 2.34.1 From 15117d66588c751b56547658ba5048ec63a6b981 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 15:32:26 +0100 Subject: [PATCH 5/6] Made the integral change: recipes can be added. --- gui/mainwindow.ui | 15 ++++++++- main.cpp | 61 +++++++++++++++++------------------- userInterface/mainwindow.cpp | 24 +++++++++++++- userInterface/mainwindow.h | 9 +++++- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 252d695..a527789 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; } - + @@ -547,6 +547,19 @@ p, li { white-space: pre-wrap; } 0 + + + + :/images/images/no_image.png + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + diff --git a/main.cpp b/main.cpp index 23f8db2..ab7a5f2 100644 --- a/main.cpp +++ b/main.cpp @@ -7,49 +7,46 @@ 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); - - NewRecipeDialog d(&recipeDB); - d.show(); - d.exec(); - - if (d.isAccepted()){ - printf("Accepted the dialog.\n"); - } +// if (d.isAccepted()){ +// printf("Accepted the dialog.\n"); +// } return a.exec(); } diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index 69a6189..8d92a70 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,7 @@ void MainWindow::loadFromRecipe(Recipe recipe){ setRecipeName(recipe.getName()); setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); + setImage(recipe.getImage()); } void MainWindow::setRecipeName(string name){ @@ -28,5 +33,22 @@ 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::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..2f2591b 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,24 @@ 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); }; #endif // MAINWINDOW_H -- 2.34.1 From 44f89031541a50d3f64a086202584ea87124fd31 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 16:02:01 +0100 Subject: [PATCH 6/6] Added extra stats to user interface. --- gui/mainwindow.ui | 197 ++++++++++++++++++++++++++++++----- main.cpp | 2 + userInterface/mainwindow.cpp | 15 +++ userInterface/mainwindow.h | 3 + 4 files changed, 192 insertions(+), 25 deletions(-) diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index a527789..58638ed 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -241,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 + + + + @@ -417,6 +558,12 @@ QPushButton#browseButton:pressed{ 0 + + + 400 + 0 + + 0 diff --git a/main.cpp b/main.cpp index ab7a5f2..4e49c1e 100644 --- a/main.cpp +++ b/main.cpp @@ -48,5 +48,7 @@ int main(int argc, char *argv[]) // printf("Accepted the dialog.\n"); // } + w.loadFromRecipe(recipeDB.retrieveRecipe("Generic Bread")); + return a.exec(); } diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index 8d92a70..b39eec6 100644 --- a/userInterface/mainwindow.cpp +++ b/userInterface/mainwindow.cpp @@ -22,6 +22,9 @@ void MainWindow::loadFromRecipe(Recipe recipe){ setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); setImage(recipe.getImage()); + setPrepTime(recipe.getPrepTime()); + setCookTime(recipe.getCookTime()); + setServings(recipe.getServings()); } void MainWindow::setRecipeName(string name){ @@ -40,6 +43,18 @@ 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(); diff --git a/userInterface/mainwindow.h b/userInterface/mainwindow.h index 2f2591b..1605311 100644 --- a/userInterface/mainwindow.h +++ b/userInterface/mainwindow.h @@ -39,6 +39,9 @@ public: 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 -- 2.34.1