Base: Drop QString-std::string conversion functions from Tools
Convenience helpers function Tools::toStdString and Tools::fromStdString were implemented for Qt4 or older to perform utf8 aware conversion as QString::toStdString/QString::fromStdString were using toAscii/fromAscii internally (see https://dreamswork.github.io/qt4/classQString.html). Since Qt5 QString uses toUtf8/fromUTf8, which makes the helper functions obsolete (see https://doc.qt.io/qt-5/qstring.html#fromStdString).
This commit is contained in:
committed by
Chris Hennes
parent
f9d1391588
commit
0ee3c9f8e6
@@ -31,7 +31,6 @@
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Gui/CommandT.h>
|
||||
#include <Gui/Document.h>
|
||||
@@ -723,7 +722,7 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
|
||||
QString qUserString = asQuantity.getUserString();
|
||||
if (Base::UnitsApi::isMultiUnitLength() || (!hideUnits() && useSystemDecimals())) {
|
||||
// just return the user string
|
||||
return Base::Tools::toStdString(qUserString);
|
||||
return qUserString.toStdString();
|
||||
}
|
||||
|
||||
// find the unit of measure
|
||||
@@ -738,24 +737,23 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
|
||||
QRegularExpressionMatch match = rxNoUnits.match(qUserString);
|
||||
if (!match.hasMatch()) {
|
||||
// no units in userString?
|
||||
return Base::Tools::toStdString(qUserString);
|
||||
return qUserString.toStdString();
|
||||
}
|
||||
QString matched = match.captured(1); // matched is the numeric part of user string
|
||||
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()) {
|
||||
return Base::Tools::toStdString(matched);
|
||||
}
|
||||
else {
|
||||
return Base::Tools::toStdString(matched + unitPart);
|
||||
if (!hideUnits()) {
|
||||
ret.append(unitPart.toStdString());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// real number
|
||||
if (useSystemDecimals() && hideUnits()) {
|
||||
// return just the numeric part of the user string
|
||||
return Base::Tools::toStdString(matched);
|
||||
return matched.toStdString();
|
||||
}
|
||||
|
||||
// real number and not using system decimals
|
||||
@@ -764,11 +762,11 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
|
||||
// just take the whole thing
|
||||
requiredLength = matched.size();
|
||||
}
|
||||
QString numericPart = matched.left(requiredLength);
|
||||
if (hideUnits()) {
|
||||
return Base::Tools::toStdString(numericPart);
|
||||
auto numericPart = matched.left(requiredLength).toStdString();
|
||||
if (!hideUnits()) {
|
||||
numericPart.append(unitPart.toStdString());
|
||||
}
|
||||
return Base::Tools::toStdString(numericPart + unitPart);
|
||||
return numericPart;
|
||||
}
|
||||
|
||||
// convert value to display format %0.[digits]f. Units are always displayed for
|
||||
@@ -791,7 +789,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
|
||||
QString escapeSecond = QString::fromLatin1("\""); // substitute ascii double quote
|
||||
QString displayString = qUserString.replace(schemeMinute, escapeMinute);
|
||||
displayString = displayString.replace(schemeSecond, escapeSecond);
|
||||
return Base::Tools::toStdString(displayString);
|
||||
return displayString.toStdString();
|
||||
}
|
||||
|
||||
// we always use use U+00B0 (°) as the unit of measure for angles in
|
||||
@@ -805,19 +803,21 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
|
||||
QRegularExpressionMatch match = rxNoUnits.match(qUserString);
|
||||
if (!match.hasMatch()) {
|
||||
// no units in userString?
|
||||
return Base::Tools::toStdString(qUserString);
|
||||
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 Base::Tools::toStdString(matched + qUnitString);
|
||||
return smatched + sUnitString;
|
||||
}
|
||||
|
||||
// real number
|
||||
if (useSystemDecimals()) {
|
||||
// return just the numeric part of the user string + degree symbol
|
||||
return Base::Tools::toStdString(matched + qUnitString);
|
||||
return smatched + sUnitString;
|
||||
}
|
||||
|
||||
// real number and not using system decimals
|
||||
@@ -826,8 +826,9 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits)
|
||||
// just take the whole thing
|
||||
requiredLength = matched.size();
|
||||
}
|
||||
QString numericPart = matched.left(requiredLength);
|
||||
return Base::Tools::toStdString(numericPart + qUnitString);
|
||||
auto numericPart = matched.left(requiredLength).toStdString();
|
||||
numericPart.append(sUnitString);
|
||||
return numericPart;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user