Re-organized files, added model objects, basic UI.

This commit is contained in:
Andrew Lalis 2018-02-02 13:27:57 +01:00
parent 661590ecc4
commit d648062314
16 changed files with 434 additions and 23 deletions

View File

@ -12,16 +12,28 @@ TARGET = RecipeDB
TEMPLATE = app TEMPLATE = app
SOURCES += sources/main.cpp \ SOURCES += SQLite/sqlite3.c \
sources/mainwindow.cpp \ model/recipe/ingredient.cpp \
SQLite/sqlite3.c model/recipe/instruction.cpp \
model/recipe/recipe.cpp \
model/recipe/recipeingredient.cpp \
userInterface/mainwindow.cpp \
main.cpp \
model/database/database.cpp
HEADERS += \ HEADERS += SQLite/sqlite3.h \
headers/mainwindow.h \ SQLite/sqlite3ext.h \
SQLite/sqlite3.h \ model/recipe/ingredient.h \
SQLite/sqlite3ext.h model/recipe/instruction.h \
model/recipe/recipe.h \
model/recipe/recipeingredient.h \
userInterface/mainwindow.h \
model/database/database.h
FORMS += gui/mainwindow.ui FORMS += gui/mainwindow.ui
DISTFILES += \ DISTFILES += \
.gitignore .gitignore
RESOURCES += \
gui/menubuttonstylesheet.qrc

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>MainWindow</class> <class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow"> <widget class="QMainWindow" name="MainWindow">
@ -5,20 +6,200 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>1000</width>
<height>300</height> <height>500</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="sizePolicy">
<string>MainWindow</string> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="windowTitle">
<string>RecipeDB</string>
</property>
<property name="windowOpacity">
<double>1.000000000000000</double>
</property>
<widget class="QWidget" name="mainWidget">
<widget class="QWidget" name="menuBarWidget" native="true">
<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> </property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget> </widget>
<layoutDefault spacing="6" margin="11" /> <widget class="QWidget" name="">
<pixmapfunction></pixmapfunction> <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">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QPushButton" name="newRecipeButton">
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);
color: rgb(0, 0, 104);</string>
</property>
<property name="text">
<string>New</string>
</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">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="openRecipeButton">
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);
color: rgb(0, 0, 104);</string>
</property>
<property name="text">
<string>Open</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="browseButton">
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);
color: rgb(0, 0, 104);</string>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>149</x>
<y>-1</y>
<width>861</width>
<height>511</height>
</rect>
</property>
<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>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="widgetResizable">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>859</width>
<height>509</height>
</rect>
</property>
</widget>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -0,0 +1,4 @@
<RCC>
<qresource prefix="/images"/>
<qresource prefix="/stylesheets"/>
</RCC>

View File

@ -1,12 +1,12 @@
#include "headers/mainwindow.h" #include "userInterface/mainwindow.h"
#include <QApplication> #include <QApplication>
#include <iostream> #include <iostream>
#include "SQLite/sqlite3.h" #include "SQLite/sqlite3.h"
static int callback(void* data, int argc, char** argv, char** azColName){ static int callback(void* data, int rows, char** argv, char** azColName){
int i; int i;
fprintf(stderr, "%s: ", (const char*)data); fprintf(stderr, "%s: ", (const char*)data);
for(i=0; i<argc; i++){ for(i=0; i<rows; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
} }
printf("\n"); printf("\n");

View File

@ -0,0 +1,13 @@
#include "model/database/database.h"
Database::Database(){
}
void Database::openConnection(){
this->returnCode = sqlite3_open(this->filename.c_str(), &this->db);
if (this->returnCode){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(EXIT_FAILURE);
}
}

29
model/database/database.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef DATABASE_H
#define DATABASE_H
#include <string>
#include <vector>
#include "SQLite/sqlite3.h"
#include "model/recipe/ingredient.h"
using namespace std;
class Database
{
public:
Database(string filename);
void insertIngredient(Ingredient);
vector<Ingredient> getIngredients();
private:
string filename;
sqlite3* db;
int returnCode;
string sql;
char* errorMsg;
void openConnection();
};
#endif // DATABASE_H

View File

@ -0,0 +1,37 @@
#include "headers/ingredient.h"
Ingredient::Ingredient(){
setId(-1);
setName("NULL");
setFoodGroup("NULL");
}
Ingredient::Ingredient(int id, string name, string foodGroup){
setId(id);
setName(name);
setFoodGroup(foodGroup);
}
int Ingredient::getId(){
return this->id;
}
string Ingredient::getName(){
return this->name;
}
string Ingredient::getFoodGroup(){
return this->foodGroup;
}
void Ingredient::setId(int newId){
this->id = newId;
}
void Ingredient::setName(string newName){
this->name = newName;
}
void Ingredient::setFoodGroup(string newFoodGroup){
this->foodGroup = newFoodGroup;
}

27
model/recipe/ingredient.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef INGREDIENT_H
#define INGREDIENT_H
#include <string>
using namespace std;
class Ingredient
{
public:
Ingredient();
Ingredient(int id, string name, string foodGroup);
int getId();
string getName();
string getFoodGroup();
void setId(int newId);
void setName(string newName);
void setFoodGroup(string newFoodGroup);
protected:
int id;
string name;
string foodGroup;
};
#endif // INGREDIENT_H

View File

@ -0,0 +1,6 @@
#include "headers/instruction.h"
Instruction::Instruction()
{
}

View File

@ -0,0 +1,11 @@
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
class Instruction
{
public:
Instruction();
};
#endif // INSTRUCTION_H

6
model/recipe/recipe.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "headers/recipe.h"
Recipe::Recipe()
{
}

26
model/recipe/recipe.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef RECIPE_H
#define RECIPE_H
#include <vector>
#include <string>
#include <hash_map>
#include "headers/ingredient.h"
#include "headers/instruction.h"
using namespace std;
class Recipe
{
public:
Recipe();
string getName();
private:
string name;
vector<string> tags;
vector<Ingredient> ingredients;
vector<Instruction> instructions;
};
#endif // RECIPE_H

View File

@ -0,0 +1,30 @@
#include "headers/recipeingredient.h"
RecipeIngredient::RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit) : Ingredient(id, name, foodGroup){
setQuantity(quantity);
setUnit(unit);
}
RecipeIngredient::RecipeIngredient(Ingredient i, int quantity, string unit){
setId(i.getId());
setName(i.getName());
setFoodGroup(i.getFoodGroup());
setQuantity(quantity);
setUnit(unit);
}
string RecipeIngredient::getComment(){
return this->comment;
}
void RecipeIngredient::setQuantity(int newQuantity){
this->quantity = newQuantity;
}
void RecipeIngredient::setUnit(string newUnit){
this->unit = newUnit;
}
void RecipeIngredient::setComment(string newComment){
this->comment = newComment;
}

View File

@ -0,0 +1,29 @@
#ifndef RECIPEINGREDIENT_H
#define RECIPEINGREDIENT_H
#include <string>
#include "headers/ingredient.h"
using namespace std;
class RecipeIngredient : public Ingredient
{
public:
RecipeIngredient(int id, string name, string foodGroup, int quantity, string unit);
RecipeIngredient(Ingredient i, int quantity, string unit);
int getQuantity();
string getUnit();
string getComment();
void setQuantity(int newQuantity);
void setUnit(string newUnit);
void setComment(string newComment);
private:
int quantity;
string unit;
string comment;
};
#endif // RECIPEINGREDIENT_H

View File

@ -1,4 +1,4 @@
#include "headers/mainwindow.h" #include "userInterface/mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :