[TD]Improve tolerance formatting
This commit is contained in:
@@ -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)!!!!
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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("<div>%1 <br/>%2 </div>");
|
||||
html = html.arg(overFormat).arg(underFormat);
|
||||
@@ -275,6 +297,13 @@ void QGIDatumLabel::setTolString()
|
||||
return;
|
||||
}
|
||||
|
||||
void QGIDatumLabel::setUnitString(QString t)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_unitText->setPlainText(t);
|
||||
}
|
||||
|
||||
|
||||
int QGIDatumLabel::getPrecision(void)
|
||||
{
|
||||
int precision;
|
||||
@@ -304,18 +333,21 @@ void QGIDatumLabel::setPrettySel(void)
|
||||
{
|
||||
m_dimText->setPrettySel();
|
||||
m_tolText->setPrettySel();
|
||||
m_unitText->setPrettySel();
|
||||
}
|
||||
|
||||
void QGIDatumLabel::setPrettyPre(void)
|
||||
{
|
||||
m_dimText->setPrettyPre();
|
||||
m_tolText->setPrettyPre();
|
||||
m_unitText->setPrettyPre();
|
||||
}
|
||||
|
||||
void QGIDatumLabel::setPrettyNormal(void)
|
||||
{
|
||||
m_dimText->setPrettyNormal();
|
||||
m_tolText->setPrettyNormal();
|
||||
m_unitText->setPrettyNormal();
|
||||
}
|
||||
|
||||
void QGIDatumLabel::setColor(QColor c)
|
||||
@@ -323,6 +355,7 @@ void QGIDatumLabel::setColor(QColor c)
|
||||
m_colNormal = c;
|
||||
m_dimText->setColor(m_colNormal);
|
||||
m_tolText->setColor(m_colNormal);
|
||||
m_unitText->setColor(m_colNormal);
|
||||
}
|
||||
|
||||
//**************************************************************
|
||||
@@ -506,7 +539,10 @@ void QGIViewDimension::updateDim()
|
||||
return;
|
||||
}
|
||||
|
||||
QString labelText = QString::fromUtf8(dim->getFormatedValue().c_str());
|
||||
// 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
|
||||
|
||||
QFont font = datumLabel->getFont();
|
||||
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
|
||||
@@ -516,6 +552,7 @@ void QGIViewDimension::updateDim()
|
||||
prepareGeometryChange();
|
||||
datumLabel->setDimString(labelText);
|
||||
datumLabel->setTolString();
|
||||
datumLabel->setUnitString(unitText);
|
||||
datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());
|
||||
|
||||
datumLabel->setFramed(dim->TheoreticalExact.getValue());
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
QFont getFont(void) { return m_dimText->font(); }
|
||||
void setDimString(QString t);
|
||||
void setDimString(QString t, qreal maxWidth);
|
||||
void setUnitString(QString t);
|
||||
void setTolString();
|
||||
void setPrettySel(void);
|
||||
void setPrettyPre(void);
|
||||
@@ -115,6 +116,7 @@ protected:
|
||||
|
||||
QGCustomText* m_dimText;
|
||||
QGCustomText* m_tolText;
|
||||
QGCustomText* m_unitText;
|
||||
int getPrecision(void);
|
||||
QColor m_colNormal;
|
||||
bool m_ctrl;
|
||||
|
||||
Reference in New Issue
Block a user