diff --git a/gui/openrecipedialog.cpp b/gui/openrecipedialog.cpp index 716e354..648beb9 100644 --- a/gui/openrecipedialog.cpp +++ b/gui/openrecipedialog.cpp @@ -10,6 +10,11 @@ OpenRecipeDialog::OpenRecipeDialog(QWidget *parent) : ui->recipeTableView->setModel(&this->recipeTableModel); ui->ingredientsListView->setModel(&this->ingredientsModel); ui->tagsListView->setModel(&this->tagsModel); + + connect(ui->ingredientsListView->selectionModel(), + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, + SLOT(on_ingredientsListView_selectionChanged(QItemSelection))); } OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){ @@ -74,3 +79,14 @@ void OpenRecipeDialog::on_recipeTableView_doubleClicked(const QModelIndex &index this->selectedRecipe = this->recipeTableModel.getRecipeAt(index.row()); this->close(); } + +void OpenRecipeDialog::on_ingredientsListView_selectionChanged(const QItemSelection &selection){ + printf("Selection changed!\n"); + vector ingredients; + for (QModelIndex index : selection.indexes()){ + Ingredient i = this->ingredientsModel.getIngredients().at(index.row()); + ingredients.push_back(i); + printf("Selected: %s\n", i.getName().c_str()); + } + +} diff --git a/gui/openrecipedialog.h b/gui/openrecipedialog.h index d762d39..44c56f9 100644 --- a/gui/openrecipedialog.h +++ b/gui/openrecipedialog.h @@ -3,6 +3,7 @@ #include #include +#include #include "model/database/recipedatabase.h" #include "model/recipe/recipetablemodel.h" @@ -29,6 +30,8 @@ class OpenRecipeDialog : public QDialog void on_recipeTableView_doubleClicked(const QModelIndex &index); + void on_ingredientsListView_selectionChanged(const QItemSelection &selection); + private: Ui::OpenRecipeDialog *ui; RecipeDatabase *recipeDB;