Base: Quantity: return std::string

This commit is contained in:
Ladislav Michl
2024-07-13 13:07:27 +02:00
committed by Yorik van Havre
parent c11b37e312
commit 2ea8a633ac
58 changed files with 573 additions and 592 deletions

View File

@@ -719,10 +719,10 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
Base::Quantity asQuantity;
asQuantity.setValue(value);
asQuantity.setUnit(Base::Unit::Length);
QString qUserString = asQuantity.getUserString();
std::string userString = asQuantity.getUserString();
if (Base::UnitsApi::isMultiUnitLength() || (!hideUnits() && useSystemDecimals())) {
// just return the user string
return qUserString.toStdString();
return userString;
}
// find the unit of measure
@@ -734,26 +734,26 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
// get the numeric part of the user string
QRegularExpression rxNoUnits(
QString::fromUtf8("(.*) \\D*$")); // text before space + any non digits at end of string
QRegularExpressionMatch match = rxNoUnits.match(qUserString);
QRegularExpressionMatch match = rxNoUnits.match(QString::fromStdString(userString));
if (!match.hasMatch()) {
// no units in userString?
return qUserString.toStdString();
return userString;
}
QString matched = match.captured(1); // matched is the numeric part of user string
auto smatched = matched.toStdString();
int dpPos = matched.indexOf(QLocale().decimalPoint());
if (dpPos < 0) {
auto ret = matched.toStdString();
// no decimal separator (ie an integer), return all the digits
if (!hideUnits()) {
ret.append(unitPart.toStdString());
smatched.append(unitPart.toStdString());
}
return ret;
return smatched;
}
// real number
if (useSystemDecimals() && hideUnits()) {
// return just the numeric part of the user string
return matched.toStdString();
return smatched;
}
// real number and not using system decimals
@@ -779,7 +779,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
Base::Quantity asQuantity;
asQuantity.setValue(value);
asQuantity.setUnit(Base::Unit::Angle);
QString qUserString = asQuantity.getUserString();
QString qUserString = QString::fromStdString(asQuantity.getUserString());
if (Base::UnitsApi::isMultiUnitAngle()) {
// just return the user string
// Coin SbString doesn't handle utf8 well, so we convert to ascii
@@ -794,7 +794,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
// we always use use U+00B0 (°) as the unit of measure for angles in
// single unit schema. Will need a change to support rads or grads.
auto qUnitString = QString::fromUtf8("°");
std::string unitString = "°";
auto decimalSep = QLocale().decimalPoint();
// get the numeric part of the user string
@@ -806,18 +806,12 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
return qUserString.toStdString();
}
QString matched = match.captured(1); // matched is the numeric part of user string
auto smatched = matched.toStdString();
auto sUnitString = qUnitString.toStdString();
int dpPos = matched.indexOf(decimalSep);
if (dpPos < 0) {
// no decimal separator (ie an integer), return all the digits
return smatched + sUnitString;
}
// real number
if (useSystemDecimals()) {
// return just the numeric part of the user string + degree symbol
return smatched + sUnitString;
if (dpPos < 0 || useSystemDecimals()) {
// just the numeric part of the user string + degree symbol
auto angle = matched.toStdString();
angle.append(unitString);
return angle;
}
// real number and not using system decimals
@@ -827,7 +821,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
requiredLength = matched.size();
}
auto numericPart = matched.left(requiredLength).toStdString();
numericPart.append(sUnitString);
numericPart.append(unitString);
return numericPart;
}