Commit 4d97aa75 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Change quantity fractions to double number

parent f3816af7
......@@ -53,6 +53,7 @@ private:
QVariantList buildInstructions(QStringList instrsList);
QVariantList buildProposal(QStringList props);
QString insertPictures(QString item);
double getQuantity(QString qte);
};
#endif // SENDPYWEBCOOKING_H
......@@ -60,6 +60,21 @@ QString SendPyWebCooking::insertPictures(QString item) {
return item;
}
double SendPyWebCooking::getQuantity(QString qte) {
bool ok;
double qte_double = qte.toDouble(&ok);
if (!ok) {
QRegExp exp("^(\\d+)/(\\d+)$");
if (exp.exactMatch(qte)) {
qte_double = exp.cap(1).toDouble() / exp.cap(2).toDouble();
qte_double = floor(qte_double * pow(10., 2) + .5) / pow(10., 2);
}
}
return qte_double;
}
void SendPyWebCooking::buildIngredients(QStringList ingrsList) {
int nb_group = 0;
int nb_ingr = 0;
......@@ -82,7 +97,7 @@ void SendPyWebCooking::buildIngredients(QStringList ingrsList) {
if (ingr_base.startsWith("ingr#")) {
//It's an ingredient
QStringList ingrParts = ingr_base.split("#");
double qte = ingrParts[1].toDouble();
double qte = getQuantity(ingrParts[1]);
QString unit = ingrParts[2];
QString name = ingrParts.mid(3).join("#");
QVariantMap ingr_obj;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment