First ability to create recipe in gui #5
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; }
 | 
			
		|||
            </layout>
 | 
			
		||||
           </widget>
 | 
			
		||||
          </item>
 | 
			
		||||
          <item alignment="Qt::AlignRight">
 | 
			
		||||
          <item>
 | 
			
		||||
           <widget class="QWidget" name="imagePanelWidget" native="true">
 | 
			
		||||
            <property name="sizePolicy">
 | 
			
		||||
             <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
 | 
			
		||||
| 
						 | 
				
			
			@ -547,6 +547,19 @@ p, li { white-space: pre-wrap; }
 | 
			
		|||
             <property name="bottomMargin">
 | 
			
		||||
              <number>0</number>
 | 
			
		||||
             </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>
 | 
			
		||||
           </widget>
 | 
			
		||||
          </item>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										61
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										61
									
								
								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<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
 | 
			
		||||
	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), ""));
 | 
			
		||||
//	bool success = recipeDB.storeRecipe(rec);
 | 
			
		||||
//	printf("Storage successful: %d\n", success);
 | 
			
		||||
 | 
			
		||||
	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);
 | 
			
		||||
//	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();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<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/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<RecipeIngredient> ingredients);
 | 
			
		||||
	void setImage(QImage img);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MAINWINDOW_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue