Skip to content

Commit

Permalink
Move dimText Prefix to FormatSpec
Browse files Browse the repository at this point in the history
- prefix was applied at every request for
  formatted value. Now prefix is applied
  to FormatSpec and can be overridden for
  things like screw dia. M6 vs (phi)M6.
  • Loading branch information
WandererFan authored and yorikvanhavre committed Oct 2, 2018
1 parent d2c2b35 commit f5668c7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -96,7 +96,7 @@ DrawViewDimension::DrawViewDimension(void)
References3D.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(FormatSpec,(getDefaultFormatSpec().c_str()) ,
"Format",(App::PropertyType)(App::Prop_None),"Dimension Format");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format",(App::PropertyType)(App::Prop_None),"Value specified by user");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format",(App::PropertyType)(App::Prop_None),"Value overridden by user");

Type.setEnums(TypeEnums); //dimension type: length, radius etc
ADD_PROPERTY(Type,((long)0));
Expand Down Expand Up @@ -172,9 +172,13 @@ void DrawViewDimension::onChanged(const App::Property* prop)
}
}

DrawView::onChanged(prop);
}

if (prop == &Type) {
FormatSpec.setValue(getDefaultFormatSpec().c_str()); //restore a FormatSpec for this type(dim,rad,etc)
}

DrawView::onChanged(prop);
}

void DrawViewDimension::onDocumentRestored()
Expand Down Expand Up @@ -448,8 +452,6 @@ std::string DrawViewDimension::getFormatedValue(bool obtuse)
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}

std::string prefixSym = getPrefix(); //get Radius/Diameter/... symbol

//find the %x.y tag in FormatSpec
QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.*[0-9]*[aefgAEFG]")); //printf double format spec
QString match;
Expand Down Expand Up @@ -480,7 +482,6 @@ std::string DrawViewDimension::getFormatedValue(bool obtuse)
}
}

repl = Base::Tools::fromStdString(getPrefix()) + repl;
specStr.replace(match,repl);
//this next bit is so inelegant!!!
QChar dp = QChar::fromLatin1('.');
Expand Down Expand Up @@ -916,7 +917,14 @@ std::string DrawViewDimension::getDefaultFormatSpec() const
precision = hGrp->GetInt("AltDecimals", 2);
}
QString formatPrecision = QString::number(precision);
QString formatSpec = format1 + formatPrecision + format2;

std::string prefix = getPrefix();
QString qPrefix;
if (!prefix.empty()) {
qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
}

QString formatSpec = qPrefix + format1 + formatPrecision + format2;
return Base::Tools::toStdString(formatSpec);
}

Expand Down

0 comments on commit f5668c7

Please sign in to comment.