Fixed compilation bugs. Program runs.

This commit is contained in:
Andrew Lalis 2018-05-22 23:21:15 +02:00
parent b3393266d3
commit 4554fdcd1e
6 changed files with 7 additions and 30 deletions

View File

@ -15,8 +15,6 @@ NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){ NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
this->recipeDB = db; this->recipeDB = db;
this->populateIngredientsBox();
this->populateUnitsBox();
this->populateTagsBox(); this->populateTagsBox();
} }

View File

@ -11,9 +11,7 @@
#include "model/recipe/ingredients/ingredientlistmodel.h" #include "model/recipe/ingredients/ingredientlistmodel.h"
#include "model/recipe/tags/taglistmodel.h" #include "model/recipe/tags/taglistmodel.h"
#include "gui/newDialogs/newingredientdialog.h"
#include "gui/newDialogs/newtagdialog.h" #include "gui/newDialogs/newtagdialog.h"
#include "gui/newDialogs/newunitdialog.h"
namespace Ui { namespace Ui {
class NewRecipeDialog; class NewRecipeDialog;

View File

@ -74,17 +74,6 @@ void OpenRecipeDialog::on_recipeTableView_doubleClicked(const QModelIndex &index
this->close(); this->close();
} }
void OpenRecipeDialog::onIngredientsListViewSelectionChanged(const QItemSelection &selection){
Q_UNUSED(selection);
vector<Ingredient> 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){ void OpenRecipeDialog::onTagsListViewSelectionChanged(const QItemSelection &selection){
Q_UNUSED(selection); Q_UNUSED(selection);
vector<RecipeTag> tags; vector<RecipeTag> tags;
@ -101,20 +90,9 @@ void OpenRecipeDialog::on_nameEdit_textChanged(const QString &arg1){
this->populateRecipesTable(this->recipeDB->retrieveRecipesWithSubstring(ui->nameEdit->text().toStdString())); 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));
}
void OpenRecipeDialog::on_clearSearchButton_clicked(){ void OpenRecipeDialog::on_clearSearchButton_clicked(){
ui->nameEdit->clear(); ui->nameEdit->clear();
ui->foodGroupsListWidget->selectionModel()->clearSelection();
ui->tagsListView->selectionModel()->clearSelection(); ui->tagsListView->selectionModel()->clearSelection();
ui->ingredientsListView->selectionModel()->clearSelection();
this->populateRecipesTable(this->recipeDB->retrieveAllRecipes()); this->populateRecipesTable(this->recipeDB->retrieveAllRecipes());
} }

View File

@ -15,7 +15,10 @@ ResultTable Database::executeSQL(string statement){
this->sql = statement; this->sql = statement;
this->returnCode = sqlite3_prepare_v2(this->db, statement.c_str(), -1, &stmt, NULL); this->returnCode = sqlite3_prepare_v2(this->db, statement.c_str(), -1, &stmt, NULL);
if (this->returnCode != SQLITE_OK){ 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); return ResultTable(this->returnCode);
} }
ResultTable t(statement); ResultTable t(statement);

View File

@ -323,7 +323,7 @@ void RecipeDatabase::ensureTablesExist(){
this->executeSQL("CREATE TABLE IF NOT EXISTS recipeIngredient(" this->executeSQL("CREATE TABLE IF NOT EXISTS recipeIngredient("
"recipeId int," "recipeId int,"
"content," "content,"
"FOREIGN KEY (recipeId) REFERENCES recipe(recipeId);"); "FOREIGN KEY (recipeId) REFERENCES recipe(recipeId));");
this->commitTransaction(); this->commitTransaction();
} }

View File

@ -13,7 +13,7 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
int row = index.row(); int row = index.row();
Ingredient i = this->ingredients[row]; Ingredient i = this->ingredients[row];
string displayStr = i.toString(); string displayStr = i.getContent();
switch(role){ switch(role){
case Qt::DisplayRole: case Qt::DisplayRole:
@ -38,7 +38,7 @@ bool IngredientListModel::addIngredient(Ingredient i){
} }
} }
//The ingredient doesn't exist already, so we'll add it. //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 index = createIndex(this->ingredients.size()-1, 0);
QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0); QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
emit dataChanged(index, bottomIndex); emit dataChanged(index, bottomIndex);