Skip to content

Commit

Permalink
[TD] Refactor DrawViewDimension getFormatedValue() into two functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
aapo-aapo authored and wwmayer committed Dec 2, 2020
1 parent 60e1d7a commit c695b40
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/AppTechDrawPy.cpp
Expand Up @@ -639,7 +639,7 @@ class Module : public Py::ExtensionModule<Module>
double parentX = dvp->X.getValue() + grandParentX;
double parentY = dvp->Y.getValue() + grandParentY;
Base::Vector3d parentPos(parentX,parentY,0.0);
std::string sDimText = dvd->getFormatedValue();
std::string sDimText = dvd->getFormattedDimensionValue();
char* dimText = &sDimText[0u]; //hack for const-ness
float gap = 5.0; //hack. don't know font size here.
layerName = dvd->getNameInDocument();
Expand Down
22 changes: 14 additions & 8 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -530,23 +530,17 @@ bool DrawViewDimension::isMultiValueSchema(void) const
return result;
}

std::string DrawViewDimension::getFormatedValue(int partial)
std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int partial)
{
// Base::Console().Message("DVD::getFormatedValue(%d)\n", partial);
std::string result;
if (Arbitrary.getValue()) {
return FormatSpec.getStrValue();
}
bool multiValueSchema = false;

QString qFormatSpec = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
double val = getDimValue();
QString qUserStringUnits;
QString formattedValue;

bool angularMeasure = false;
Base::Quantity asQuantity;
asQuantity.setValue(val);
asQuantity.setValue(value);
if ( (Type.isValue("Angle")) ||
(Type.isValue("Angle3Pt")) ) {
angularMeasure = true;
Expand Down Expand Up @@ -686,8 +680,20 @@ std::string DrawViewDimension::getFormatedValue(int partial)
}

return result;

}

std::string DrawViewDimension::getFormattedDimensionValue(int partial)
{
// Base::Console().Message("DVD::getFormattedValue(%d)\n", partial);
QString qFormatSpec = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());

if (Arbitrary.getValue()) {
return FormatSpec.getStrValue();
}

return formatValue(getDimValue(), qFormatSpec, partial);
}

QStringList DrawViewDimension::getPrefixSuffixSpec(QString fSpec)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/App/DrawViewDimension.h
Expand Up @@ -133,7 +133,9 @@ class TechDrawExport DrawViewDimension : public TechDraw::DrawView
//return PyObject as DrawViewDimensionPy
virtual PyObject *getPyObject(void) override;

virtual std::string getFormatedValue(int partial = 0);
virtual std::string getFormattedDimensionValue(int partial = 0);
virtual std::string formatValue(qreal value, QString qFormatSpec, int partial = 0);

virtual double getDimValue();
QStringList getPrefixSuffixSpec(QString fSpec);

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/DrawViewDimensionPyImp.cpp
Expand Up @@ -61,7 +61,7 @@ PyObject* DrawViewDimensionPy::getText(PyObject* args)
// return 0;
// }
DrawViewDimension* dvd = getDrawViewDimensionPtr();
std::string textString = dvd->getFormatedValue();
std::string textString = dvd->getFormattedDimensionValue();
//TODO: check multiversion code!
#if PY_MAJOR_VERSION >= 3
PyObject* pyText = Base::PyAsUnicodeObject(textString);
Expand Down
12 changes: 6 additions & 6 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Expand Up @@ -352,7 +352,7 @@ void QGIDatumLabel::setTolString()
}
QString tolSuffix;
if ((dim->Type.isValue("Angle")) || (dim->Type.isValue("Angle3Pt"))) {
tolSuffix = QString::fromUtf8(dim->getFormatedValue(2).c_str()); //just the unit
tolSuffix = QString::fromUtf8(dim->getFormattedDimensionValue(2).c_str()); //just the unit
}

QString overFormat;
Expand Down Expand Up @@ -626,18 +626,18 @@ void QGIViewDimension::updateDim()
return;
}

// QString labelText = QString::fromUtf8(dim->getFormatedValue().c_str());
// QString labelText = QString::fromUtf8(dim->getFormattedDimensionValue().c_str());
//want this split into value and unit
QString labelText;
QString unitText;
if (dim->Arbitrary.getValue()) {
labelText = QString::fromUtf8(dim->getFormatedValue(1).c_str()); //just the number pref/spec/suf
labelText = QString::fromUtf8(dim->getFormattedDimensionValue(1).c_str()); //just the number pref/spec/suf
} else {
if (dim->isMultiValueSchema()) {
labelText = QString::fromUtf8(dim->getFormatedValue(0).c_str()); //don't format multis
labelText = QString::fromUtf8(dim->getFormattedDimensionValue(0).c_str()); //don't format multis
} 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
labelText = QString::fromUtf8(dim->getFormattedDimensionValue(1).c_str()); //just the number pref/spec/suf
unitText = QString::fromUtf8(dim->getFormattedDimensionValue(2).c_str()); //just the unit
}
}
QFont font = datumLabel->getFont();
Expand Down

0 comments on commit c695b40

Please sign in to comment.