Improvements made to recipe objects.

This commit is contained in:
Andrew Lalis 2018-02-12 14:24:11 +01:00
parent db91d81ec3
commit 3b42d1f418
11 changed files with 621 additions and 254 deletions

View File

@ -19,7 +19,8 @@ SOURCES += SQLite/sqlite3.c \
model/recipe/recipeingredient.cpp \ model/recipe/recipeingredient.cpp \
userInterface/mainwindow.cpp \ userInterface/mainwindow.cpp \
main.cpp \ main.cpp \
model/database/database.cpp model/database/database.cpp \
model/recipe/ingredientlistmodel.cpp
HEADERS += SQLite/sqlite3.h \ HEADERS += SQLite/sqlite3.h \
SQLite/sqlite3ext.h \ SQLite/sqlite3ext.h \
@ -28,12 +29,12 @@ HEADERS += SQLite/sqlite3.h \
model/recipe/recipe.h \ model/recipe/recipe.h \
model/recipe/recipeingredient.h \ model/recipe/recipeingredient.h \
userInterface/mainwindow.h \ userInterface/mainwindow.h \
model/database/database.h model/database/database.h \
model/recipe/ingredientlistmodel.h
FORMS += gui/mainwindow.ui FORMS += gui/mainwindow.ui
DISTFILES += \ DISTFILES += \
.gitignore .gitignore
RESOURCES += \ RESOURCES +=
gui/menubuttonstylesheet.qrc

View File

@ -2,6 +2,9 @@
<ui version="4.0"> <ui version="4.0">
<class>MainWindow</class> <class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow"> <widget class="QMainWindow" name="MainWindow">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -11,7 +14,7 @@
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -26,133 +29,139 @@
<double>1.000000000000000</double> <double>1.000000000000000</double>
</property> </property>
<widget class="QWidget" name="mainWidget"> <widget class="QWidget" name="mainWidget">
<widget class="QWidget" name="menuBarWidget" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<height>500</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 104)</string>
</property>
<widget class="QLabel" name="title">
<property name="geometry">
<rect>
<x>0</x>
<y>-1</y>
<width>151</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>24</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Recipe DB</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>0</x>
<y>53</y>
<width>151</width>
<height>451</height>
</rect>
</property>
<layout class="QVBoxLayout" name="menuButtonLayout">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>0</number>
</property> </property>
<property name="sizeConstraint"> <property name="leftMargin">
<enum>QLayout::SetDefaultConstraint</enum> <number>0</number>
</property> </property>
<item> <property name="topMargin">
<widget class="QPushButton" name="newRecipeButton"> <number>0</number>
<property name="font"> </property>
<font> <property name="rightMargin">
<family>Source Sans Pro Light</family> <number>0</number>
<pointsize>16</pointsize> </property>
</font> <property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="QWidget" name="menuPanelWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property> </property>
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255); <string notr="true">background-color: rgb(210, 222, 255);</string>
color: rgb(0, 0, 104);</string> </property>
<layout class="QVBoxLayout" name="menuPanel">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QWidget" name="menuPanelButtons" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="newButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>80</height>
</size>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>20</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(83, 75, 255);</string>
</property> </property>
<property name="text"> <property name="text">
<string>New</string> <string>New</string>
</property> </property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat"> <property name="flat">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignTop">
<widget class="QPushButton" name="openRecipeButton"> <widget class="QPushButton" name="openButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>80</height>
</size>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Source Sans Pro Light</family> <family>Source Sans Pro Light</family>
<pointsize>16</pointsize> <pointsize>20</pointsize>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255); <string notr="true">background-color: rgb(112, 105, 255);</string>
color: rgb(0, 0, 104);</string>
</property> </property>
<property name="text"> <property name="text">
<string>Open</string> <string>Open</string>
</property> </property>
<property name="flat">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item alignment="Qt::AlignTop">
<widget class="QPushButton" name="browseButton"> <widget class="QPushButton" name="browseButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>80</height>
</size>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Source Sans Pro Light</family> <family>Source Sans Pro Light</family>
<pointsize>16</pointsize> <pointsize>20</pointsize>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255); <string notr="true">background-color: rgb(137, 131, 255);</string>
color: rgb(0, 0, 104);</string>
</property> </property>
<property name="text"> <property name="text">
<string>Browse</string> <string>Browse</string>
@ -161,18 +170,169 @@ color: rgb(0, 0, 104);</string>
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget> </widget>
<widget class="QScrollArea" name="scrollArea"> </item>
<property name="geometry"> <item>
<rect> <widget class="QWidget" name="displayPanelWidget" native="true">
<x>149</x> <property name="sizePolicy">
<y>-1</y> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<width>861</width> <horstretch>0</horstretch>
<height>511</height> <verstretch>0</verstretch>
</rect> </sizepolicy>
</property>
<layout class="QVBoxLayout" name="displayPanel">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="recipeNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>80</height>
</size>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>24</pointsize>
</font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: qlineargradient(spread:pad, x1:0, y1:0.466, x2:1, y2:0.534, stop:0 rgba(0, 55, 104, 255), stop:1 rgba(0, 0, 0, 255));</string> <string notr="true">background-color: rgb(219, 216, 216);</string>
</property>
<property name="text">
<string>Recipe Name</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="displayPanelContent" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="QWidget" name="ingredientsPanel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="ingredientsLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>18</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(194, 196, 233);</string>
</property>
<property name="text">
<string>Ingredients</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="listView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(232, 232, 232);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
@ -180,23 +340,162 @@ color: rgb(0, 0, 104);</string>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="verticalScrollBarPolicy"> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>
<property name="widgetResizable"> <property name="isWrapping" stdset="0">
<bool>false</bool> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="scrollAreaWidgetContents"> <property name="layoutMode">
<property name="geometry"> <enum>QListView::SinglePass</enum>
<rect> </property>
<x>0</x> <property name="wordWrap">
<y>0</y> <bool>true</bool>
<width>859</width>
<height>509</height>
</rect>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget> </widget>
</item>
<item>
<widget class="QWidget" name="instructionsPanel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="instructionsLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>18</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(218, 219, 234);</string>
</property>
<property name="text">
<string>Instructions</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="instructionsTextEdit">
<property name="styleSheet">
<string notr="true">background-color: rgb(244, 244, 244);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::WidgetWidth</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; color:#00ff40;&quot;&gt;This is some &lt;/span&gt;&lt;span style=&quot; font-size:16pt; color:#a33c3e;&quot;&gt;colored text and &lt;/span&gt;&lt;a href=&quot;https://www.google.com&quot;&gt;&lt;span style=&quot; font-size:8pt; text-decoration: underline; color:#0000ff;&quot;&gt;link&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QWidget" name="imagePanelWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<layout class="QVBoxLayout" name="imagePanel">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>

