Added search by food group.
This commit is contained in:
parent
4170df7fc8
commit
f13432a2fe
|
@ -15,12 +15,17 @@ OpenRecipeDialog::OpenRecipeDialog(QWidget *parent) :
|
||||||
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||||
this,
|
this,
|
||||||
SLOT(onIngredientsListViewSelectionChanged(QItemSelection)));
|
SLOT(onIngredientsListViewSelectionChanged(QItemSelection)));
|
||||||
|
QObject::connect(ui->tagsListView->selectionModel(),
|
||||||
|
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||||
|
this,
|
||||||
|
SLOT(onTagsListViewSelectionChanged(QItemSelection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){
|
OpenRecipeDialog::OpenRecipeDialog(RecipeDatabase *recipeDB, QWidget *parent) : OpenRecipeDialog(parent){
|
||||||
this->recipeDB = recipeDB;
|
this->recipeDB = recipeDB;
|
||||||
this->populateIngredientsList();
|
this->populateIngredientsList();
|
||||||
this->populateTagsList();
|
this->populateTagsList();
|
||||||
|
this->populateFoodGroupsList();
|
||||||
this->populateRecipesTable(this->recipeDB->retrieveAllRecipes());
|
this->populateRecipesTable(this->recipeDB->retrieveAllRecipes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +53,13 @@ void OpenRecipeDialog::populateTagsList(){
|
||||||
this->tagsModel.setTags(this->recipeDB->retrieveAllTags());
|
this->tagsModel.setTags(this->recipeDB->retrieveAllTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenRecipeDialog::populateFoodGroupsList(){
|
||||||
|
for (string s : this->recipeDB->retrieveAllFoodGroups()){
|
||||||
|
ui->foodGroupsListWidget->addItem(QString::fromStdString(s));
|
||||||
|
}
|
||||||
|
//ui->foodGroupsListWidget->show();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
|
void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
|
||||||
QItemSelectionModel *selectModel = ui->recipeTableView->selectionModel();
|
QItemSelectionModel *selectModel = ui->recipeTableView->selectionModel();
|
||||||
if (!selectModel->hasSelection()){
|
if (!selectModel->hasSelection()){
|
||||||
|
@ -81,6 +93,7 @@ void OpenRecipeDialog::on_recipeTableView_doubleClicked(const QModelIndex &index
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenRecipeDialog::onIngredientsListViewSelectionChanged(const QItemSelection &selection){
|
void OpenRecipeDialog::onIngredientsListViewSelectionChanged(const QItemSelection &selection){
|
||||||
|
Q_UNUSED(selection);
|
||||||
vector<Ingredient> ingredients;
|
vector<Ingredient> ingredients;
|
||||||
QModelIndexList indexes = ui->ingredientsListView->selectionModel()->selectedRows();
|
QModelIndexList indexes = ui->ingredientsListView->selectionModel()->selectedRows();
|
||||||
for (QModelIndex index : indexes){
|
for (QModelIndex index : indexes){
|
||||||
|
@ -89,3 +102,28 @@ void OpenRecipeDialog::onIngredientsListViewSelectionChanged(const QItemSelectio
|
||||||
}
|
}
|
||||||
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithIngredients(ingredients));
|
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithIngredients(ingredients));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenRecipeDialog::onTagsListViewSelectionChanged(const QItemSelection &selection){
|
||||||
|
Q_UNUSED(selection);
|
||||||
|
vector<RecipeTag> tags;
|
||||||
|
QModelIndexList indexes = ui->tagsListView->selectionModel()->selectedRows();
|
||||||
|
for (QModelIndex index : indexes){
|
||||||
|
RecipeTag t = this->tagsModel.getTags().at(index.row());
|
||||||
|
tags.push_back(t);
|
||||||
|
}
|
||||||
|
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithTags(tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenRecipeDialog::on_nameEdit_textChanged(const QString &arg1){
|
||||||
|
Q_UNUSED(arg1);
|
||||||
|
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithSubstring(ui->nameEdit->text().toStdString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenRecipeDialog::on_foodGroupsListWidget_itemSelectionChanged(){
|
||||||
|
vector<string> groups;
|
||||||
|
for (QModelIndex index : ui->foodGroupsListWidget->selectionModel()->selectedRows()){
|
||||||
|
QListWidgetItem *item = ui->foodGroupsListWidget->item(index.row());
|
||||||
|
groups.push_back(item->text().toStdString());
|
||||||
|
}
|
||||||
|
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithFoodGroups(groups));
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,12 @@ class OpenRecipeDialog : public QDialog
|
||||||
|
|
||||||
void onIngredientsListViewSelectionChanged(const QItemSelection &selection);
|
void onIngredientsListViewSelectionChanged(const QItemSelection &selection);
|
||||||
|
|
||||||
|
void onTagsListViewSelectionChanged(const QItemSelection &selection);
|
||||||
|
|
||||||
|
void on_nameEdit_textChanged(const QString &arg1);
|
||||||
|
|
||||||
|
void on_foodGroupsListWidget_itemSelectionChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::OpenRecipeDialog *ui;
|
Ui::OpenRecipeDialog *ui;
|
||||||
RecipeDatabase *recipeDB;
|
RecipeDatabase *recipeDB;
|
||||||
|
@ -44,6 +50,7 @@ class OpenRecipeDialog : public QDialog
|
||||||
void populateRecipesTable(vector<Recipe> recipes);
|
void populateRecipesTable(vector<Recipe> recipes);
|
||||||
void populateIngredientsList();
|
void populateIngredientsList();
|
||||||
void populateTagsList();
|
void populateTagsList();
|
||||||
|
void populateFoodGroupsList();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPENRECIPEDIALOG_H
|
#endif // OPENRECIPEDIALOG_H
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1000</width>
|
<width>1064</width>
|
||||||
<height>480</height>
|
<height>480</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -25,15 +25,27 @@
|
||||||
<widget class="QWidget" name="searchPanel" native="true">
|
<widget class="QWidget" name="searchPanel" native="true">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item alignment="Qt::AlignLeft">
|
<item alignment="Qt::AlignLeft">
|
||||||
<widget class="QWidget" name="tagsSearchpanel" native="true">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<property name="minimumSize">
|
||||||
<item>
|
<size>
|
||||||
<widget class="QLabel" name="tagLabel">
|
<width>290</width>
|
||||||
<property name="text">
|
<height>0</height>
|
||||||
<string>Tag</string>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="tabPosition">
|
||||||
</item>
|
<enum>QTabWidget::South</enum>
|
||||||
|
</property>
|
||||||
|
<property name="tabShape">
|
||||||
|
<enum>QTabWidget::Rounded</enum>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tagsTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Tags</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="tagsListView">
|
<widget class="QListView" name="tagsListView">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -48,27 +60,24 @@
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
<property name="isWrapping" stdset="0">
|
<property name="isWrapping" stdset="0">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
<widget class="QWidget" name="ingredientsTab">
|
||||||
<item alignment="Qt::AlignLeft">
|
<attribute name="title">
|
||||||
<widget class="QWidget" name="ingredientSearchPanel" native="true">
|
<string>Ingredients</string>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
</attribute>
|
||||||
<item>
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
<widget class="QLabel" name="ingredientLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Ingredient</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="ingredientsListView">
|
<widget class="QListView" name="ingredientsListView">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -83,6 +92,9 @@
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
<property name="isWrapping" stdset="0">
|
<property name="isWrapping" stdset="0">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -93,6 +105,30 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Food Groups</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="foodGroupsListWidget">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="nameSearchPanel" native="true">
|
<widget class="QWidget" name="nameSearchPanel" native="true">
|
||||||
|
|
|
@ -189,6 +189,39 @@ vector<Recipe> RecipeDatabase::retrieveRecipesWithIngredients(vector<Ingredient>
|
||||||
return this->readRecipesFromTable(t);
|
return this->readRecipesFromTable(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<Recipe> RecipeDatabase::retrieveRecipesWithTags(vector<RecipeTag> tags){
|
||||||
|
vector<Recipe> recipes;
|
||||||
|
if (tags.empty()){
|
||||||
|
return recipes;
|
||||||
|
}
|
||||||
|
string filterList = surroundString(tags.at(0).getValue(), "'");
|
||||||
|
for (unsigned int i = 1; i < tags.size(); i++){
|
||||||
|
filterList += ", " + surroundString(tags[i].getValue(), "'");
|
||||||
|
}
|
||||||
|
filterList = '(' + filterList + ')';
|
||||||
|
ResultTable t = this->executeSQL("SELECT * FROM recipe WHERE recipeId IN (SELECT recipeId FROM recipeTag WHERE tagName IN "+filterList+" );");
|
||||||
|
return this->readRecipesFromTable(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Recipe> RecipeDatabase::retrieveRecipesWithSubstring(string s){
|
||||||
|
ResultTable t = this->executeSQL("SELECT * FROM recipe WHERE name LIKE '%"+s+"%' COLLATE NOCASE;");
|
||||||
|
return this->readRecipesFromTable(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Recipe> RecipeDatabase::retrieveRecipesWithFoodGroups(vector<string> groups){
|
||||||
|
vector<Recipe> recipes;
|
||||||
|
if (groups.empty()){
|
||||||
|
return recipes;
|
||||||
|
}
|
||||||
|
string filterList = surroundString(groups.at(0), "'");
|
||||||
|
for (unsigned int i = 1; i < groups.size(); i++){
|
||||||
|
filterList += ", " + surroundString(groups.at(i), "'");
|
||||||
|
}
|
||||||
|
filterList = '(' + filterList + ')';
|
||||||
|
ResultTable t = this->executeSQL("SELECT * FROM recipe WHERE recipeId IN (SELECT recipeId FROM recipeIngredient WHERE ingredientId IN (SELECT ingredientId FROM ingredient WHERE foodGroup IN "+filterList+" ) ) ORDER BY name;");
|
||||||
|
return this->readRecipesFromTable(t);
|
||||||
|
}
|
||||||
|
|
||||||
vector<string> RecipeDatabase::retrieveAllFoodGroups(){
|
vector<string> RecipeDatabase::retrieveAllFoodGroups(){
|
||||||
ResultTable t = this->executeSQL("SELECT DISTINCT foodGroup FROM ingredient ORDER BY foodGroup;");
|
ResultTable t = this->executeSQL("SELECT DISTINCT foodGroup FROM ingredient ORDER BY foodGroup;");
|
||||||
vector<string> foodGroups;
|
vector<string> foodGroups;
|
||||||
|
|
|
@ -35,6 +35,9 @@ class RecipeDatabase : public Database
|
||||||
Recipe retrieveRandomRecipe();
|
Recipe retrieveRandomRecipe();
|
||||||
vector<Recipe> retrieveAllRecipes();
|
vector<Recipe> retrieveAllRecipes();
|
||||||
vector<Recipe> retrieveRecipesWithIngredients(vector<Ingredient> ingredients);
|
vector<Recipe> retrieveRecipesWithIngredients(vector<Ingredient> ingredients);
|
||||||
|
vector<Recipe> retrieveRecipesWithTags(vector<RecipeTag> tags);
|
||||||
|
vector<Recipe> retrieveRecipesWithSubstring(string s);
|
||||||
|
vector<Recipe> retrieveRecipesWithFoodGroups(vector<string> groups);
|
||||||
vector<string> retrieveAllFoodGroups();
|
vector<string> retrieveAllFoodGroups();
|
||||||
vector<RecipeIngredient> retrieveRecipeIngredients(int recipeId);
|
vector<RecipeIngredient> retrieveRecipeIngredients(int recipeId);
|
||||||
vector<Ingredient> retrieveAllIngredients();
|
vector<Ingredient> retrieveAllIngredients();
|
||||||
|
|
Loading…
Reference in New Issue