Added ability to edit recipe (WIP).

This commit is contained in:
Andrew Lalis 2018-03-30 23:25:28 +02:00
parent f13432a2fe
commit 6597efa646
8 changed files with 57 additions and 17 deletions

View File

@ -31,6 +31,7 @@ void MainWindow::loadFromRecipe(Recipe recipe){
setCookTime(recipe.getCookTime());
setServings(recipe.getServings());
setTags(recipe.getTags());
this->currentRecipe = recipe;
}
void MainWindow::setRecipeName(string name){
@ -91,3 +92,17 @@ void MainWindow::on_openButton_clicked(){
void MainWindow::on_exitButton_clicked(){
this->close();
}
void MainWindow::on_editButton_clicked(){
NewRecipeDialog d(this->recipeDB, this->currentRecipe, 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. Make sure to give the recipe a name, instructions, and some ingredients!"));
} else {
this->loadFromRecipe(r);
}
}
}

View File

@ -36,11 +36,14 @@ public:
void on_exitButton_clicked();
void on_editButton_clicked();
private:
Ui::MainWindow *ui;
RecipeDatabase *recipeDB;
RecipeIngredientListModel ingredientModel;
TagListModel tagsListModel;
Recipe currentRecipe;
//Hidden manipulation methods.
void setRecipeName(string name);

View File

@ -180,9 +180,9 @@ QPushButton#openButton:pressed{
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="browseButton">
<widget class="QPushButton" name="editButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
@ -201,19 +201,19 @@ QPushButton#openButton:pressed{
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">QPushButton#browseButton {
<string notr="true">QPushButton#editButton {
background-color: rgb(215, 215, 255);
border: 0px;
}
QPushButton#browseButton:hover{
QPushButton#editButton:hover{
background-color: rgb(225, 225, 255);
}
QPushButton#browseButton:pressed{
QPushButton#editButton:pressed{
background-color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>Browse</string>
<string>Edit</string>
</property>
<property name="flat">
<bool>false</bool>
@ -363,6 +363,9 @@ font: &quot;Noto Sans CJK KR&quot;;</string>
</item>
<item alignment="Qt::AlignLeft|Qt::AlignBottom">
<widget class="QLabel" name="authorLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>

View File

@ -21,6 +21,17 @@ NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecip
this->populateTagsBox();
}
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent) : NewRecipeDialog(db, parent){
ui->recipeNameEdit->setText(QString::fromStdString(recipe.getName()));
ui->prepTimeEdit->setTime(recipe.getPrepTime());
ui->cookTimeEdit->setTime(recipe.getCookTime());
ui->servingsSpinBox->setValue((double)recipe.getServings());
ui->instructionsTextEdit->setHtml(QString::fromStdString(recipe.getInstruction().getHTML()));
ui->imageDisplayLabel->setPixmap(QPixmap::fromImage(recipe.getImage()));
this->tagsListModel.setTags(recipe.getTags());
this->ingredientListModel.setIngredients(recipe.getIngredients());
}
NewRecipeDialog::~NewRecipeDialog(){
delete ui;
}

View File

@ -26,6 +26,7 @@ class NewRecipeDialog : public QDialog
public:
explicit NewRecipeDialog(QWidget *parent = 0);
NewRecipeDialog(RecipeDatabase *db, QWidget *parent = 0);
NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent = 0);
~NewRecipeDialog();
Recipe getRecipe();

View File

@ -48,18 +48,18 @@ void test(RecipeDatabase *recipeDB){
bool success = recipeDB->storeRecipe(rec);
printf("Storage successful: %d\n", success);
vector<string> foodGroups = recipeDB->retrieveAllFoodGroups();
printf("Food Groups:\n");
for (string s : foodGroups){
printf("\t%s\n", s.c_str());
}
// vector<string> foodGroups = recipeDB->retrieveAllFoodGroups();
// printf("Food Groups:\n");
// for (string s : foodGroups){
// printf("\t%s\n", s.c_str());
// }
//Get food groups from recipe.
Recipe r = recipeDB->retrieveRecipe("Pannenkoeken");
vector<string> foodGroupsR = r.getFoodGroups();
printf("Pannenkoeken Food Groups:\n");
for (string s : foodGroupsR){
printf("\t%s\n", s.c_str());
}
// Recipe r = recipeDB->retrieveRecipe("Pannenkoeken");
// vector<string> foodGroupsR = r.getFoodGroups();
// printf("Pannenkoeken Food Groups:\n");
// for (string s : foodGroupsR){
// printf("\t%s\n", s.c_str());
// }
}

View File

@ -356,6 +356,10 @@ bool RecipeDatabase::deleteTag(RecipeTag tag){
return this->deleteFrom("recipeTag", "WHERE tagName='"+tag.getValue()+"'");
}
bool RecipeDatabase::updateRecipe(Recipe recipe){
}
void RecipeDatabase::ensureTablesExist(){
//Make sure that foreign keys are enabled.
this->executeSQL("PRAGMA foreign_keys = ON;");

View File

@ -51,6 +51,9 @@ class RecipeDatabase : public Database
bool deleteIngredient(string name);
bool deleteUnitOfMeasure(string name);
bool deleteTag(RecipeTag tag);
//Updating.
bool updateRecipe(Recipe recipe);
private:
//Utility methods.