From fefa913e94063cc3142d83c22bb0d162861ad125 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Thu, 29 Mar 2018 09:58:25 +0200 Subject: [PATCH] Able to display recipes in list in openRecipe dialog. --- RecipeDB.pro | 1 - gui/mainwindow.cpp | 2 +- gui/mainwindow.h | 1 + gui/openrecipedialog.cpp | 7 ++++++- main.cpp | 2 +- model/database/recipedatabase.cpp | 4 ++-- model/database/recipedatabase.h | 1 + model/recipe/recipetablemodel.cpp | 7 ++++++- 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/RecipeDB.pro b/RecipeDB.pro index 580f9c9..92ac7d6 100644 --- a/RecipeDB.pro +++ b/RecipeDB.pro @@ -38,7 +38,6 @@ SOURCES += model/recipe/instruction.cpp \ HEADERS += model/recipe/instruction.h \ model/recipe/recipe.h \ - userInterface/mainwindow.h \ model/database/database.h \ model/recipe/ingredients/unitofmeasure.h \ model/recipe/ingredients/ingredient.h \ diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e805751..78b64db 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1,4 +1,4 @@ -#include "userInterface/mainwindow.h" +#include "gui/mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 515fddb..0dd91b9 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -28,6 +28,7 @@ public: //Loads all data from a recipe into the GUI components. void loadFromRecipe(Recipe recipe); + private slots: void on_newButton_clicked(); diff --git a/gui/openrecipedialog.cpp b/gui/openrecipedialog.cpp index 67e3add..a910ad5 100644 --- a/gui/openrecipedialog.cpp +++ b/gui/openrecipedialog.cpp @@ -22,6 +22,11 @@ OpenRecipeDialog::~OpenRecipeDialog() void OpenRecipeDialog::populateRecipesTable(){ vector recipes = this->recipeDB->retrieveAllRecipes(); + printf("Found %d recipes:\n", recipes.size()); + for (Recipe r : recipes){ + r.print(); + printf("\n------------------\n"); + } this->recipeTableModel.setRecipes(recipes); - ui->recipeTableView->update(QModelIndex()); + ui->recipeTableView->show(); } diff --git a/main.cpp b/main.cpp index 4e49c1e..c786362 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ -#include "userInterface/mainwindow.h" +#include "gui/mainwindow.h" #include "gui/newrecipedialog.h" #include diff --git a/model/database/recipedatabase.cpp b/model/database/recipedatabase.cpp index d1a8de0..81dfb14 100644 --- a/model/database/recipedatabase.cpp +++ b/model/database/recipedatabase.cpp @@ -232,8 +232,8 @@ vector RecipeDatabase::retrieveAllTags(){ return tags; } -void RecipeDatabase::deleteTag(RecipeTag tag){ - ResultTable t = this->executeSQL("DELETE FROM recipeTag WHERE tagName="+surroundString(tag.getValue(), "'")); +bool RecipeDatabase::deleteRecipe(string name){ + } void RecipeDatabase::ensureTablesExist(){ diff --git a/model/database/recipedatabase.h b/model/database/recipedatabase.h index 60d382d..c36f061 100644 --- a/model/database/recipedatabase.h +++ b/model/database/recipedatabase.h @@ -40,6 +40,7 @@ class RecipeDatabase : public Database vector retrieveAllTags(); //Deletion. + bool deleteRecipe(string name); void deleteTag(RecipeTag tag); private: diff --git a/model/recipe/recipetablemodel.cpp b/model/recipe/recipetablemodel.cpp index db58738..1b00a55 100644 --- a/model/recipe/recipetablemodel.cpp +++ b/model/recipe/recipetablemodel.cpp @@ -45,6 +45,10 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation, return "Name"; case 1: return "Created On"; + case 2: + + default: + return QVariant(); } } else if (orientation == Qt::Vertical){ return QString::fromStdString(std::to_string(section)); @@ -53,6 +57,7 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation, } void RecipeTableModel::setRecipes(vector recipes){ + beginInsertRows({}, 0, recipes.size()-1); this->recipes = recipes; - emit dataChanged(createIndex(0, 0), createIndex(this->recipes.size()-1, 2)); + endInsertRows(); }