Periodic update of progress. #4
|
@ -462,6 +462,12 @@ QPushButton#browseButton:pressed{
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextEdit" name="instructionsTextEdit">
|
<widget class="QTextEdit" name="instructionsTextEdit">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Noto Sans CJK KR Medium</family>
|
||||||
|
<stylestrategy>PreferAntialias</stylestrategy>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true">background-color: rgb(244, 244, 244);</string>
|
<string notr="true">background-color: rgb(244, 244, 244);</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -493,7 +499,7 @@ QPushButton#browseButton:pressed{
|
||||||
<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:'Liberation Serif Bold'; font-size:11pt; font-weight:400; font-style:normal;">
|
</style></head><body style=" font-family:'Noto Sans CJK KR Medium'; 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=" 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>
|
<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">
|
||||||
|
|
|
@ -5,6 +5,8 @@ NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::NewRecipeDialog){
|
ui(new Ui::NewRecipeDialog){
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->ingredientsListView->setModel(&this->ingredientListModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
||||||
|
@ -19,10 +21,6 @@ NewRecipeDialog::~NewRecipeDialog(){
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewRecipeDialog::on_toolButton_clicked(){
|
|
||||||
ui->instructionsTextEdit->setFontItalic(!ui->instructionsTextEdit->fontItalic());
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewRecipeDialog::populateIngredientsBox(){
|
void NewRecipeDialog::populateIngredientsBox(){
|
||||||
this->ingredients = this->recipeDB->retrieveAllIngredients();
|
this->ingredients = this->recipeDB->retrieveAllIngredients();
|
||||||
ui->ingredientNameBox->clear();
|
ui->ingredientNameBox->clear();
|
||||||
|
@ -40,3 +38,23 @@ void NewRecipeDialog::populateUnitsBox(){
|
||||||
ui->unitComboBox->insertItem(i, s);
|
ui->unitComboBox->insertItem(i, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewRecipeDialog::on_addIngredientButton_clicked(){
|
||||||
|
//Construct a recipe ingredient from the supplied data.
|
||||||
|
Ingredient i = this->ingredients[ui->ingredientNameBox->currentIndex()];
|
||||||
|
UnitOfMeasure u = this->units[ui->unitComboBox->currentIndex()];
|
||||||
|
RecipeIngredient ri(i, ui->quantitySpinBox->value(), u, ui->commentsLineEdit->text().toStdString());
|
||||||
|
this->ingredientListModel.addIngredient(ri);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewRecipeDialog::on_italicsButton_clicked(){
|
||||||
|
ui->instructionsTextEdit->setFontItalic(ui->italicsButton->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewRecipeDialog::on_boldButton_clicked(){
|
||||||
|
if (ui->boldButton->isChecked()){
|
||||||
|
ui->instructionsTextEdit->setFontWeight(QFont::Bold);
|
||||||
|
} else {
|
||||||
|
ui->instructionsTextEdit->setFontWeight(QFont::Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
|
||||||
#include "model/database/recipedatabase.h"
|
#include "model/database/recipedatabase.h"
|
||||||
|
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class NewRecipeDialog;
|
class NewRecipeDialog;
|
||||||
|
@ -20,13 +21,18 @@ class NewRecipeDialog : public QDialog
|
||||||
~NewRecipeDialog();
|
~NewRecipeDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_toolButton_clicked();
|
void on_addIngredientButton_clicked();
|
||||||
|
|
||||||
|
void on_italicsButton_clicked();
|
||||||
|
|
||||||
|
void on_boldButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::NewRecipeDialog *ui;
|
Ui::NewRecipeDialog *ui;
|
||||||
RecipeDatabase *recipeDB;
|
RecipeDatabase *recipeDB;
|
||||||
vector<Ingredient> ingredients;
|
vector<Ingredient> ingredients;
|
||||||
vector<UnitOfMeasure> units;
|
vector<UnitOfMeasure> units;
|
||||||
|
IngredientListModel ingredientListModel;
|
||||||
|
|
||||||
//Helper functions to fill fields.
|
//Helper functions to fill fields.
|
||||||
void populateIngredientsBox();
|
void populateIngredientsBox();
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
<second>0</second>
|
<second>0</second>
|
||||||
<year>1999</year>
|
<year>1999</year>
|
||||||
<month>12</month>
|
<month>12</month>
|
||||||
<day>28</day>
|
<day>27</day>
|
||||||
</datetime>
|
</datetime>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentSection">
|
<property name="currentSection">
|
||||||
|
@ -160,7 +160,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox">
|
<widget class="QDoubleSpinBox" name="servingsSpinBox">
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -335,6 +335,13 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="unitComboBox"/>
|
<widget class="QComboBox" name="unitComboBox"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="newUnitButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>New</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -389,16 +396,56 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item alignment="Qt::AlignLeft|Qt::AlignTop">
|
||||||
|
<widget class="QWidget" name="textControlPanel" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="toolButton">
|
<widget class="QToolButton" name="italicsButton">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Liberation Serif</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
<italic>true</italic>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>italics</string>
|
<string>I</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolButtonStyle">
|
<property name="toolButtonStyle">
|
||||||
<enum>Qt::ToolButtonIconOnly</enum>
|
<enum>Qt::ToolButtonIconOnly</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="boldButton">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Liberation Serif</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>B</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextEdit" name="instructionsTextEdit">
|
<widget class="QTextEdit" name="instructionsTextEdit">
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
|
|
6
main.cpp
6
main.cpp
|
@ -18,13 +18,17 @@ int main(int argc, char *argv[])
|
||||||
//TESTING CODE
|
//TESTING CODE
|
||||||
vector<RecipeIngredient> ri;
|
vector<RecipeIngredient> ri;
|
||||||
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), ""));
|
ri.push_back(RecipeIngredient("flour", "grains", 3.0f, UnitOfMeasure("cup", "cups", "c", UnitOfMeasure::VOLUME, 1.0), ""));
|
||||||
ri.push_back(RecipeIngredient("Baking Powder", "Additives", 1.0f, UnitOfMeasure("Teaspoon", "Teaspoons", "Tsp", UnitOfMeasure::VOLUME, 1.0), ""));
|
ri.push_back(RecipeIngredient("baking powder", "Additives", 1.0f, UnitOfMeasure("teaspoon", "teaspoons", "tsp", UnitOfMeasure::VOLUME, 1.0), ""));
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
recipeDB.storeUnitOfMeasure(UnitOfMeasure("tablespoon", "tablespoons", "tbsp", UnitOfMeasure::VOLUME, 1.0));
|
||||||
|
recipeDB.storeUnitOfMeasure(UnitOfMeasure("pinch", "pinches", "pch", UnitOfMeasure::VOLUME, 1.0));
|
||||||
|
recipeDB.storeUnitOfMeasure(UnitOfMeasure("gram", "grams", "g", UnitOfMeasure::MASS, 1.0));
|
||||||
|
|
||||||
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
Recipe reloadRec = recipeDB.retrieveRecipe("Example");
|
||||||
reloadRec.print();
|
reloadRec.print();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
||||||
//The quantity is an integer and should be casted.
|
//The quantity is an integer and should be casted.
|
||||||
displayStr += std::to_string((int)i.getQuantity());
|
displayStr += std::to_string((int)i.getQuantity());
|
||||||
} else {
|
} else {
|
||||||
displayStr += std::to_string(i.getQuantity());
|
float q = i.getQuantity();
|
||||||
|
displayStr += toString(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName();
|
displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName();
|
||||||
|
@ -37,3 +38,35 @@ void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
|
||||||
QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
|
QModelIndex bottomIndex = createIndex(ingredients.size()-1, 0);
|
||||||
emit dataChanged(index, bottomIndex);
|
emit dataChanged(index, bottomIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IngredientListModel::addIngredient(RecipeIngredient ri){
|
||||||
|
//Add only if it doesn't exist already.
|
||||||
|
for (unsigned int i = 0; i < this->ingredients.size(); i++){
|
||||||
|
if (!this->ingredients[i].getName().compare(ri.getName())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->ingredients.push_back(ri);
|
||||||
|
QModelIndex index = createIndex(this->ingredients.size()-1, 0);
|
||||||
|
QModelIndex bottomIndex = createIndex(this->ingredients.size()-1, 0);
|
||||||
|
emit dataChanged(index, bottomIndex);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<RecipeIngredient> IngredientListModel::getIngredients(){
|
||||||
|
return this->ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
string toString(float val){
|
||||||
|
float decimal = std::fmod(val, 1.0f);
|
||||||
|
int places = 1;
|
||||||
|
while (std::fmod(decimal * 10, 1.0f) > 0){
|
||||||
|
decimal *= 10;
|
||||||
|
places++;
|
||||||
|
}
|
||||||
|
char buffer[50];
|
||||||
|
string arg = "%."+std::to_string(places)+"f";
|
||||||
|
sprintf(buffer, arg.c_str(), val);
|
||||||
|
string s = buffer;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
|
@ -17,9 +17,15 @@ public:
|
||||||
|
|
||||||
//Custom methods to handle ingredient data.
|
//Custom methods to handle ingredient data.
|
||||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
void setIngredients(vector<RecipeIngredient> ingredients);
|
||||||
|
bool addIngredient(RecipeIngredient ri);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<RecipeIngredient> ingredients;
|
vector<RecipeIngredient> ingredients;
|
||||||
|
|
||||||
|
//Helper for printing.
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
string toString(float val);
|
||||||
|
|
||||||
#endif // INGREDIENTLISTMODEL_H
|
#endif // INGREDIENTLISTMODEL_H
|
||||||
|
|
Loading…
Reference in New Issue