diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 30ff00e003..ae0eaee0dc 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -512,7 +512,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) return DrawView::execute(); } -std::string DrawViewDimension::getFormatedValue() +std::string DrawViewDimension::getFormatedValue(int partial) { // Base::Console().Message("DVD::getFormatedValue()\n"); std::string result; @@ -522,7 +522,9 @@ std::string DrawViewDimension::getFormatedValue() QString specStr = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size()); double val = getDimValue(); - + QString specVal; + QString userUnits; + bool angularMeasure = false; Base::Quantity qVal; qVal.setValue(val); @@ -575,7 +577,7 @@ std::string DrawViewDimension::getFormatedValue() QLocale loc; double userValNum = loc.toDouble(userVal); - QString userUnits; +// QString userUnits; int pos = 0; if ((pos = rxUnits.indexIn(userStr, 0)) != -1) { userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString @@ -584,7 +586,8 @@ std::string DrawViewDimension::getFormatedValue() //find the %x.y tag in FormatSpec QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.*[0-9]*[aefgAEFG]")); //printf double format spec QString match; - QString specVal = userVal; //sensible default +// QString specVal = userVal; //sensible default + specVal = userVal; //sensible default pos = 0; if ((pos = rxFormat.indexIn(specStr, 0)) != -1) { match = rxFormat.cap(0); //entire capture of rx @@ -627,7 +630,26 @@ std::string DrawViewDimension::getFormatedValue() } } - return specStr.toUtf8().constData(); + //specVal - qstring with formatted numeric value + //userUnits - qstring with unit abbrev + //specStr - number + units + //partial = 0 --> the whole dimension string number + units )the "user string" + result = specStr.toUtf8().constData(); + if (partial == 1) { //just the number + result = Base::Tools::toStdString(specVal); + } else if (partial == 2) { //just the unit + if (showUnits()) { + if ((Type.isValue("Angle")) || (Type.isValue("Angle3Pt"))) { + QRegExp space(QString::fromUtf8("\\s")); + userUnits.remove(space); + } + result = Base::Tools::toStdString(userUnits); + } else { + result = ""; + } + } + + return result; } //!NOTE: this returns the Dimension value in internal units (ie mm)!!!! diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index 74e7345511..93716322b9 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -123,7 +123,7 @@ public: //return PyObject as DrawViewDimensionPy virtual PyObject *getPyObject(void); - virtual std::string getFormatedValue(); + virtual std::string getFormatedValue(int partial = 0); virtual double getDimValue(); DrawViewPart* getViewPart() const; virtual QRectF getRect() const { return QRectF(0,0,1,1);} //pretend dimensions always fit! diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp index a82cc1e164..b1409aecbb 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -96,6 +96,8 @@ QGIDatumLabel::QGIDatumLabel() m_dimText->setParentItem(this); m_tolText = new QGCustomText(); m_tolText->setParentItem(this); + m_unitText = new QGCustomText(); + m_unitText->setParentItem(this); m_ctrl = false; hasHover = false; @@ -210,11 +212,17 @@ void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCente { //set label's Qt position(top,left) given boundingRect center point setPos(xCenter - m_dimText->boundingRect().width() / 2., yCenter - m_dimText->boundingRect().height() / 2.); + //set tolerance position QRectF labelBox = m_dimText->boundingRect(); double right = labelBox.right(); double top = labelBox.top(); m_tolText->setPos(right,top); + + //set unit position + QRectF tolBox = m_tolText->boundingRect(); + right = right + tolBox.right(); + m_unitText->setPos(right,top); } void QGIDatumLabel::setLabelCenter() @@ -227,6 +235,7 @@ void QGIDatumLabel::setLabelCenter() void QGIDatumLabel::setFont(QFont f) { m_dimText->setFont(f); + m_unitText->setFont(f); QFont tFont(f); double fontSize = f.pixelSize(); double tolAdj = getTolAdjust(); @@ -265,8 +274,21 @@ void QGIDatumLabel::setTolString() double underTol = dim->UnderTolerance.getValue(); int precision = getPrecision(); - QString overFormat = QString::number(overTol,'f', precision); - QString underFormat = QString::number(underTol,'f',precision); + QString qsPrecision = QString::number(precision); + QString qsFormat = QString::fromUtf8("%+.") + //show sign + qsPrecision + + QString::fromUtf8("g"); //trim trailing zeroes + + QString overFormat; + QString underFormat; + #if QT_VERSION >= 0x050000 + overFormat = QString::asprintf(qsFormat.toStdString().c_str(), overTol); + underFormat = QString::asprintf(qsFormat.toStdString().c_str(), underTol); + #else + QString qs2; + overFormat = qs2.sprintf(qsFormat.toStdString().c_str(), overTol); + underFormat = qs2.sprintf(qsFormat.toStdString().c_str(), underTol); + #endif QString html = QString::fromUtf8("