View File

@ -1,17 +1,7 @@
#include "userInterface/mainwindow.h" #include "userInterface/mainwindow.h"
#include <QApplication> #include <QApplication>
#include <iostream>
#include "SQLite/sqlite3.h"
static int callback(void* data, int rows, char** argv, char** azColName){ #include "model/database/database.h"
int i;
fprintf(stderr, "%s: ", (const char*)data);
for(i=0; i<rows; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -19,64 +9,7 @@ int main(int argc, char *argv[])
MainWindow w; MainWindow w;
w.show(); w.show();
sqlite3* db; //Database object. Database db("test.db");
char* zErrMsg = 0; //Error message object.
int rc; //Return code from sqlite3 calls.
char* sql; //SQL text code is stored here.
const char* data = "Callback function called";
rc = sqlite3_open("test.db", &db);
if (rc){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(0);
} else {
fprintf(stdout, "Opened database successfully\n");
}
//Create sample SQL statement.
sql = "DROP TABLE ingredients;"
"CREATE TABLE ingredients(" \
"id int PRIMARY KEY NOT NULL," \
"name varchar NOT NULL," \
"foodGroup varchar NOT NULL);";
//Execute statement.
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if (rc != SQLITE_OK){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
} else {
fprintf(stdout, "Table created successfully.\n");
}
//Create some fake data.
sql = "INSERT INTO ingredients (id, name, foodGroup) VALUES (1, 'flour', 'grains');" \
"INSERT INTO ingredients (id, name, foodGroup) VALUES (2, 'pasta', 'grains');";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if (rc != SQLITE_OK){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
} else {
fprintf(stdout, "Records created successfully.\n");
}
//Select data.
sql = "SELECT * FROM ingredients;";
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
if (rc != SQLITE_OK){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
} else {
fprintf(stdout, "Select done successfully.\n");
}
sqlite3_close(db);
return a.exec(); return a.exec();
} }

View File

