First ability to create recipe in gui #5
|
@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; }
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item alignment="Qt::AlignRight">
|
<item>
|
||||||
<widget class="QWidget" name="imagePanelWidget" native="true">
|
<widget class="QWidget" name="imagePanelWidget" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
@ -547,6 +547,19 @@ p, li { white-space: pre-wrap; }
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="imageLabel">
|
||||||
|
<property name="pixmap">
|
||||||
|
<pixmap resource="../images.qrc">:/images/images/no_image.png</pixmap>
|
||||||
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
61
main.cpp
61
main.cpp
|
@ -7,49 +7,46 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
RecipeDatabase recipeDB("recipes");
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w(&recipeDB);
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
//TESTING CODE
|
//TESTING CODE
|
||||||
|
// vector<RecipeIngredient> 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("<b>BOLD</b><i>iTaLiCs</i>"),
|
||||||
|
// QImage(),
|
||||||
|
// vector<RecipeTag>({RecipeTag("testing"),
|
||||||
|
// RecipeTag("fake")}),
|
||||||
|
// QDate::currentDate(),
|
||||||
|
// QTime(0, 30),
|
||||||
|
// QTime(0, 25),
|
||||||
|
// 10.0f);
|
||||||
|
|
||||||
//TESTING CODE
|
// bool success = recipeDB.storeRecipe(rec);
|
||||||
vector<RecipeIngredient> ri;
|
// printf("Storage successful: %d\n", success);
|
||||||
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), ""));
|
|
||||||
|
|
||||||
Recipe rec("Example",
|
// recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0));
|
||||||
ri,
|
// recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0));
|
||||||
Instruction("<b>BOLD</b><i>iTaLiCs</i>"),
|
// recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0));
|
||||||
QImage(),
|
|
||||||
vector<RecipeTag>({RecipeTag("testing"),
|
|
||||||
RecipeTag("fake")}),
|
|
||||||
QDate::currentDate(),
|
|
||||||
QTime(0, 30),
|
|
||||||
QTime(0, 25),
|
|
||||||
10.0f);
|
|
||||||
|
|
||||||
bool success = recipeDB.storeRecipe(rec);
|
// Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
||||||
printf("Storage successful: %d\n", success);
|
// reloadRec.print();
|
||||||
|
|
||||||
recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0));
|
// w.loadFromRecipe(reloadRec);
|
||||||
recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0));
|
|
||||||
recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0));
|
|
||||||
|
|
||||||
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
// NewRecipeDialog d(&recipeDB);
|
||||||
reloadRec.print();
|
// d.show();
|
||||||
|
// d.exec();
|
||||||
|
|
||||||
w.loadFromRecipe(reloadRec);
|
// if (d.isAccepted()){
|
||||||
|
// printf("Accepted the dialog.\n");
|
||||||
NewRecipeDialog d(&recipeDB);
|
// }
|
||||||
d.show();
|
|
||||||
d.exec();
|
|
||||||
|
|
||||||
if (d.isAccepted()){
|
|
||||||
printf("Accepted the dialog.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
ui->ingredientsListView->setModel(&this->ingredientModel);
|
ui->ingredientsListView->setModel(&this->ingredientModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainWindow::MainWindow(RecipeDatabase *db, QWidget *parent) : MainWindow(parent){
|
||||||
|
this->recipeDB = db;
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow(){
|
MainWindow::~MainWindow(){
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +21,7 @@ void MainWindow::loadFromRecipe(Recipe recipe){
|
||||||
setRecipeName(recipe.getName());
|
setRecipeName(recipe.getName());
|
||||||
setInstruction(recipe.getInstruction());
|
setInstruction(recipe.getInstruction());
|
||||||
setIngredients(recipe.getIngredients());
|
setIngredients(recipe.getIngredients());
|
||||||
|
setImage(recipe.getImage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setRecipeName(string name){
|
void MainWindow::setRecipeName(string name){
|
||||||
|
@ -28,5 +33,22 @@ void MainWindow::setInstruction(Instruction instruction){
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setIngredients(vector<RecipeIngredient> ingredients){
|
void MainWindow::setIngredients(vector<RecipeIngredient> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "model/recipe/recipe.h"
|
#include "model/recipe/recipe.h"
|
||||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||||
|
#include "gui/newrecipedialog.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -20,18 +21,24 @@ class MainWindow : public QMainWindow
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
|
MainWindow(RecipeDatabase *db, QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
//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:
|
private slots:
|
||||||
|
void on_newButton_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
RecipeDatabase *recipeDB;
|
||||||
IngredientListModel ingredientModel;
|
IngredientListModel ingredientModel;
|
||||||
|
|
||||||
//Hidden manipulation methods.
|
//Hidden manipulation methods.
|
||||||
void setRecipeName(string name);
|
void setRecipeName(string name);
|
||||||
void setInstruction(Instruction instruction);
|
void setInstruction(Instruction instruction);
|
||||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
void setIngredients(vector<RecipeIngredient> ingredients);
|
||||||
|
void setImage(QImage img);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue