From cbb2079a7fe7d7de9359a3216c8dfa2b59a6f50d Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Mar 2018 13:22:04 +0100 Subject: [PATCH] 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;