@ -1,13 +1,46 @@
#include "model/database/database.h" #include "model/database/database.h"
Database::Database(){ Database::Database(string filename){
this->filename = filename;
openConnection();
if (tableExists("ingredients")){
printf("Ingredients table already exists.\n");
} else {
printf("Couldn't find the ingredients table.\n");
}
}
Database::~Database(){
closeConnection();
} }
void Database::openConnection(){ void Database::openConnection(){
this->returnCode = sqlite3_open(this->filename.c_str(), &this->db); this->returnCode = sqlite3_open(this->filename.c_str(), &this->db);
if (this->returnCode){ if (this->returnCode || this->db == NULL){
this->dbIsOpen = false;
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else {
this->dbIsOpen = true;
} }
} }
void Database::closeConnection(){
this->returnCode = sqlite3_close(this->db);
this->dbIsOpen = false;
}
bool Database::tableExists(string tableName){
if (this->dbIsOpen){
this->sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='"+tableName+"';";
const char* str = this->sql.c_str();
this->returnCode = sqlite3_exec(this->db, str, NULL, 0, &this->errorMsg);
if (this->returnCode == SQLITE_ERROR){
fprintf(stderr, "Unable to select name from master table list: %s\n", this->errorMsg);
return false;
} else {
return true;
}
}
return false;
}

View File

@ -13,17 +13,26 @@ class Database
{ {
public: public:
Database(string filename); Database(string filename);
~Database();
void insertIngredient(Ingredient); void insertIngredient(Ingredient);
vector<Ingredient> getIngredients();
private: private:
//SQL Instance variables.
string filename; string filename;
sqlite3* db; sqlite3* db;
bool dbIsOpen;
int returnCode; int returnCode;
string sql; string sql;
char* errorMsg; char* errorMsg;
void openConnection(); void openConnection();
void closeConnection();
//Guarantees that all tables from the schema exist.
void ensureTablesExist();
//Utility methods.
bool tableExists(string tableName);
}; };
#endif // DATABASE_H #endif // DATABASE_H

View File

@ -0,0 +1,17 @@
#include "model/recipe/ingredientlistmodel.h"
IngredientListModel::IngredientListModel(){
this->ingredients = vector<Ingredient>();
}
int IngredientListModel::rowCount(const QModelIndex &parent){
return this->ingredients.size();
}
QVariant IngredientListModel::data(const QModelIndex &index, int role){
}
void IngredientListModel::setIngredients(vector<Ingredient> ingredients){
this->ingredients = ingredients;
}

View File

@ -0,0 +1,24 @@
#ifndef INGREDIENTLISTMODEL_H
#define INGREDIENTLISTMODEL_H
#include <QAbstractListModel>
#include "model/recipe/ingredient.h"
class IngredientListModel : public QAbstractListModel
{
public:
IngredientListModel();
//Overridden methods.
int rowCount(const QModelIndex &parent = QModelIndex());
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole);
//Custom methods to handle ingredient data.
void setIngredients(vector<Ingredient> ingredients);
private:
vector<Ingredient> ingredients;
};
#endif // INGREDIENTLISTMODEL_H

View File

@ -1,6 +1,25 @@
#include "headers/recipe.h" #include "model/recipe/recipe.h"
Recipe::Recipe()
{
Recipe::Recipe(){
this->name = "NULL";
this->ingredients = vector<Ingredient>();
this->instructions = vector<Instruction>();
}
Recipe::Recipe(string name, vector<Ingredient> ingredients, vector<Instruction> instructions){
this->name = name;
this->ingredients = ingredients;
this->instructions = instructions;
}
string Recipe::getName(){
return this->name;
}
vector<Ingredient> Recipe::getIngredients(){
return this->ingredients;
}
vector<Instruction> Recipe::getInstructions(){
return this->instructions;
} }

View File

@ -5,8 +5,8 @@
#include <string> #include <string>
#include <hash_map> #include <hash_map>
#include "headers/ingredient.h" #include "model/recipe/ingredient.h"
#include "headers/instruction.h" #include "model/recipe/instruction.h"
using namespace std; using namespace std;
@ -14,13 +14,17 @@ class Recipe
{ {
public: public:
Recipe(); Recipe();
Recipe(string name, vector<Ingredient> ingredients, vector<Instruction> instructions);
string getName(); string getName();
vector<Ingredient> getIngredients();
vector<Instruction> getInstructions();
private: private:
string name; string name;
vector<string> tags; vector<string> tags;
vector<Ingredient> ingredients; vector<Ingredient> ingredients;
vector<Instruction> instructions; vector<Instruction> instructions;
}; };
#endif // RECIPE_H #endif // RECIPE_H

View File

@ -3,12 +3,28 @@
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow){
{
ui->setupUi(this); ui->setupUi(this);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow(){
{
delete ui; delete ui;
} }
void MainWindow::loadFromRecipe(Recipe recipe){
setRecipeName(recipe.getName());
setInstructions(recipe.getInstructions());
setIngredients(recipe.getIngredients());
}
void MainWindow::setRecipeName(string name){
ui->recipeNameLabel->setText(QString::fromStdString(name));
}
void MainWindow::setInstructions(vector<Instruction> instructions){
}
void MainWindow::setIngredients(vector<Ingredient> ingredients){
ui->listView
}

View File

@ -2,6 +2,11 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <string>
#include "model/recipe/recipe.h"
using namespace std;
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -15,8 +20,15 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
//Loads all data from a recipe into the GUI components.
void loadFromRecipe(Recipe recipe);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
//Hidden manipulation methods.
void setRecipeName(string name);
void setInstructions(vector<Instruction> instructions);
void setIngredients(vector<Ingredient> ingredients);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H