From 4554fdcd1e3b997f2192f829aa0c0c28c96c9aa9 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 22 May 2018 23:21:15 +0200 Subject: [PATCH] Fixed compilation bugs. Program runs. --- gui/newrecipedialog.cpp | 2 -- gui/newrecipedialog.h | 2 -- gui/openrecipedialog.cpp | 22 ------------------- model/database/database.cpp | 5 ++++- model/database/recipedatabase.cpp | 2 +- .../ingredients/ingredientlistmodel.cpp | 4 ++-- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp index 87afeed..1d9a6c5 100644 --- a/gui/newrecipedialog.cpp +++ b/gui/newrecipedialog.cpp @@ -15,8 +15,6 @@ NewRecipeDialog::NewRecipeDialog(QWidget *parent) : NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){ this->recipeDB = db; - this->populateIngredientsBox(); - this->populateUnitsBox(); this->populateTagsBox(); } diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h index 909f80c..99d7af8 100644 --- a/gui/newrecipedialog.h +++ b/gui/newrecipedialog.h @@ -11,9 +11,7 @@ #include "model/recipe/ingredients/ingredientlistmodel.h" #include "model/recipe/tags/taglistmodel.h" -#include "gui/newDialogs/newingredientdialog.h" #include "gui/newDialogs/newtagdialog.h" -#include "gui/newDialogs/newunitdialog.h" namespace Ui { class NewRecipeDialog; diff --git a/gui/openrecipedialog.cpp b/gui/openrecipedialog.cpp index 6e3d474..7984736 100644 --- a/gui/openrecipedialog.cpp +++ b/gui/openrecipedialog.cpp @@ -74,17 +74,6 @@ void OpenRecipeDialog::on_recipeTableView_doubleClicked(const QModelIndex &index this->close(); } -void OpenRecipeDialog::onIngredientsListViewSelectionChanged(const QItemSelection &selection){ - Q_UNUSED(selection); - vector ingredients; - QModelIndexList indexes = ui->ingredientsListView->selectionModel()->selectedRows(); - for (QModelIndex index : indexes){ - Ingredient i = this->ingredientsModel.getIngredients().at(index.row()); - ingredients.push_back(i); - } - this->populateRecipesTable(this->recipeDB->retrieveRecipesWithIngredients(ingredients)); -} - void OpenRecipeDialog::onTagsListViewSelectionChanged(const QItemSelection &selection){ Q_UNUSED(selection); vector tags; @@ -101,20 +90,9 @@ void OpenRecipeDialog::on_nameEdit_textChanged(const QString &arg1){ this->populateRecipesTable(this->recipeDB->retrieveRecipesWithSubstring(ui->nameEdit->text().toStdString())); } -void OpenRecipeDialog::on_foodGroupsListWidget_itemSelectionChanged(){ - vector 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)); -} - void OpenRecipeDialog::on_clearSearchButton_clicked(){ ui->nameEdit->clear(); - ui->foodGroupsListWidget->selectionModel()->clearSelection(); ui->tagsListView->selectionModel()->clearSelection(); - ui->ingredientsListView->selectionModel()->clearSelection(); this->populateRecipesTable(this->recipeDB->retrieveAllRecipes()); } diff --git a/model/database/database.cpp b/model/database/database.cpp index ca23338..b879d7c 100644 --- a/model/database/database.cpp +++ b/model/database/database.cpp @@ -15,7 +15,10 @@ ResultTable Database::executeSQL(string statement){ this->sql = statement; this->returnCode = sqlite3_prepare_v2(this->db, statement.c_str(), -1, &stmt, NULL); if (this->returnCode != SQLITE_OK){ - fprintf(stderr, "Unable to successfully prepare SQL statement. Error code: %d\n\tError Message: %s\n", this->returnCode, sqlite3_errmsg(this->db)); + fprintf(stderr, "Unable to successfully prepare SQL statement. Error code: %d\n\tError Message: %s\nSQL Statement: %s\n", + this->returnCode, + sqlite3_errmsg(this->db), + statement.c_str()); return ResultTable(this->returnCode); } ResultTable t(statement); diff --git a/model/database/recipedatabase.cpp b/model/database/recipedatabase.cpp index 9cd1351..08939a8 100644 --- a/model/database/recipedatabase.cpp +++ b/model/database/recipedatabase.cpp @@ -323,7 +323,7 @@ void RecipeDatabase::ensureTablesExist(){ this->executeSQL("CREATE TABLE IF NOT EXISTS recipeIngredient(" "recipeId int," "content," - "FOREIGN KEY (recipeId) REFERENCES recipe(recipeId);"); + "FOREIGN KEY (recipeId) REFERENCES recipe(recipeId));"); this->commitTransaction(); } diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp index e3b4f63..66721d1 100644 --- a/model/recipe/ingredients/ingredientlistmodel.cpp +++ b/model/recipe/ingredients/ingredientlistmodel.cpp @@ -13,7 +13,7 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{ int row = index.row(); Ingredient i = this->ingredients[row]; - string displayStr = i.toString(); + string displayStr = i.getContent(); switch(role){ case Qt::DisplayRole: @@ -38,7 +38,7 @@ bool IngredientListModel::addIngredient(Ingredient i){ } } //The ingredient doesn't exist already, so we'll add it. - this->ingredients.push_back(ri); + this->ingredients.push_back(i); QModelIndex index = createIndex(this->ingredients.size()-1, 0); QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0); emit dataChanged(index, bottomIndex);