Able to display recipes in list in openRecipe dialog.
This commit is contained in:
parent
aab7a10553
commit
fefa913e94
|
@ -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 \
|
||||||
|
|
|
@ -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) :
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,11 @@ OpenRecipeDialog::~OpenRecipeDialog()
|
||||||
|
|
||||||
void OpenRecipeDialog::populateRecipesTable(){
|
void OpenRecipeDialog::populateRecipesTable(){
|
||||||
vector<Recipe> recipes = this->recipeDB->retrieveAllRecipes();
|
vector<Recipe> recipes = this->recipeDB->retrieveAllRecipes();
|
||||||
|
printf("Found %d recipes:\n", recipes.size());
|
||||||
|
for (Recipe r : recipes){
|
||||||
|
r.print();
|
||||||
|
printf("\n------------------\n");
|
||||||
|
}
|
||||||
this->recipeTableModel.setRecipes(recipes);
|
this->recipeTableModel.setRecipes(recipes);
|
||||||
ui->recipeTableView->update(QModelIndex());
|
ui->recipeTableView->show();
|
||||||
}
|
}
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -1,4 +1,4 @@
|
||||||
#include "userInterface/mainwindow.h"
|
#include "gui/mainwindow.h"
|
||||||
#include "gui/newrecipedialog.h"
|
#include "gui/newrecipedialog.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
|
|
@ -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(){
|
||||||
|
|
|
@ -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:
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue