Able to display recipes in list in openRecipe dialog.

This commit is contained in:
Andrew Lalis 2018-03-29 09:58:25 +02:00
parent aab7a10553
commit fefa913e94
8 changed files with 18 additions and 7 deletions

View File

@ -38,7 +38,6 @@ SOURCES += model/recipe/instruction.cpp \
HEADERS += model/recipe/instruction.h \ HEADERS += model/recipe/instruction.h \
model/recipe/recipe.h \ model/recipe/recipe.h \
userInterface/mainwindow.h \
model/database/database.h \ model/database/database.h \
model/recipe/ingredients/unitofmeasure.h \ model/recipe/ingredients/unitofmeasure.h \
model/recipe/ingredients/ingredient.h \ model/recipe/ingredients/ingredient.h \

View File

@ -1,4 +1,4 @@
#include "userInterface/mainwindow.h" #include "gui/mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :

View File

@ -28,6 +28,7 @@ public:
//Loads all data from a recipe into the GUI components. //Loads all data from a recipe into the GUI components.
void loadFromRecipe(Recipe recipe); void loadFromRecipe(Recipe recipe);
private slots: private slots:
void on_newButton_clicked(); void on_newButton_clicked();

View File

@ -22,6 +22,11 @@ OpenRecipeDialog::~OpenRecipeDialog()
void OpenRecipeDialog::populateRecipesTable(){ void OpenRecipeDialog::populateRecipesTable(){
vector<Recipe> recipes = this->recipeDB->retrieveAllRecipes(); vector<Recipe> recipes = this->recipeDB->retrieveAllRecipes();
this->recipeTableModel.setRecipes(recipes); printf("Found %d recipes:\n", recipes.size());
ui->recipeTableView->update(QModelIndex()); for (Recipe r : recipes){
r.print();
printf("\n------------------\n");
}
this->recipeTableModel.setRecipes(recipes);
ui->recipeTableView->show();
} }

View File

@ -1,4 +1,4 @@
#include "userInterface/mainwindow.h" #include "gui/mainwindow.h"
#include "gui/newrecipedialog.h" #include "gui/newrecipedialog.h"
#include <QApplication> #include <QApplication>

View File

@ -232,8 +232,8 @@ vector<RecipeTag> RecipeDatabase::retrieveAllTags(){
return tags; return tags;
} }
void RecipeDatabase::deleteTag(RecipeTag tag){ bool RecipeDatabase::deleteRecipe(string name){
ResultTable t = this->executeSQL("DELETE FROM recipeTag WHERE tagName="+surroundString(tag.getValue(), "'"));
} }
void RecipeDatabase::ensureTablesExist(){ void RecipeDatabase::ensureTablesExist(){

View File

@ -40,6 +40,7 @@ class RecipeDatabase : public Database
vector<RecipeTag> retrieveAllTags(); vector<RecipeTag> retrieveAllTags();
//Deletion. //Deletion.
bool deleteRecipe(string name);
void deleteTag(RecipeTag tag); void deleteTag(RecipeTag tag);
private: private:

View File

@ -45,6 +45,10 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation,
return "Name"; return "Name";
case 1: case 1:
return "Created On"; return "Created On";
case 2:
default:
return QVariant();
} }
} else if (orientation == Qt::Vertical){ } else if (orientation == Qt::Vertical){
return QString::fromStdString(std::to_string(section)); return QString::fromStdString(std::to_string(section));
@ -53,6 +57,7 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation,
} }
void RecipeTableModel::setRecipes(vector<Recipe> recipes){ void RecipeTableModel::setRecipes(vector<Recipe> recipes){
beginInsertRows({}, 0, recipes.size()-1);
this->recipes = recipes; this->recipes = recipes;
emit dataChanged(createIndex(0, 0), createIndex(this->recipes.size()-1, 2)); endInsertRows();
} }