From 019e0e3cde9ba8f3542489b7eb9925811c7d3abf Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Fri, 30 Mar 2018 16:20:09 +0200 Subject: [PATCH] Added selection listener. --- gui/openrecipedialog.cpp | 16 ++++++++++++++++ gui/openrecipedialog.h | 3 +++ 2 files changed, 19 insertions(+) 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;