2018-03-10 13:06:24 +00:00
|
|
|
#include "newingredientdialog.h"
|
|
|
|
#include "ui_newingredientdialog.h"
|
|
|
|
|
|
|
|
NewIngredientDialog::NewIngredientDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::NewIngredientDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
2018-03-30 10:56:42 +00:00
|
|
|
NewIngredientDialog::NewIngredientDialog(RecipeDatabase *recipeDB, QWidget *parent) : NewIngredientDialog(parent){
|
|
|
|
this->recipeDB = recipeDB;
|
|
|
|
this->populateFoodGroupBox();
|
|
|
|
}
|
|
|
|
|
2018-03-10 13:06:24 +00:00
|
|
|
NewIngredientDialog::~NewIngredientDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ingredient NewIngredientDialog::getIngredient(){
|
2018-03-30 10:56:42 +00:00
|
|
|
return Ingredient(ui->nameEdit->text().toLower().toStdString(), ui->foodGroupBox->currentText().toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewIngredientDialog::populateFoodGroupBox(){
|
|
|
|
vector<string> foodGroups = this->recipeDB->retrieveAllFoodGroups();
|
|
|
|
ui->foodGroupBox->clear();
|
|
|
|
for (unsigned int i = 0; i < foodGroups.size(); i++){
|
|
|
|
QString s = QString::fromStdString(foodGroups[i]);
|
|
|
|
ui->foodGroupBox->insertItem(i, s);
|
|
|
|
}
|
2018-03-10 13:06:24 +00:00
|
|
|
}
|
2018-03-30 12:33:48 +00:00
|
|
|
|
|
|
|
void NewIngredientDialog::on_addFoodGroupButton_clicked(){
|
|
|
|
newFoodGroupDialog d(this);
|
|
|
|
if (d.exec() == QDialog::Accepted){
|
|
|
|
string s = d.getFoodGroup();
|
|
|
|
if (!s.empty()){
|
|
|
|
ui->foodGroupBox->addItem(QString::fromStdString(s));
|
|
|
|
ui->foodGroupBox->setCurrentText(QString::fromStdString(s));
|
|
|
|
} else {
|
|
|
|
QMessageBox::warning(this, "Empty Food Group", "The food group you entered is empty!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewIngredientDialog::on_deleteFoodGroupButton_clicked(){
|
|
|
|
ui->foodGroupBox->removeItem(ui->foodGroupBox->currentIndex());
|
|
|
|
}
|