1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
void CalorieCounter::submitFood()
{
QString food = foodLine->text();
QString calorie = calorieLine->text();
QString protein = proteinLine->text();
QString carb = carbLine->text();
QString fat = fatLine->text();
QString sugar = sugarLine->text();
QString sodium = sodiumLine->text();
QString fiber = fiberLine->text();
if (food.isEmpty() || calorie.isEmpty() || protein.isEmpty()
|| carb.isEmpty() || fat.isEmpty() || sugar.isEmpty()
|| sodium.isEmpty() || fiber.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter food, calorie, protein, carb, fat, sugar, sodium and fiber"));
return;
}
if (currentMode == AddingMode) {
if (!foods.contains(food)) {
foods.insert(food, calorie, protein, carb, fat, sugar, sodium, fiber);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your calorie counter.").arg(food));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your calorie counter.").arg(food));
}
} else if (currentMode == EditingMode) {
if (oldFood != food) {
if (!foods.contains(food)) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(oldFood));
foods.remove(oldFood);
foods.insert(food, calorie, protein, carb, fat, sugar, sodium, fiber);
} else {
QMessageBox::information(this, tr("Edit Unsuccessful"),
tr("Sorry, \"%1\" is already in your calorie counter.").arg(food));
}
} else if (oldCalorie != calorie) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = calorie;
} else if (oldProtein != protein) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = protein;
}
else if (oldCarb != carb) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = carb;
} else if (oldFat != fat) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = fat;
} else if (oldSugar != sugar) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = sugar;
} else if (oldSodium != sodium) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = sodium;
}
else if (oldFiber != fiber) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your calorie counter.").arg(food));
foods[food] = fiber;
}
}
updateInterface(NavigationMode);
}
|