From 4ea6204d2ead3c15bda99744be8209bedfb6012b Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sun, 12 Nov 2017 19:05:14 -0500 Subject: [PATCH] Fix Dimension value format with Qt5 - Dimension values were displayed as zero for locales with "," decimal point in Qt5. --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 572e2bb5ce..6d59671e9b 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -209,12 +209,13 @@ std::string DrawViewDimension::getFormatedValue() QString userStr = qVal.getUserString(); //this handles mm to inch/km/parsec etc and decimal positions //but won't give more than Global_Decimals precision //really should be able to ask units for value in appropriate UoM!! - QRegExp rxUnits(QString::fromUtf8("\\D*$")); //any non digits at end of string + QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string QString userVal = userStr; userVal.remove(rxUnits); //getUserString(defaultDecimals) without units - double userValNum = userVal.toDouble(); + QLocale loc; + double userValNum = loc.toDouble(userVal); QString userUnits; int pos = 0; @@ -227,7 +228,7 @@ std::string DrawViewDimension::getFormatedValue() //find the %x.y tag in FormatSpec QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.*[0-9]*[aefgAEFG]")); //printf double format spec QString match; - QString specVal = Base::Tools::fromStdString("%.2f"); //sensible default + QString specVal = userVal; //sensible default pos = 0; if ((pos = rxFormat.indexIn(specStr, 0)) != -1) { match = rxFormat.cap(0); //entire capture of rx @@ -256,6 +257,11 @@ std::string DrawViewDimension::getFormatedValue() repl = Base::Tools::fromStdString(getPrefix()) + repl; specStr.replace(match,repl); + //this next bit is so inelegant!!! + QChar dp = QChar::fromLatin1('.'); + if (loc.decimalPoint() != dp) { + specStr.replace(dp,loc.decimalPoint()); + } return specStr.toUtf8().constData(); }