diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 252d695..a527789 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; } - + @@ -547,6 +547,19 @@ p, li { white-space: pre-wrap; } 0 + + + + :/images/images/no_image.png + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + diff --git a/main.cpp b/main.cpp index 23f8db2..ab7a5f2 100644 --- a/main.cpp +++ b/main.cpp @@ -7,49 +7,46 @@ int main(int argc, char *argv[]) { + RecipeDatabase recipeDB("recipes"); QApplication a(argc, argv); - MainWindow w; + MainWindow w(&recipeDB); w.show(); //TESTING CODE +// vector ri; +// ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), "")); +// ri.push_back(RecipeIngredient("baking powder", "additives", 1.0f, UnitOfMeasure("teaspoon", "teaspoons", "tsp", UnitOfMeasure::VOLUME, 1.0), "")); - RecipeDatabase recipeDB("recipes"); +// Recipe rec("Example", +// ri, +// Instruction("BOLDiTaLiCs"), +// QImage(), +// vector({RecipeTag("testing"), +// RecipeTag("fake")}), +// QDate::currentDate(), +// QTime(0, 30), +// QTime(0, 25), +// 10.0f); - //TESTING CODE - vector ri; - ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), "")); - ri.push_back(RecipeIngredient("baking powder", "additives", 1.0f, UnitOfMeasure("teaspoon", "teaspoons", "tsp", UnitOfMeasure::VOLUME, 1.0), "")); +// bool success = recipeDB.storeRecipe(rec); +// printf("Storage successful: %d\n", success); - Recipe rec("Example", - ri, - Instruction("BOLDiTaLiCs"), - QImage(), - vector({RecipeTag("testing"), - RecipeTag("fake")}), - QDate::currentDate(), - QTime(0, 30), - QTime(0, 25), - 10.0f); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0)); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0)); +// recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0)); - bool success = recipeDB.storeRecipe(rec); - printf("Storage successful: %d\n", success); +// Recipe reloadRec = recipeDB.retrieveRecipe("Example"); +// reloadRec.print(); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0)); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0)); - recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0)); +// w.loadFromRecipe(reloadRec); - Recipe reloadRec = recipeDB.retrieveRecipe("Example"); - reloadRec.print(); +// NewRecipeDialog d(&recipeDB); +// d.show(); +// d.exec(); - w.loadFromRecipe(reloadRec); - - NewRecipeDialog d(&recipeDB); - d.show(); - d.exec(); - - if (d.isAccepted()){ - printf("Accepted the dialog.\n"); - } +// if (d.isAccepted()){ +// printf("Accepted the dialog.\n"); +// } return a.exec(); } diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp index 69a6189..8d92a70 100644 --- a/userInterface/mainwindow.cpp +++ b/userInterface/mainwindow.cpp @@ -9,6 +9,10 @@ MainWindow::MainWindow(QWidget *parent) : ui->ingredientsListView->setModel(&this->ingredientModel); } +MainWindow::MainWindow(RecipeDatabase *db, QWidget *parent) : MainWindow(parent){ + this->recipeDB = db; +} + MainWindow::~MainWindow(){ delete ui; } @@ -17,6 +21,7 @@ void MainWindow::loadFromRecipe(Recipe recipe){ setRecipeName(recipe.getName()); setInstruction(recipe.getInstruction()); setIngredients(recipe.getIngredients()); + setImage(recipe.getImage()); } void MainWindow::setRecipeName(string name){ @@ -28,5 +33,22 @@ void MainWindow::setInstruction(Instruction instruction){ } void MainWindow::setIngredients(vector ingredients){ - this->ingredientModel.setIngredients(ingredients); + this->ingredientModel.setIngredients(ingredients); +} + +void MainWindow::setImage(QImage img){ + ui->imageLabel->setPixmap(QPixmap::fromImage(img)); +} + +void MainWindow::on_newButton_clicked(){ + NewRecipeDialog d(this->recipeDB, this); + d.show(); + d.exec(); + if (d.isAccepted()){ + Recipe r = d.getRecipe(); + if (!this->recipeDB->storeRecipe(r)){ + QMessageBox::critical(this, QString("Unable to Save Recipe"), QString("The program was not able to successfully save the recipe.")); + } + this->loadFromRecipe(r); + } } diff --git a/userInterface/mainwindow.h b/userInterface/mainwindow.h index b1b50be..2f2591b 100644 --- a/userInterface/mainwindow.h +++ b/userInterface/mainwindow.h @@ -7,6 +7,7 @@ #include "model/recipe/recipe.h" #include "model/recipe/ingredients/ingredientlistmodel.h" +#include "gui/newrecipedialog.h" using namespace std; @@ -20,18 +21,24 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); + MainWindow(RecipeDatabase *db, QWidget *parent = 0); ~MainWindow(); //Loads all data from a recipe into the GUI components. void loadFromRecipe(Recipe recipe); -private: + private slots: + void on_newButton_clicked(); + + private: Ui::MainWindow *ui; + RecipeDatabase *recipeDB; IngredientListModel ingredientModel; //Hidden manipulation methods. void setRecipeName(string name); void setInstruction(Instruction instruction); void setIngredients(vector ingredients); + void setImage(QImage img); }; #endif // MAINWINDOW_H