Actually Usable Version #7
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -38,7 +38,6 @@ SOURCES += model/recipe/instruction.cpp \
 | 
			
		|||
 | 
			
		||||
HEADERS  += model/recipe/instruction.h \
 | 
			
		||||
    model/recipe/recipe.h \
 | 
			
		||||
    userInterface/mainwindow.h \
 | 
			
		||||
    model/database/database.h \
 | 
			
		||||
    model/recipe/ingredients/unitofmeasure.h \
 | 
			
		||||
    model/recipe/ingredients/ingredient.h \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
#include "userInterface/mainwindow.h"
 | 
			
		||||
#include "gui/mainwindow.h"
 | 
			
		||||
#include "ui_mainwindow.h"
 | 
			
		||||
 | 
			
		||||
MainWindow::MainWindow(QWidget *parent) :
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ public:
 | 
			
		|||
 | 
			
		||||
    //Loads all data from a recipe into the GUI components.
 | 
			
		||||
    void loadFromRecipe(Recipe recipe);
 | 
			
		||||
 | 
			
		||||
	private slots:
 | 
			
		||||
	void on_newButton_clicked();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,11 @@ OpenRecipeDialog::~OpenRecipeDialog()
 | 
			
		|||
 | 
			
		||||
void OpenRecipeDialog::populateRecipesTable(){
 | 
			
		||||
	vector<Recipe> recipes = this->recipeDB->retrieveAllRecipes();
 | 
			
		||||
	printf("Found %d recipes:\n", recipes.size());
 | 
			
		||||
	for (Recipe r : recipes){
 | 
			
		||||
		r.print();
 | 
			
		||||
		printf("\n------------------\n");
 | 
			
		||||
	}
 | 
			
		||||
	this->recipeTableModel.setRecipes(recipes);
 | 
			
		||||
	ui->recipeTableView->update(QModelIndex());
 | 
			
		||||
	ui->recipeTableView->show();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								main.cpp
								
								
								
								
							
							
						
						
									
										2
									
								
								main.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
#include "userInterface/mainwindow.h"
 | 
			
		||||
#include "gui/mainwindow.h"
 | 
			
		||||
#include "gui/newrecipedialog.h"
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -232,8 +232,8 @@ vector<RecipeTag> RecipeDatabase::retrieveAllTags(){
 | 
			
		|||
	return tags;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RecipeDatabase::deleteTag(RecipeTag tag){
 | 
			
		||||
	ResultTable t = this->executeSQL("DELETE FROM recipeTag WHERE tagName="+surroundString(tag.getValue(), "'"));
 | 
			
		||||
bool RecipeDatabase::deleteRecipe(string name){
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RecipeDatabase::ensureTablesExist(){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,6 +40,7 @@ class RecipeDatabase : public Database
 | 
			
		|||
		vector<RecipeTag> retrieveAllTags();
 | 
			
		||||
 | 
			
		||||
		//Deletion.
 | 
			
		||||
		bool deleteRecipe(string name);
 | 
			
		||||
		void deleteTag(RecipeTag tag);
 | 
			
		||||
	private:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,10 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation,
 | 
			
		|||
				return "Name";
 | 
			
		||||
			case 1:
 | 
			
		||||
				return "Created On";
 | 
			
		||||
			case 2:
 | 
			
		||||
 | 
			
		||||
			default:
 | 
			
		||||
				return QVariant();
 | 
			
		||||
		}
 | 
			
		||||
	} else if (orientation == Qt::Vertical){
 | 
			
		||||
		return QString::fromStdString(std::to_string(section));
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +57,7 @@ QVariant RecipeTableModel::headerData(int section, Qt::Orientation orientation,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void RecipeTableModel::setRecipes(vector<Recipe> recipes){
 | 
			
		||||
	beginInsertRows({}, 0, recipes.size()-1);
 | 
			
		||||
	this->recipes = recipes;
 | 
			
		||||
	emit dataChanged(createIndex(0, 0), createIndex(this->recipes.size()-1, 2));
 | 
			
		||||
	endInsertRows();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue