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 0000000..f806792 Binary files /dev/null and b/images/minus_icon.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/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.