From 3370d0902acd638e8627fc3a1955aad3d392f73e Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 22 Mar 2019 11:53:58 -0400 Subject: [PATCH] Add Preference for Dimension Format --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 46 ++++++----- src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui | 77 ++++++++++++++++--- src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp | 2 + 3 files changed, 94 insertions(+), 31 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 6586fdf2ce..7153801895 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -427,9 +427,8 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) } //TODO: if MeasureType = Projected and the Projected shape changes, the Dimension may become invalid (see tilted Cube example) - requestPaint(); - return App::DocumentObject::execute(); + return DrawView::execute(); } std::string DrawViewDimension::getFormatedValue(bool obtuse) @@ -502,13 +501,15 @@ std::string DrawViewDimension::getFormatedValue(bool obtuse) pos = 0; if ((pos = rxFormat.indexIn(specStr, 0)) != -1) { match = rxFormat.cap(0); //entire capture of rx - #if QT_VERSION >= 0x050000 specVal = QString::asprintf(Base::Tools::toStdString(match).c_str(),userValNum); #else QString qs2; specVal = qs2.sprintf(Base::Tools::toStdString(match).c_str(),userValNum); #endif + } else { //printf format not found! + Base::Console().Warning("Warning - no numeric format in formatSpec - %s\n",getNameInDocument()); + return Base::Tools::toStdString(specStr); } QString repl = userVal; @@ -978,23 +979,30 @@ std::string DrawViewDimension::getDefaultFormatSpec() const { Base::Reference hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); - QString format1 = Base::Tools::fromStdString("%."); - QString format2 = Base::Tools::fromStdString("f"); - int precision; - if (useDecimals()) { - precision = Base::UnitsApi::getDecimals(); - } else { - precision = hGrp->GetInt("AltDecimals", 2); - } - QString formatPrecision = QString::number(precision); - - std::string prefix = getPrefix(); - QString qPrefix; - if (!prefix.empty()) { - qPrefix = QString::fromUtf8(prefix.data(),prefix.size()); - } + std::string prefFormat = hGrp->GetASCII("formatSpec",""); + QString formatSpec; + if (prefFormat.empty()) { + QString format1 = Base::Tools::fromStdString("%."); + QString format2 = Base::Tools::fromStdString("f"); + int precision; + if (useDecimals()) { + precision = Base::UnitsApi::getDecimals(); + } else { + precision = hGrp->GetInt("AltDecimals", 2); + } + QString formatPrecision = QString::number(precision); - QString formatSpec = qPrefix + format1 + formatPrecision + format2; + std::string prefix = getPrefix(); + QString qPrefix; + if (!prefix.empty()) { + qPrefix = QString::fromUtf8(prefix.data(),prefix.size()); + } + + formatSpec = qPrefix + format1 + formatPrecision + format2; + } else { + return prefFormat; + } + return Base::Tools::toStdString(formatSpec); } diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui index 19ff21ce83..ce28bd9d58 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui @@ -7,7 +7,7 @@ 0 0 521 - 732 + 771 @@ -24,6 +24,9 @@ + + Append unit to Dimension text + Show Units @@ -35,15 +38,18 @@ - + Color - + + + Dimension text color + 0 @@ -59,14 +65,14 @@ - + Font Size - + Qt::Horizontal @@ -86,27 +92,30 @@ - + Arrow Size - + Diameter Symbol - + 12 + + Character to use to indicate Diameter dimension + @@ -123,6 +132,9 @@ + + Use system setting for decimal places. + Use Global Decimals @@ -137,7 +149,7 @@ - + Preferred arrowhead style @@ -206,7 +218,7 @@ - + Arrow Style @@ -215,6 +227,9 @@ + + Number of decimal places if not using Global Decimals + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -229,7 +244,7 @@ - + Dimension font size in units @@ -245,7 +260,7 @@ - + Dimension arrowhead size in units @@ -261,6 +276,26 @@ + + + + Default Format + + + + + + + Custom format for Dimension text + + + formatSpec + + + /Mod/TechDraw/Dimensions + + + @@ -276,6 +311,9 @@ + + Color for centerlines + 175 @@ -316,6 +354,9 @@ + + Round or Square outline in Detail view + MattingStyle @@ -357,6 +398,9 @@ + + Line type for centerlines + 2 @@ -457,6 +501,9 @@ + + Line color for sectionlines + 175 @@ -494,6 +541,9 @@ + + Name of entry in LineGroup CSV file + FC 0.70mm @@ -514,6 +564,9 @@ + + Vertex display color + 150 diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp index 4985f8272e..751b4436a7 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp @@ -57,6 +57,7 @@ void DlgPrefsTechDraw2Imp::saveSettings() pcbArrow->onSave(); cbGlobalDecimals->onSave(); sbAltDecimals->onSave(); + leformatSpec->onSave(); plsb_ArrowSize->onSave(); leLineGroup->onSave(); pdsb_VertexScale->onSave(); @@ -77,6 +78,7 @@ void DlgPrefsTechDraw2Imp::loadSettings() pcbArrow->onRestore(); cbGlobalDecimals->onRestore(); sbAltDecimals->onRestore(); + leformatSpec->onRestore(); plsb_ArrowSize->onRestore(); leLineGroup->onRestore(); pdsb_VertexScale->onRestore();