From 8b65d0eb2815576780c57df428c1faf23fe75068 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 1 May 2022 17:31:28 +0200 Subject: Add ingredient group support for both krecipes and gourmet databases and show them in the viewer. --- src/viewer.cc | 55 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'src/viewer.cc') diff --git a/src/viewer.cc b/src/viewer.cc index e3c25be..b0b6f35 100644 --- a/src/viewer.cc +++ b/src/viewer.cc @@ -50,24 +50,33 @@ void Viewer::show(const Recipe& recipe) instructions.replace("\n", "
"); QString ingredients; - for(const auto& ingredient : recipe.ingredients) + for(const auto& ingredient_group : recipe.ingredient_groups) { - if(ingredient.amount > 0) + if(ingredient_group.title != "") { - ingredients += - "
  • " + - QString::number(ingredient.amount) + " " + - QString::fromUtf8(ingredient.unit.data()) + " " + - QString::fromUtf8(ingredient.item.data()) + - "
  • "; + ingredients += "

    " + QString::fromUtf8(ingredient_group.title.data()) + "

    "; } - else + ingredients += ""; } QByteArray image(recipe.image.data(), recipe.image.size()); @@ -76,6 +85,20 @@ void Viewer::show(const Recipe& recipe) image = QByteArray::fromBase64(image); } + QString db; + switch(recipe.db) + { + case DatabaseSource::KRecipes: + db = "KRecipes"; + break; + case DatabaseSource::Gourmet: + db = "Gourmet"; + break; + case DatabaseSource::Qookie: + db = "Qookie"; + break; + } + QString html = "
    " + QString::fromUtf8(recipe.title.data()) + "

    " "" @@ -83,6 +106,7 @@ void Viewer::show(const Recipe& recipe) "" "" "" "
    " "

    " + QString::fromUtf8(recipe.description.data()) + "

    " "

    " + "Database: " + db + " (id:" + QString::number(recipe.id) + ")
    " "Source: " + QString::fromUtf8(recipe.source.data()) + "
    " "Cuisine: " + QString::fromUtf8(recipe.cuisine.data()) + "
    " "Cooktime: " + QString::number(recipe.cooktime / 60) + "min
    " @@ -90,15 +114,14 @@ void Viewer::show(const Recipe& recipe) "Yields: " + QString::number(recipe.yields) + " " + QString::fromUtf8(recipe.yield_unit.data()) + "
    " "Tags: " + QString::fromUtf8(recipe.tags[0].data()) + "" "

    " - "

    Ingredients

    " - "
      " + ingredients + "
    " + "

    Ingredienser

    " + ingredients + "
    " "" "
    " - "

    Instructions

    " + "

    Instruktioner

    " "

    " + instructions + "

    " ; textEdit->setHtml(html); -- cgit v1.2.3