Added new recipe dialog, improved ingredient list display

This commit is contained in:
Andrew Lalis 2018-03-04 09:05:20 +01:00
parent 446ff8f5ba
commit 358bc8de5d
10 changed files with 161 additions and 36 deletions

View File

@ -25,7 +25,8 @@ SOURCES += model/recipe/instruction.cpp \
SQLite/sqlite3.c \
model/database/resulttable.cpp \
model/database/recipedatabase.cpp \
utils/fileutils.cpp
utils/fileutils.cpp \
gui/newrecipedialog.cpp
HEADERS += model/recipe/instruction.h \
model/recipe/recipe.h \
@ -40,11 +41,13 @@ HEADERS += model/recipe/instruction.h \
SQLite/sqlite3ext.h \
model/database/resulttable.h \
model/database/recipedatabase.h \
utils/fileutils.h
utils/fileutils.h \
gui/newrecipedialog.h
LIBS += -ldl \
FORMS += gui/mainwindow.ui
FORMS += gui/mainwindow.ui \
gui/newrecipedialog.ui
DISTFILES += \
.gitignore

View File

@ -109,12 +109,25 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Light</family>
<pointsize>20</pointsize>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<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 name="text">
<string>New</string>
@ -134,12 +147,22 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Light</family>
<pointsize>20</pointsize>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<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 name="text">
<string>Open</string>
@ -156,16 +179,32 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Light</family>
<pointsize>20</pointsize>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<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 name="text">
<string>Browse</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@ -214,8 +253,13 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Light</family>
<pointsize>24</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<stylestrategy>PreferAntialias</stylestrategy>
<kerning>true</kerning>
</font>
</property>
<property name="styleSheet">
@ -299,7 +343,7 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Thin</family>
<pointsize>18</pointsize>
</font>
</property>
@ -324,8 +368,9 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<pointsize>16</pointsize>
<family>Noto Sans CJK KR Light</family>
<pointsize>12</pointsize>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<property name="styleSheet">
@ -343,6 +388,9 @@
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
@ -397,7 +445,7 @@
</property>
<property name="font">
<font>
<family>Source Sans Pro Light</family>
<family>Noto Sans CJK KR Thin</family>
<pointsize>18</pointsize>
</font>
</property>
@ -445,11 +493,11 @@
<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>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Liberation Serif Bold'; font-size:11pt; 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; font-family:'MS Shell Dlg 2'; font-size:8.25pt; color:#00ff40;&quot;&gt;This is some &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; 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-family:'MS Shell Dlg 2'; 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>
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>

14
gui/newrecipedialog.cpp Normal file
View File

@ -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;
}

22
gui/newrecipedialog.h Normal file
View File

@ -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

19
gui/newrecipedialog.ui Normal file
View File

@ -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>

View File

@ -13,22 +13,16 @@ int main(int argc, char *argv[])
//TESTING CODE
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
vector<RecipeIngredient> ri;
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")));
// vector<RecipeIngredient> ri;
// 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")));
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);
printf("Storage successful: %d\n", success);
// bool success = recipeDB.storeRecipe(rec);
// printf("Storage successful: %d\n", success);
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
reloadRec.print();

View File

@ -117,7 +117,6 @@ Recipe RecipeDatabase::retrieveRecipe(string name){
fprintf(stderr, "Error: No recipe with name %s found!\n", name.c_str());
return Recipe();
}
t.printData();
Recipe r;
int id = std::stoi(t.valueAt(0, 0));
r.setName(t.valueAt(0, 1));
@ -137,7 +136,6 @@ vector<RecipeIngredient> RecipeDatabase::retrieveRecipeIngredients(int recipeId)
"INNER JOIN recipeIngredient "
"ON ingredient.ingredientId = recipeIngredient.ingredientId "
"AND recipeIngredient.recipeId = "+std::to_string(recipeId)+";");
t.printData();
vector<RecipeIngredient> ings;
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)));

View File

@ -10,10 +10,22 @@ int IngredientListModel::rowCount(const QModelIndex &parent) const{
QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
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){
case Qt::DisplayRole:
return QString::fromStdString(ingredients[row].getName());
return QString::fromStdString(displayStr);
}
return QVariant();

View File

@ -1,19 +1,21 @@
#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->plural = plural;
this->abbreviation = abbreviation;
this->type = type;
}
UnitOfMeasure::UnitOfMeasure(string name){
this->name = name;
this->plural = name + "s";
this->abbreviation = "NULL";
this->type = MISC;
///TODO: Make actual guessing of this stuff.
}
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", ""){
UnitOfMeasure::UnitOfMeasure() : UnitOfMeasure::UnitOfMeasure("", "", "", MISC){
//Default constructor initializes all fields to empty strings.
}
@ -26,5 +28,9 @@ string UnitOfMeasure::getNamePlural() const{
}
string UnitOfMeasure::getAbbreviation() const{
return this->abbreviation;
return this->abbreviation;
}
int UnitOfMeasure::getType() const{
return this->type;
}

View File

@ -12,8 +12,14 @@ using namespace std;
class UnitOfMeasure
{
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.
UnitOfMeasure(string name, string plural, string abbreviation);
UnitOfMeasure(string name, string plural, string abbreviation, int type);
//Attempt to guess unit from just a string.
UnitOfMeasure(string name);
//Constructor with default values.
@ -23,10 +29,13 @@ public:
string getName() const;
string getNamePlural() const;
string getAbbreviation() const;
int getType() const;
private:
string name; //The name of the unit of measure.
string plural; //The plural name.
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