Improve/redesign ingredients #13
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -74,17 +74,6 @@ void OpenRecipeDialog::on_recipeTableView_doubleClicked(const QModelIndex &index
|
|||
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){
|
||||
Q_UNUSED(selection);
|
||||
vector<RecipeTag> 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<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(){
|
||||
ui->nameEdit->clear();
|
||||
ui->foodGroupsListWidget->selectionModel()->clearSelection();
|
||||
ui->tagsListView->selectionModel()->clearSelection();
|
||||
ui->ingredientsListView->selectionModel()->clearSelection();
|
||||
this->populateRecipesTable(this->recipeDB->retrieveAllRecipes());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue