Skip to content

Commit

Permalink
[TD]Fix Dimension prefix/suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Oct 20, 2019
1 parent 3500451 commit 5021f37
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
33 changes: 22 additions & 11 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -521,6 +521,9 @@ std::string DrawViewDimension::getFormatedValue(int partial)
}

QString specStr = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
QString specStrCopy = specStr;
QString formatPrefix;
QString formatSuffix;
double val = getDimValue();
QString specVal;
QString userUnits;
Expand All @@ -536,11 +539,11 @@ std::string DrawViewDimension::getFormatedValue(int partial)
qVal.setUnit(Base::Unit::Length);
}

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!!
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!!

//units api: get schema to figure out if this is multi-value schema(Imperial1, ImperialBuilding, etc)
//if it is multi-unit schema, don't even try to use Alt Decimals or format per format spec
Expand Down Expand Up @@ -569,18 +572,18 @@ std::string DrawViewDimension::getFormatedValue(int partial)
}
} else {
//handle single value schemes
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + 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
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units

QLocale loc;
double userValNum = loc.toDouble(userVal);

// QString userUnits;
int pos = 0;
if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}

//find the %x.y tag in FormatSpec
Expand All @@ -597,8 +600,11 @@ std::string DrawViewDimension::getFormatedValue(int partial)
QString qs2;
specVal = qs2.sprintf(Base::Tools::toStdString(match).c_str(),userValNum);
#endif
formatPrefix = specStrCopy.left(pos);
formatSuffix = specStrCopy.right(specStrCopy.size() - pos - match.size());
} else { //printf format not found!
Base::Console().Warning("Warning - no numeric format in formatSpec - %s\n",getNameInDocument());
Base::Console().Warning("Warning - no numeric format in formatSpec %s - %s\n",
qPrintable(specStr), getNameInDocument());
return Base::Tools::toStdString(specStr);
}

Expand Down Expand Up @@ -634,9 +640,14 @@ std::string DrawViewDimension::getFormatedValue(int partial)
//userUnits - qstring with unit abbrev
//specStr - number + units
//partial = 0 --> the whole dimension string number + units )the "user string"
std::string ssPrefix = Base::Tools::toStdString(formatPrefix);
std::string ssSuffix = Base::Tools::toStdString(formatSuffix);
result = specStr.toUtf8().constData();
if (partial == 1) { //just the number
result = Base::Tools::toStdString(specVal);
if (partial == 1) { //just the number (+prefix & suffix)
// result = Base::Tools::toStdString(specVal);
result = ssPrefix +
Base::Tools::toStdString(specVal) +
ssSuffix;
} else if (partial == 2) { //just the unit
if (showUnits()) {
if ((Type.isValue("Angle")) || (Type.isValue("Angle3Pt"))) {
Expand Down
26 changes: 14 additions & 12 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Expand Up @@ -538,31 +538,33 @@ void QGIViewDimension::updateDim()
if ( vp == nullptr ) {
return;
}

// QString labelText = QString::fromUtf8(dim->getFormatedValue().c_str());
//want this split into value and unit
QString labelText = QString::fromUtf8(dim->getFormatedValue(1).c_str()); //just the number
QString unitText = QString::fromUtf8(dim->getFormatedValue(2).c_str()); //just the unit
QString arbText = QString::fromUtf8(dim->FormatSpec.getValue());

QString labelText;
QString unitText;
if (dim->Arbitrary.getValue()) {
labelText = QString::fromUtf8(dim->getFormatedValue(1).c_str()); //just the number pref/spec/suf
} else {
labelText = QString::fromUtf8(dim->getFormatedValue(1).c_str()); //just the number pref/spec/suf
unitText = QString::fromUtf8(dim->getFormatedValue(2).c_str()); //just the unit
}

QFont font = datumLabel->getFont();
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
datumLabel->setFont(font);

prepareGeometryChange();
if (dim->Arbitrary.getValue()) {
datumLabel->setDimString(arbText);
} else {
datumLabel->setDimString(labelText);
datumLabel->setTolString();
datumLabel->setUnitString(unitText);
}
datumLabel->setDimString(labelText);
datumLabel->setTolString();
datumLabel->setUnitString(unitText);
datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());

datumLabel->setFramed(dim->TheoreticalExact.getValue());
datumLabel->setLineWidth(m_lineWidth);
}

//this is for formatting and finding centers, not display
QString QGIViewDimension::getLabelText(void)
{
Expand Down

0 comments on commit 5021f37

Please sign in to comment.