Added ability to edit recipe (WIP).
This commit is contained in:
		
							parent
							
								
									f13432a2fe
								
							
						
					
					
						commit
						6597efa646
					
				| 
						 | 
					@ -31,6 +31,7 @@ void MainWindow::loadFromRecipe(Recipe recipe){
 | 
				
			||||||
	setCookTime(recipe.getCookTime());
 | 
						setCookTime(recipe.getCookTime());
 | 
				
			||||||
	setServings(recipe.getServings());
 | 
						setServings(recipe.getServings());
 | 
				
			||||||
	setTags(recipe.getTags());
 | 
						setTags(recipe.getTags());
 | 
				
			||||||
 | 
						this->currentRecipe = recipe;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::setRecipeName(string name){
 | 
					void MainWindow::setRecipeName(string name){
 | 
				
			||||||
| 
						 | 
					@ -91,3 +92,17 @@ void MainWindow::on_openButton_clicked(){
 | 
				
			||||||
void MainWindow::on_exitButton_clicked(){
 | 
					void MainWindow::on_exitButton_clicked(){
 | 
				
			||||||
	this->close();
 | 
						this->close();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void MainWindow::on_editButton_clicked(){
 | 
				
			||||||
 | 
						NewRecipeDialog d(this->recipeDB, this->currentRecipe, 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. Make sure to give the recipe a name, instructions, and some ingredients!"));
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								this->loadFromRecipe(r);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,11 +36,14 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void on_exitButton_clicked();
 | 
						void on_exitButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void on_editButton_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
    Ui::MainWindow *ui;
 | 
					    Ui::MainWindow *ui;
 | 
				
			||||||
	RecipeDatabase *recipeDB;
 | 
						RecipeDatabase *recipeDB;
 | 
				
			||||||
	RecipeIngredientListModel ingredientModel;
 | 
						RecipeIngredientListModel ingredientModel;
 | 
				
			||||||
	TagListModel tagsListModel;
 | 
						TagListModel tagsListModel;
 | 
				
			||||||
 | 
						Recipe currentRecipe;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Hidden manipulation methods.
 | 
					    //Hidden manipulation methods.
 | 
				
			||||||
    void setRecipeName(string name);
 | 
					    void setRecipeName(string name);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,9 +180,9 @@ QPushButton#openButton:pressed{
 | 
				
			||||||
           </widget>
 | 
					           </widget>
 | 
				
			||||||
          </item>
 | 
					          </item>
 | 
				
			||||||
          <item alignment="Qt::AlignTop">
 | 
					          <item alignment="Qt::AlignTop">
 | 
				
			||||||
           <widget class="QPushButton" name="browseButton">
 | 
					           <widget class="QPushButton" name="editButton">
 | 
				
			||||||
            <property name="enabled">
 | 
					            <property name="enabled">
 | 
				
			||||||
             <bool>false</bool>
 | 
					             <bool>true</bool>
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <property name="minimumSize">
 | 
					            <property name="minimumSize">
 | 
				
			||||||
             <size>
 | 
					             <size>
 | 
				
			||||||
| 
						 | 
					@ -201,19 +201,19 @@ QPushButton#openButton:pressed{
 | 
				
			||||||
             <bool>false</bool>
 | 
					             <bool>false</bool>
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <property name="styleSheet">
 | 
					            <property name="styleSheet">
 | 
				
			||||||
             <string notr="true">QPushButton#browseButton {
 | 
					             <string notr="true">QPushButton#editButton {
 | 
				
			||||||
	background-color: rgb(215, 215, 255);
 | 
						background-color: rgb(215, 215, 255);
 | 
				
			||||||
	border: 0px;
 | 
						border: 0px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
QPushButton#browseButton:hover{
 | 
					QPushButton#editButton:hover{
 | 
				
			||||||
	background-color: rgb(225, 225, 255);
 | 
						background-color: rgb(225, 225, 255);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
QPushButton#browseButton:pressed{
 | 
					QPushButton#editButton:pressed{
 | 
				
			||||||
	background-color: rgb(255, 255, 255);
 | 
						background-color: rgb(255, 255, 255);
 | 
				
			||||||
}</string>
 | 
					}</string>
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <property name="text">
 | 
					            <property name="text">
 | 
				
			||||||
             <string>Browse</string>
 | 
					             <string>Edit</string>
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <property name="flat">
 | 
					            <property name="flat">
 | 
				
			||||||
             <bool>false</bool>
 | 
					             <bool>false</bool>
 | 
				
			||||||
| 
						 | 
					@ -363,6 +363,9 @@ font: "Noto Sans CJK KR";</string>
 | 
				
			||||||
          </item>
 | 
					          </item>
 | 
				
			||||||
          <item alignment="Qt::AlignLeft|Qt::AlignBottom">
 | 
					          <item alignment="Qt::AlignLeft|Qt::AlignBottom">
 | 
				
			||||||
           <widget class="QLabel" name="authorLabel">
 | 
					           <widget class="QLabel" name="authorLabel">
 | 
				
			||||||
 | 
					            <property name="enabled">
 | 
				
			||||||
 | 
					             <bool>false</bool>
 | 
				
			||||||
 | 
					            </property>
 | 
				
			||||||
            <property name="sizePolicy">
 | 
					            <property name="sizePolicy">
 | 
				
			||||||
             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
 | 
					             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
 | 
				
			||||||
              <horstretch>0</horstretch>
 | 
					              <horstretch>0</horstretch>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,17 @@ NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecip
 | 
				
			||||||
	this->populateTagsBox();
 | 
						this->populateTagsBox();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent) : NewRecipeDialog(db, parent){
 | 
				
			||||||
 | 
						ui->recipeNameEdit->setText(QString::fromStdString(recipe.getName()));
 | 
				
			||||||
 | 
						ui->prepTimeEdit->setTime(recipe.getPrepTime());
 | 
				
			||||||
 | 
						ui->cookTimeEdit->setTime(recipe.getCookTime());
 | 
				
			||||||
 | 
						ui->servingsSpinBox->setValue((double)recipe.getServings());
 | 
				
			||||||
 | 
						ui->instructionsTextEdit->setHtml(QString::fromStdString(recipe.getInstruction().getHTML()));
 | 
				
			||||||
 | 
						ui->imageDisplayLabel->setPixmap(QPixmap::fromImage(recipe.getImage()));
 | 
				
			||||||
 | 
						this->tagsListModel.setTags(recipe.getTags());
 | 
				
			||||||
 | 
						this->ingredientListModel.setIngredients(recipe.getIngredients());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
NewRecipeDialog::~NewRecipeDialog(){
 | 
					NewRecipeDialog::~NewRecipeDialog(){
 | 
				
			||||||
	delete ui;
 | 
						delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@ class NewRecipeDialog : public QDialog
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		explicit NewRecipeDialog(QWidget *parent = 0);
 | 
							explicit NewRecipeDialog(QWidget *parent = 0);
 | 
				
			||||||
		NewRecipeDialog(RecipeDatabase *db, QWidget *parent = 0);
 | 
							NewRecipeDialog(RecipeDatabase *db, QWidget *parent = 0);
 | 
				
			||||||
 | 
							NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent = 0);
 | 
				
			||||||
		~NewRecipeDialog();
 | 
							~NewRecipeDialog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Recipe getRecipe();
 | 
							Recipe getRecipe();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										22
									
								
								main.cpp
								
								
								
								
							| 
						 | 
					@ -48,18 +48,18 @@ void test(RecipeDatabase *recipeDB){
 | 
				
			||||||
	bool success = recipeDB->storeRecipe(rec);
 | 
						bool success = recipeDB->storeRecipe(rec);
 | 
				
			||||||
	printf("Storage successful: %d\n", success);
 | 
						printf("Storage successful: %d\n", success);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vector<string> foodGroups = recipeDB->retrieveAllFoodGroups();
 | 
					//	vector<string> foodGroups = recipeDB->retrieveAllFoodGroups();
 | 
				
			||||||
	printf("Food Groups:\n");
 | 
					//	printf("Food Groups:\n");
 | 
				
			||||||
	for (string s : foodGroups){
 | 
					//	for (string s : foodGroups){
 | 
				
			||||||
		printf("\t%s\n", s.c_str());
 | 
					//		printf("\t%s\n", s.c_str());
 | 
				
			||||||
	}
 | 
					//	}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Get food groups from recipe.
 | 
						//Get food groups from recipe.
 | 
				
			||||||
	Recipe r = recipeDB->retrieveRecipe("Pannenkoeken");
 | 
					//	Recipe r = recipeDB->retrieveRecipe("Pannenkoeken");
 | 
				
			||||||
	vector<string> foodGroupsR = r.getFoodGroups();
 | 
					//	vector<string> foodGroupsR = r.getFoodGroups();
 | 
				
			||||||
	printf("Pannenkoeken Food Groups:\n");
 | 
					//	printf("Pannenkoeken Food Groups:\n");
 | 
				
			||||||
	for (string s : foodGroupsR){
 | 
					//	for (string s : foodGroupsR){
 | 
				
			||||||
		printf("\t%s\n", s.c_str());
 | 
					//		printf("\t%s\n", s.c_str());
 | 
				
			||||||
	}
 | 
					//	}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -356,6 +356,10 @@ bool RecipeDatabase::deleteTag(RecipeTag tag){
 | 
				
			||||||
	return this->deleteFrom("recipeTag", "WHERE tagName='"+tag.getValue()+"'");
 | 
						return this->deleteFrom("recipeTag", "WHERE tagName='"+tag.getValue()+"'");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool RecipeDatabase::updateRecipe(Recipe recipe){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RecipeDatabase::ensureTablesExist(){
 | 
					void RecipeDatabase::ensureTablesExist(){
 | 
				
			||||||
	//Make sure that foreign keys are enabled.
 | 
						//Make sure that foreign keys are enabled.
 | 
				
			||||||
	this->executeSQL("PRAGMA foreign_keys = ON;");
 | 
						this->executeSQL("PRAGMA foreign_keys = ON;");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,9 @@ class RecipeDatabase : public Database
 | 
				
			||||||
		bool deleteIngredient(string name);
 | 
							bool deleteIngredient(string name);
 | 
				
			||||||
		bool deleteUnitOfMeasure(string name);
 | 
							bool deleteUnitOfMeasure(string name);
 | 
				
			||||||
		bool deleteTag(RecipeTag tag);
 | 
							bool deleteTag(RecipeTag tag);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Updating.
 | 
				
			||||||
 | 
							bool updateRecipe(Recipe recipe);
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Utility methods.
 | 
							//Utility methods.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue