Updates saving and deleting instructions and images.
This commit is contained in:
		
							parent
							
								
									076212e392
								
							
						
					
					
						commit
						8fee8c0cdb
					
				| 
						 | 
				
			
			@ -38,7 +38,7 @@ void OpenRecipeDialog::on_deleteRecipeButton_clicked(){
 | 
			
		|||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	vector<int> rows;
 | 
			
		||||
	QModelIndexList indexes = selectModel->selectedIndexes();
 | 
			
		||||
	QModelIndexList indexes = selectModel->selectedRows();
 | 
			
		||||
	for (int i = 0; i < indexes.count(); i++){
 | 
			
		||||
		rows.push_back(indexes.at(i).row());
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										3
									
								
								main.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -4,10 +4,11 @@
 | 
			
		|||
 | 
			
		||||
#include "model/database/database.h"
 | 
			
		||||
#include "model/database/recipedatabase.h"
 | 
			
		||||
#include "utils/fileutils.h"
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
	RecipeDatabase recipeDB("recipes");
 | 
			
		||||
	RecipeDatabase recipeDB(QString(FileUtils::appDataPath+"recipes.db").toStdString());
 | 
			
		||||
    QApplication a(argc, argv);
 | 
			
		||||
	MainWindow w(&recipeDB);
 | 
			
		||||
    w.show();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -255,6 +255,8 @@ bool RecipeDatabase::deleteRecipe(int recipeId){
 | 
			
		|||
	bool tagsDeleted = this->deleteFrom("recipeTag", "WHERE recipeId="+idString);
 | 
			
		||||
	bool recipeIngredientDeleted = this->deleteFrom("recipeIngredient", "WHERE recipeId="+idString);
 | 
			
		||||
	bool recipeDeleted = this->deleteFrom("recipe", "WHERE recipeId="+idString);
 | 
			
		||||
	bool instructionDeleted = FileUtils::deleteInstruction(recipeId);
 | 
			
		||||
	bool imageDeleted = FileUtils::deleteImage(recipeId);
 | 
			
		||||
	if (tagsDeleted && recipeIngredientDeleted && recipeDeleted){
 | 
			
		||||
		this->executeSQL("COMMIT;");
 | 
			
		||||
		return true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,4 +61,18 @@ QImage loadImage(int nr){
 | 
			
		|||
	return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool deleteInstruction(int nr){
 | 
			
		||||
	ensureAppDataFolderExists();
 | 
			
		||||
	QString filename = appDataPath + QString::fromStdString(std::to_string(nr)) +".html";
 | 
			
		||||
	QFile file(filename);
 | 
			
		||||
	return file.remove();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool deleteImage(int nr){
 | 
			
		||||
	ensureAppDataFolderExists();
 | 
			
		||||
	QString filename = appDataPath + QString::fromStdString(std::to_string(nr)) +".png";
 | 
			
		||||
	QFile file(filename);
 | 
			
		||||
	return file.remove();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
#include <QDir>
 | 
			
		||||
#include <QTextStream>
 | 
			
		||||
#include <QImage>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include "model/recipe/instruction.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -19,9 +20,13 @@ namespace FileUtils{
 | 
			
		|||
 | 
			
		||||
	Instruction loadInstruction(int nr);
 | 
			
		||||
 | 
			
		||||
	bool deleteInstruction(int nr);
 | 
			
		||||
 | 
			
		||||
	bool saveImage(int nr, QImage image);
 | 
			
		||||
 | 
			
		||||
	QImage loadImage(int nr);
 | 
			
		||||
 | 
			
		||||
	bool deleteImage(int nr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // FILEUTILS_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue