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,73 +25,109 @@
|
||||||
<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>
|
||||||
<item>
|
</property>
|
||||||
<widget class="QListView" name="tagsListView">
|
<property name="tabShape">
|
||||||
<property name="sizePolicy">
|
<enum>QTabWidget::Rounded</enum>
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
</property>
|
||||||
<horstretch>0</horstretch>
|
<property name="currentIndex">
|
||||||
<verstretch>0</verstretch>
|
<number>2</number>
|
||||||
</sizepolicy>
|
</property>
|
||||||
</property>
|
<widget class="QWidget" name="tagsTab">
|
||||||
<property name="frameShape">
|
<attribute name="title">
|
||||||
<enum>QFrame::NoFrame</enum>
|
<string>Tags</string>
|
||||||
</property>
|
</attribute>
|
||||||
<property name="selectionMode">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
<item>
|
||||||
</property>
|
<widget class="QListView" name="tagsListView">
|
||||||
<property name="isWrapping" stdset="0">
|
<property name="sizePolicy">
|
||||||
<bool>false</bool>
|
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||||
</property>
|
<horstretch>0</horstretch>
|
||||||
<property name="wordWrap">
|
<verstretch>0</verstretch>
|
||||||
<bool>false</bool>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="frameShape">
|
||||||
</item>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</layout>
|
</property>
|
||||||
</widget>
|
<property name="selectionMode">
|
||||||
</item>
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
<item alignment="Qt::AlignLeft">
|
</property>
|
||||||
<widget class="QWidget" name="ingredientSearchPanel" native="true">
|
<property name="verticalScrollMode">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
<item>
|
</property>
|
||||||
<widget class="QLabel" name="ingredientLabel">
|
<property name="isWrapping" stdset="0">
|
||||||
<property name="text">
|
<bool>false</bool>
|
||||||
<string>Ingredient</string>
|
</property>
|
||||||
</property>
|
<property name="wordWrap">
|
||||||
</widget>
|
<bool>true</bool>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
</widget>
|
||||||
<widget class="QListView" name="ingredientsListView">
|
</item>
|
||||||
<property name="sizePolicy">
|
</layout>
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
</widget>
|
||||||
<horstretch>0</horstretch>
|
<widget class="QWidget" name="ingredientsTab">
|
||||||
<verstretch>0</verstretch>
|
<attribute name="title">
|
||||||
</sizepolicy>
|
<string>Ingredients</string>
|
||||||
</property>
|
</attribute>
|
||||||
<property name="frameShape">
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
<enum>QFrame::NoFrame</enum>
|
<item>
|
||||||
</property>
|
<widget class="QListView" name="ingredientsListView">
|
||||||
<property name="selectionMode">
|
<property name="sizePolicy">
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||||
</property>
|
<horstretch>0</horstretch>
|
||||||
<property name="isWrapping" stdset="0">
|
<verstretch>0</verstretch>
|
||||||
<bool>false</bool>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="frameShape">
|
||||||
<bool>true</bool>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="selectionMode">
|
||||||
</item>
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
</layout>
|
</property>
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</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>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -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