Added new recipe dialog, improved ingredient list display
This commit is contained in:
parent
446ff8f5ba
commit
358bc8de5d
|
@ -25,7 +25,8 @@ SOURCES += model/recipe/instruction.cpp \
|
||||||
SQLite/sqlite3.c \
|
SQLite/sqlite3.c \
|
||||||
model/database/resulttable.cpp \
|
model/database/resulttable.cpp \
|
||||||
model/database/recipedatabase.cpp \
|
model/database/recipedatabase.cpp \
|
||||||
utils/fileutils.cpp
|
utils/fileutils.cpp \
|
||||||
|
gui/newrecipedialog.cpp
|
||||||
|
|
||||||
HEADERS += model/recipe/instruction.h \
|
HEADERS += model/recipe/instruction.h \
|
||||||
model/recipe/recipe.h \
|
model/recipe/recipe.h \
|
||||||
|
@ -40,11 +41,13 @@ HEADERS += model/recipe/instruction.h \
|
||||||
SQLite/sqlite3ext.h \
|
SQLite/sqlite3ext.h \
|
||||||
model/database/resulttable.h \
|
model/database/resulttable.h \
|
||||||
model/database/recipedatabase.h \
|
model/database/recipedatabase.h \
|
||||||
utils/fileutils.h
|
utils/fileutils.h \
|
||||||
|
gui/newrecipedialog.h
|
||||||
|
|
||||||
LIBS += -ldl \
|
LIBS += -ldl \
|
||||||
|
|
||||||
FORMS += gui/mainwindow.ui
|
FORMS += gui/mainwindow.ui \
|
||||||
|
gui/newrecipedialog.ui
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES += \
|
||||||
.gitignore
|
.gitignore
|
||||||
|
|
|
@ -109,12 +109,25 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Light</family>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="autoFillBackground">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(83, 75, 255);</string>
|
<string notr="true">QPushButton#newButton {
|
||||||
|
background-color: rgb(235, 235, 255);
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
QPushButton#newButton:hover{
|
||||||
|
background-color: rgb(245, 245, 255);
|
||||||
|
}
|
||||||
|
QPushButton#newButton:pressed{
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New</string>
|
<string>New</string>
|
||||||
|
@ -134,12 +147,22 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Light</family>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(112, 105, 255);</string>
|
<string notr="true">QPushButton#openButton {
|
||||||
|
background-color: rgb(222, 226, 255);
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
QPushButton#openButton:hover{
|
||||||
|
background-color: rgb(232, 236, 255);
|
||||||
|
}
|
||||||
|
QPushButton#openButton:pressed{
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open</string>
|
<string>Open</string>
|
||||||
|
@ -156,16 +179,32 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Light</family>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="autoFillBackground">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(137, 131, 255);</string>
|
<string notr="true">QPushButton#browseButton {
|
||||||
|
background-color: rgb(215, 215, 255);
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
QPushButton#browseButton:hover{
|
||||||
|
background-color: rgb(225, 225, 255);
|
||||||
|
}
|
||||||
|
QPushButton#browseButton:pressed{
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Browse</string>
|
<string>Browse</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="flat">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -214,8 +253,13 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Light</family>
|
||||||
<pointsize>24</pointsize>
|
<pointsize>24</pointsize>
|
||||||
|
<weight>50</weight>
|
||||||
|
<italic>false</italic>
|
||||||
|
<bold>false</bold>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
|
<kerning>true</kerning>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
|
@ -299,7 +343,7 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Thin</family>
|
||||||
<pointsize>18</pointsize>
|
<pointsize>18</pointsize>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
@ -324,8 +368,9 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Light</family>
|
||||||
<pointsize>16</pointsize>
|
<pointsize>12</pointsize>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
|
@ -343,6 +388,9 @@
|
||||||
<property name="horizontalScrollBarPolicy">
|
<property name="horizontalScrollBarPolicy">
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
<property name="isWrapping" stdset="0">
|
<property name="isWrapping" stdset="0">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -397,7 +445,7 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Source Sans Pro Light</family>
|
<family>Noto Sans CJK KR Thin</family>
|
||||||
<pointsize>18</pointsize>
|
<pointsize>18</pointsize>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
@ -445,11 +493,11 @@
|
||||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
p, li { white-space: pre-wrap; }
|
p, li { white-space: pre-wrap; }
|
||||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
</style></head><body style=" font-family:'Liberation Serif Bold'; font-size:11pt; font-weight:400; font-style:normal;">
|
||||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#00ff40;">This is some </span><span style=" font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html></string>
|
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; color:#00ff40;">This is some </span><span style=" font-family:'MS Shell Dlg 2'; font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="textInteractionFlags">
|
<property name="textInteractionFlags">
|
||||||
<set>Qt::LinksAccessibleByMouse</set>
|
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "newrecipedialog.h"
|
||||||
|
#include "ui_newrecipedialog.h"
|
||||||
|
|
||||||
|
NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::NewRecipeDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
NewRecipeDialog::~NewRecipeDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef NEWRECIPEDIALOG_H
|
||||||
|
#define NEWRECIPEDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class NewRecipeDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewRecipeDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NewRecipeDialog(QWidget *parent = 0);
|
||||||
|
~NewRecipeDialog();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::NewRecipeDialog *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NEWRECIPEDIALOG_H
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version='1.0'?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NewRecipeDialog</class>
|
||||||
|
<widget class="QDialog" name="NewRecipeDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>640</width>
|
||||||
|
<height>480</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
18
main.cpp
18
main.cpp
|
@ -13,22 +13,16 @@ int main(int argc, char *argv[])
|
||||||
//TESTING CODE
|
//TESTING CODE
|
||||||
|
|
||||||
RecipeDatabase recipeDB("recipes");
|
RecipeDatabase recipeDB("recipes");
|
||||||
// recipeDB.storeIngredient(Ingredient("Apple", "Fruit"));
|
|
||||||
// recipeDB.storeIngredient(Ingredient("Corn", "Vegetable"));
|
|
||||||
// recipeDB.storeIngredient(Ingredient("Lettuce", "Vegetable"));
|
|
||||||
// recipeDB.storeIngredient(Ingredient("Carrot", "Vegetable"));
|
|
||||||
|
|
||||||
// recipeDB.executeSQL("SELECT * FROM ingredient;").printData();
|
|
||||||
|
|
||||||
//TESTING CODE
|
//TESTING CODE
|
||||||
vector<RecipeIngredient> ri;
|
// vector<RecipeIngredient> ri;
|
||||||
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c")));
|
// ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c")));
|
||||||
ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp")));
|
// ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp")));
|
||||||
|
|
||||||
Recipe rec("Example", ri, Instruction("<b>BOLD</b><i>iTaLiCs</i>"), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f);
|
// Recipe rec("Example", ri, Instruction("<b>BOLD</b><i>iTaLiCs</i>"), QImage(), vector<RecipeTag>(), QDate::currentDate(), QTime(0, 30), QTime(0, 25), 10.0f);
|
||||||
|
|
||||||
bool success = recipeDB.storeRecipe(rec);
|
// bool success = recipeDB.storeRecipe(rec);
|
||||||
printf("Storage successful: %d\n", success);
|
// printf("Storage successful: %d\n", success);
|
||||||
|
|
||||||
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
||||||
reloadRec.print();
|
reloadRec.print();
|
||||||
|
|
|
@ -117,7 +117,6 @@ Recipe RecipeDatabase::retrieveRecipe(string name){
|
||||||
fprintf(stderr, "Error: No recipe with name %s found!\n", name.c_str());
|
fprintf(stderr, "Error: No recipe with name %s found!\n", name.c_str());
|
||||||
return Recipe();
|
return Recipe();
|
||||||
}
|
}
|
||||||
t.printData();
|
|
||||||
Recipe r;
|
Recipe r;
|
||||||
int id = std::stoi(t.valueAt(0, 0));
|
int id = std::stoi(t.valueAt(0, 0));
|
||||||
r.setName(t.valueAt(0, 1));
|
r.setName(t.valueAt(0, 1));
|
||||||
|
@ -137,7 +136,6 @@ vector<RecipeIngredient> RecipeDatabase::retrieveRecipeIngredients(int recipeId)
|
||||||
"INNER JOIN recipeIngredient "
|
"INNER JOIN recipeIngredient "
|
||||||
"ON ingredient.ingredientId = recipeIngredient.ingredientId "
|
"ON ingredient.ingredientId = recipeIngredient.ingredientId "
|
||||||
"AND recipeIngredient.recipeId = "+std::to_string(recipeId)+";");
|
"AND recipeIngredient.recipeId = "+std::to_string(recipeId)+";");
|
||||||
t.printData();
|
|
||||||
vector<RecipeIngredient> ings;
|
vector<RecipeIngredient> ings;
|
||||||
for (unsigned int row = 0; row < t.rowCount(); row++){
|
for (unsigned int row = 0; row < t.rowCount(); row++){
|
||||||
RecipeIngredient r(t.valueAt(row, 0), t.valueAt(row, 1), std::stof(t.valueAt(row, 2)), UnitOfMeasure(t.valueAt(row, 3)));
|
RecipeIngredient r(t.valueAt(row, 0), t.valueAt(row, 1), std::stof(t.valueAt(row, 2)), UnitOfMeasure(t.valueAt(row, 3)));
|
||||||
|
|
|
@ -10,10 +10,22 @@ int IngredientListModel::rowCount(const QModelIndex &parent) const{
|
||||||
|
|
||||||
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
|
RecipeIngredient i = this->ingredients[row];
|
||||||
|
|
||||||
|
string displayStr;
|
||||||
|
|
||||||
|
if (std::ceil(i.getQuantity()) == i.getQuantity()){
|
||||||
|
//The quantity is an integer and should be casted.
|
||||||
|
displayStr += std::to_string((int)i.getQuantity());
|
||||||
|
} else {
|
||||||
|
displayStr += std::to_string(i.getQuantity());
|
||||||
|
}
|
||||||
|
|
||||||
|
displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName();
|
||||||
|
|
||||||
switch(role){
|
switch(role){
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return QString::fromStdString(ingredients[row].getName());
|
return QString::fromStdString(displayStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
#include "unitofmeasure.h"
|
#include "unitofmeasure.h"
|
||||||
|
|
||||||
UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation){
|
UnitOfMeasure::UnitOfMeasure(string name, string plural, string abbreviation, int type){
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->plural = plural;
|
this->plural = plural;
|
||||||
this->abbreviation = abbreviation;
|
this->abbreviation = abbreviation;
|
||||||
|
this->type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitOfMeasure::UnitOfMeasure(string name){
|
UnitOfMeasure::UnitOfMeasure(string name){
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->plural = name + "s";
|
this->plural = name + "s";
|
||||||
this->abbreviation = "NULL";
|
this->abbreviation = "NULL";
|
||||||
|
this->type = MISC;
|
||||||
///TODO: Make actual guessing of this stuff.
|
///TODO: Make actual guessing of this stuff.
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){
|
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", "", MISC){
|
||||||
//Default constructor initializes all fields to empty strings.
|
//Default constructor initializes all fields to empty strings.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,5 +28,9 @@ string UnitOfMeasure::getNamePlural() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
string UnitOfMeasure::getAbbreviation() const{
|
string UnitOfMeasure::getAbbreviation() const{
|
||||||
return this->abbreviation;
|
return this->abbreviation;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnitOfMeasure::getType() const{
|
||||||
|
return this->type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,14 @@ using namespace std;
|
||||||
class UnitOfMeasure
|
class UnitOfMeasure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//Constants Declarations.
|
||||||
|
static const int MASS = 1;
|
||||||
|
static const int VOLUME = 2;
|
||||||
|
static const int LENGTH = 3;
|
||||||
|
static const int MISC = 4;
|
||||||
|
|
||||||
//Full constructor.
|
//Full constructor.
|
||||||
UnitOfMeasure(string name, string plural, string abbreviation);
|
UnitOfMeasure(string name, string plural, string abbreviation, int type);
|
||||||
//Attempt to guess unit from just a string.
|
//Attempt to guess unit from just a string.
|
||||||
UnitOfMeasure(string name);
|
UnitOfMeasure(string name);
|
||||||
//Constructor with default values.
|
//Constructor with default values.
|
||||||
|
@ -23,10 +29,13 @@ public:
|
||||||
string getName() const;
|
string getName() const;
|
||||||
string getNamePlural() const;
|
string getNamePlural() const;
|
||||||
string getAbbreviation() const;
|
string getAbbreviation() const;
|
||||||
|
int getType() const;
|
||||||
private:
|
private:
|
||||||
string name; //The name of the unit of measure.
|
string name; //The name of the unit of measure.
|
||||||
string plural; //The plural name.
|
string plural; //The plural name.
|
||||||
string abbreviation; //A short version of the unit.
|
string abbreviation; //A short version of the unit.
|
||||||
|
int type; //The type of unit, as one of the constants above.
|
||||||
|
double metricCoefficient; //The conversion from this unit to the standard metric unit.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UNITOFMEASURE_H
|
#endif // UNITOFMEASURE_H
|
||||||
|
|
Loading…
Reference in New Issue