2018-03-04 08:05:20 +00:00
|
|
|
#include "newrecipedialog.h"
|
|
|
|
#include "ui_newrecipedialog.h"
|
|
|
|
|
|
|
|
NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
2018-03-10 07:51:17 +00:00
|
|
|
ui(new Ui::NewRecipeDialog){
|
2018-03-04 08:05:20 +00:00
|
|
|
ui->setupUi(this);
|
2018-03-10 09:42:22 +00:00
|
|
|
|
|
|
|
ui->ingredientsListView->setModel(&this->ingredientListModel);
|
2018-03-04 08:05:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 07:51:17 +00:00
|
|
|
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
|
|
|
this->recipeDB = db;
|
|
|
|
|
|
|
|
|
|
|
|
this->populateIngredientsBox();
|
|
|
|
this->populateUnitsBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewRecipeDialog::~NewRecipeDialog(){
|
2018-03-04 08:05:20 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
2018-03-10 07:51:17 +00:00
|
|
|
|
|
|
|
void NewRecipeDialog::populateIngredientsBox(){
|
|
|
|
this->ingredients = this->recipeDB->retrieveAllIngredients();
|
|
|
|
ui->ingredientNameBox->clear();
|
|
|
|
for (unsigned int i = 0; i < this->ingredients.size(); i++){
|
|
|
|
QString s = QString::fromStdString(this->ingredients[i].getName());
|
|
|
|
ui->ingredientNameBox->insertItem(i, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::populateUnitsBox(){
|
|
|
|
this->units = this->recipeDB->retrieveAllUnitsOfMeasure();
|
|
|
|
ui->unitComboBox->clear();
|
|
|
|
for (unsigned int i = 0; i < this->units.size(); i++){
|
|
|
|
QString s = QString::fromStdString(this->units[i].getName());
|
|
|
|
ui->unitComboBox->insertItem(i, s);
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 09:42:22 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|