Base: Quantity: return std::string
This commit is contained in:
committed by
Yorik van Havre
parent
c11b37e312
commit
2ea8a633ac
@@ -765,8 +765,8 @@ PyObject* SketchObjectPy::setDatum(PyObject* args)
|
||||
str << "Cannot set the datum because the sketch contains conflicting constraints";
|
||||
}
|
||||
else if (err == -2) {
|
||||
str << "Datum " << (const char*)Quantity.getUserString().toUtf8()
|
||||
<< " for the constraint with index " << Index << " is invalid";
|
||||
str << "Datum " << Quantity.getUserString() << " for the constraint with index "
|
||||
<< Index << " is invalid";
|
||||
}
|
||||
else if (err == -4) {
|
||||
str << "Negative datum values are not valid for the constraint with index " << Index;
|
||||
@@ -778,8 +778,7 @@ PyObject* SketchObjectPy::setDatum(PyObject* args)
|
||||
str << "Cannot set the datum because of invalid geometry";
|
||||
}
|
||||
else {
|
||||
str << "Unexpected problem at setting datum "
|
||||
<< (const char*)Quantity.getUserString().toUtf8()
|
||||
str << "Unexpected problem at setting datum " << Quantity.getUserString()
|
||||
<< " for the constraint with index " << Index;
|
||||
}
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
|
||||
@@ -2095,11 +2095,10 @@ void EditModeConstraintCoinManager::rebuildConstraintNodes(
|
||||
|
||||
QString EditModeConstraintCoinManager::getPresentationString(const Constraint* constraint)
|
||||
{
|
||||
QString nameStr; // name parameter string
|
||||
std::string nameStr; // name parameter string
|
||||
QString valueStr; // dimensional value string
|
||||
QString presentationStr; // final return string
|
||||
QString unitStr; // the actual unit string
|
||||
QString baseUnitStr; // the expected base unit string
|
||||
std::string unitStr; // the actual unit string
|
||||
std::string baseUnitStr; // the expected base unit string
|
||||
double factor; // unit scaling factor, currently not used
|
||||
Base::UnitSystem unitSys; // current unit system
|
||||
|
||||
@@ -2108,10 +2107,11 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint* c
|
||||
}
|
||||
|
||||
// Get the current name parameter string of the constraint
|
||||
nameStr = QString::fromStdString(constraint->Name);
|
||||
nameStr = constraint->Name;
|
||||
|
||||
// Get the current value string including units
|
||||
valueStr = constraint->getPresentationValue().getUserString(factor, unitStr);
|
||||
valueStr =
|
||||
QString::fromStdString(constraint->getPresentationValue().getUserString(factor, unitStr));
|
||||
|
||||
// Hide units if user has requested it, is being displayed in the base
|
||||
// units, and the schema being used has a clear base unit in the first
|
||||
@@ -2127,19 +2127,19 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint* c
|
||||
switch (unitSys) {
|
||||
case Base::UnitSystem::SI1:
|
||||
case Base::UnitSystem::MmMin:
|
||||
baseUnitStr = QString::fromLatin1("mm");
|
||||
baseUnitStr = "mm";
|
||||
break;
|
||||
|
||||
case Base::UnitSystem::SI2:
|
||||
baseUnitStr = QString::fromLatin1("m");
|
||||
baseUnitStr = "m";
|
||||
break;
|
||||
|
||||
case Base::UnitSystem::ImperialDecimal:
|
||||
baseUnitStr = QString::fromLatin1("in");
|
||||
baseUnitStr = "in";
|
||||
break;
|
||||
|
||||
case Base::UnitSystem::Centimeters:
|
||||
baseUnitStr = QString::fromLatin1("cm");
|
||||
baseUnitStr = "cm";
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2147,9 +2147,9 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint* c
|
||||
break;
|
||||
}
|
||||
|
||||
if (!baseUnitStr.isEmpty()) {
|
||||
if (!baseUnitStr.empty()) {
|
||||
// expected unit string matches actual unit string. remove.
|
||||
if (QString::compare(baseUnitStr, unitStr) == 0) {
|
||||
if (baseUnitStr.compare(unitStr) == 0) {
|
||||
// Example code from: Mod/TechDraw/App/DrawViewDimension.cpp:372
|
||||
QRegularExpression rxUnits(
|
||||
QString::fromUtf8(" \\D*$")); // space + any non digits at end of string
|
||||
@@ -2171,17 +2171,19 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint* c
|
||||
%N - the constraint name parameter
|
||||
%V - the value of the dimensional constraint, including any unit characters
|
||||
*/
|
||||
if (constraintParameters.bShowDimensionalName && !nameStr.isEmpty()) {
|
||||
if (constraintParameters.bShowDimensionalName && !nameStr.empty()) {
|
||||
QString presentationStr;
|
||||
if (constraintParameters.sDimensionalStringFormat.contains(QLatin1String("%V"))
|
||||
|| constraintParameters.sDimensionalStringFormat.contains(QLatin1String("%N"))) {
|
||||
presentationStr = constraintParameters.sDimensionalStringFormat;
|
||||
presentationStr.replace(QLatin1String("%N"), nameStr);
|
||||
presentationStr.replace(QLatin1String("%N"), QString::fromStdString(nameStr));
|
||||
presentationStr.replace(QLatin1String("%V"), valueStr);
|
||||
}
|
||||
else {
|
||||
// user defined format string does not contain any valid parameter, using default format
|
||||
// "%N = %V"
|
||||
presentationStr = nameStr + QLatin1String(" = ") + valueStr;
|
||||
presentationStr =
|
||||
QString::fromStdString(nameStr) + QString::fromLatin1(" = ") + valueStr;
|
||||
}
|
||||
|
||||
return presentationStr;
|
||||
|
||||
@@ -50,8 +50,7 @@ PropertyConstraintListItem::~PropertyConstraintListItem()
|
||||
QVariant PropertyConstraintListItem::toString(const QVariant& prop) const
|
||||
{
|
||||
const QList<Base::Quantity>& value = prop.value<QList<Base::Quantity>>();
|
||||
QString str;
|
||||
QTextStream out(&str);
|
||||
std::stringstream out;
|
||||
out << "[";
|
||||
for (QList<Base::Quantity>::const_iterator it = value.begin(); it != value.end(); ++it) {
|
||||
if (it != value.begin()) {
|
||||
@@ -60,7 +59,7 @@ QVariant PropertyConstraintListItem::toString(const QVariant& prop) const
|
||||
out << it->getUserString();
|
||||
}
|
||||
out << "]";
|
||||
return QVariant(str);
|
||||
return QVariant(QString::fromStdString(out.str()));
|
||||
}
|
||||
|
||||
void PropertyConstraintListItem::initialize()
|
||||
|
||||
@@ -158,7 +158,8 @@ public:
|
||||
case Sketcher::Diameter:
|
||||
case Sketcher::Angle:
|
||||
name = QString::fromLatin1("%1 (%2)").arg(
|
||||
name, constraint->getPresentationValue().getUserString());
|
||||
name,
|
||||
QString::fromStdString(constraint->getPresentationValue().getUserString()));
|
||||
break;
|
||||
case Sketcher::SnellsLaw: {
|
||||
double v = constraint->getPresentationValue().getValue();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -158,8 +158,7 @@ void ViewProviderSketch::ParameterObserver::updateGridSize(const std::string& st
|
||||
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");
|
||||
|
||||
Client.GridSize.setValue(
|
||||
Base::Quantity::parse(
|
||||
QString::fromLatin1(hGrp->GetGroup("GridSize")->GetASCII("GridSize", "10.0").c_str()))
|
||||
Base::Quantity::parse(hGrp->GetGroup("GridSize")->GetASCII("GridSize", "10.0"))
|
||||
.getValue());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user