Periodic update of progress. #4
|
@ -462,6 +462,12 @@ QPushButton#browseButton:pressed{
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="instructionsTextEdit">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Noto Sans CJK KR Medium</family>
|
||||
<stylestrategy>PreferAntialias</stylestrategy>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(244, 244, 244);</string>
|
||||
</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">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
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>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
|
|
|
@ -5,6 +5,8 @@ NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
|||
QDialog(parent),
|
||||
ui(new Ui::NewRecipeDialog){
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->ingredientsListView->setModel(&this->ingredientListModel);
|
||||
}
|
||||
|
||||
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
||||
|
@ -19,10 +21,6 @@ NewRecipeDialog::~NewRecipeDialog(){
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void NewRecipeDialog::on_toolButton_clicked(){
|
||||
ui->instructionsTextEdit->setFontItalic(!ui->instructionsTextEdit->fontItalic());
|
||||
}
|
||||
|
||||
void NewRecipeDialog::populateIngredientsBox(){
|
||||
this->ingredients = this->recipeDB->retrieveAllIngredients();
|
||||
ui->ingredientNameBox->clear();
|
||||
|
@ -40,3 +38,23 @@ void NewRecipeDialog::populateUnitsBox(){
|
|||
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 "model/database/recipedatabase.h"
|
||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||
|
||||
namespace Ui {
|
||||
class NewRecipeDialog;
|
||||
|
@ -20,13 +21,18 @@ class NewRecipeDialog : public QDialog
|
|||
~NewRecipeDialog();
|
||||
|
||||
private slots:
|
||||
void on_toolButton_clicked();
|
||||
void on_addIngredientButton_clicked();
|
||||
|
||||
void on_italicsButton_clicked();
|
||||
|
||||
void on_boldButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::NewRecipeDialog *ui;
|
||||
RecipeDatabase *recipeDB;
|
||||
vector<Ingredient> ingredients;
|
||||
vector<UnitOfMeasure> units;
|
||||
IngredientListModel ingredientListModel;
|
||||
|
||||
//Helper functions to fill fields.
|
||||
void populateIngredientsBox();
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<second>0</second>
|
||||
<year>1999</year>
|
||||
<month>12</month>
|
||||
<day>28</day>
|
||||
<day>27</day>
|
||||
</datetime>
|
||||
</property>
|
||||
<property name="currentSection">
|
||||
|
@ -160,7 +160,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox">
|
||||
<widget class="QDoubleSpinBox" name="servingsSpinBox">
|
||||
<property name="decimals">
|
||||
<number>1</number>
|
||||
</property>
|
||||
|
@ -335,6 +335,13 @@
|
|||
<item>
|
||||
<widget class="QComboBox" name="unitComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newUnitButton">
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -389,14 +396,54 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>italics</string>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
<item alignment="Qt::AlignLeft|Qt::AlignTop">
|
||||
<widget class="QWidget" name="textControlPanel" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QToolButton" name="italicsButton">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Liberation Serif</family>
|
||||
<pointsize>12</pointsize>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>I</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -18,13 +18,17 @@ int main(int argc, char *argv[])
|
|||
//TESTING CODE
|
||||
vector<RecipeIngredient> ri;
|
||||
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);
|
||||
|
||||
bool success = recipeDB.storeRecipe(rec);
|
||||
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");
|
||||
reloadRec.print();
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
|
|||
//The quantity is an integer and should be casted.
|
||||
displayStr += std::to_string((int)i.getQuantity());
|
||||
} else {
|
||||
displayStr += std::to_string(i.getQuantity());
|
||||
float q = i.getQuantity();
|
||||
displayStr += toString(q);
|
||||
}
|
||||
|
||||
displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName();
|
||||
|
@ -35,5 +36,37 @@ void IngredientListModel::setIngredients(vector<RecipeIngredient> ingredients){
|
|||
this->ingredients = ingredients;
|
||||
QModelIndex index = createIndex(0, 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.
|
||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
||||
bool addIngredient(RecipeIngredient ri);
|
||||
|
||||
private:
|
||||
vector<RecipeIngredient> ingredients;
|
||||
|
||||
//Helper for printing.
|
||||
|
||||
};
|
||||
|
||||
string toString(float val);
|
||||
|
||||
#endif // INGREDIENTLISTMODEL_H
|
||||
|
|
Loading…
Reference in New Issue