Merge pull request #25853 from 3x380V/reimplement_24749
TechDraw: Fix dimension formatter
This commit is contained in:
@@ -66,11 +66,6 @@ std::string UnitsApi::getBasicLengthUnit()
|
||||
return schemas->currentSchema()->getBasicLengthUnit();
|
||||
}
|
||||
|
||||
std::string UnitsApi::getUnitText(const Quantity& quant)
|
||||
{
|
||||
return schemas->currentSchema()->getUnitText(quant);
|
||||
}
|
||||
|
||||
void UnitsApi::setDecimals(const int prec)
|
||||
{
|
||||
decimals = prec;
|
||||
|
||||
@@ -67,7 +67,6 @@ public:
|
||||
static bool isMultiUnitAngle();
|
||||
static bool isMultiUnitLength();
|
||||
static std::string getBasicLengthUnit();
|
||||
static std::string getUnitText(const Quantity& quant);
|
||||
|
||||
static std::size_t getDefSchemaNum()
|
||||
{
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "Exception.h"
|
||||
#include "Quantity.h"
|
||||
|
||||
#include "Console.h"
|
||||
|
||||
using Base::UnitsSchema;
|
||||
using Base::UnitsSchemaSpec;
|
||||
|
||||
@@ -145,34 +143,3 @@ int UnitsSchema::getNum() const
|
||||
{
|
||||
return static_cast<int>(spec.num);
|
||||
}
|
||||
|
||||
|
||||
//! return the unit text for this quantity in this schema. ex 10 mm => "mm"
|
||||
//! a more general approach than getBasicLengthUnit.
|
||||
//! TODO: some common code here with translate()
|
||||
std::string UnitsSchema::getUnitText(const Base::Quantity& quant) const
|
||||
{
|
||||
std::string typeString = quant.getUnit().getTypeString(); // "Area", "Mass", ...
|
||||
const auto value = quant.getValue();
|
||||
|
||||
// TODO: some common code here with translate()
|
||||
if (!spec.translationSpecs.contains(typeString)) {
|
||||
Base::Console().log("Schema %s has no entry for %s\n", getName().c_str(), typeString.c_str());
|
||||
return {};
|
||||
}
|
||||
auto unitSpecs = spec.translationSpecs.at(typeString);
|
||||
|
||||
auto isSuitable = [&](const UnitTranslationSpec& row) {
|
||||
return row.threshold > value || row.threshold == 0;
|
||||
};
|
||||
|
||||
const auto unitSpec = std::ranges::find_if(unitSpecs, isSuitable);
|
||||
if (unitSpec == unitSpecs.end()) {
|
||||
throw RuntimeError(
|
||||
"Suitable threshold not found (2). Schema: " + spec.name
|
||||
+ " value: " + std::to_string(value)
|
||||
);
|
||||
}
|
||||
|
||||
return unitSpec->unitString;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ public:
|
||||
[[nodiscard]] std::string getName() const;
|
||||
[[nodiscard]] std::string getDescription() const;
|
||||
[[nodiscard]] int getNum() const;
|
||||
[[nodiscard]] std::string getUnitText(const Quantity& quant) const;
|
||||
|
||||
std::string translate(const Quantity& quant) const;
|
||||
std::string translate(const Quantity& quant, double& factor, std::string& unitString) const;
|
||||
|
||||
@@ -51,7 +51,7 @@ std::string DimensionFormatter::formatValue(const qreal value,
|
||||
const Format partial,
|
||||
const bool isDim) const
|
||||
{
|
||||
bool distanceMeasure{true};
|
||||
bool distanceMeasure{true};
|
||||
const bool angularMeasure =
|
||||
m_dimension->Type.isValue("Angle") || m_dimension->Type.isValue("Angle3Pt");
|
||||
const bool areaMeasure = m_dimension->Type.isValue("Area");
|
||||
@@ -77,7 +77,7 @@ std::string DimensionFormatter::formatValue(const qreal value,
|
||||
// won't give more than Global_Decimals precision
|
||||
std::string basicString = formatPrefix + asQuantity.getUserString() + formatSuffix;
|
||||
|
||||
if (isMultiValueSchema() && partial == Format::UNALTERED) {
|
||||
if (isMultiValueSchema() || partial == Format::UNALTERED) {
|
||||
return basicString; // Don't even try to use Alt Decimals or hide units
|
||||
}
|
||||
|
||||
@@ -101,7 +101,9 @@ std::string DimensionFormatter::formatValue(const qreal value,
|
||||
formatSpecifier.replace(QStringLiteral("%g"), newSpecifier, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
std::string unitText = Base::UnitsApi::getUnitText(asQuantity);
|
||||
double factor{1.0};
|
||||
std::string unitText{""};
|
||||
asQuantity.getUserString(factor, unitText);
|
||||
std::string super2{"²"};
|
||||
std::string squareTag{"^2"};
|
||||
|
||||
@@ -118,8 +120,7 @@ std::string DimensionFormatter::formatValue(const qreal value,
|
||||
double userVal = asQuantity.getValue();
|
||||
|
||||
if (distanceMeasure || areaMeasure) {
|
||||
const double convertValue = Base::Quantity::parse("1" + unitText).getValue();
|
||||
userVal /= convertValue;
|
||||
userVal /= factor;
|
||||
}
|
||||
|
||||
// convert ^2 to superscript 2 for display
|
||||
|
||||
@@ -273,22 +273,15 @@ void QGIViewDimension::updateDim()
|
||||
return;
|
||||
}
|
||||
|
||||
QString labelText =
|
||||
// what about fromStdString?
|
||||
QString::fromUtf8(dim->getFormattedDimensionValue(Format::FORMATTED).c_str());// pre value [unit] post
|
||||
if (dim->isMultiValueSchema()) {
|
||||
labelText =
|
||||
QString::fromUtf8(dim->getFormattedDimensionValue(Format::UNALTERED).c_str());//don't format multis
|
||||
}
|
||||
|
||||
QFont font = datumLabel->getFont();
|
||||
auto labelText = dim->getFormattedDimensionValue(Format::FORMATTED);
|
||||
auto font = datumLabel->getFont();
|
||||
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
|
||||
int fontSize = QGIView::exactFontSize(vp->Font.getValue(), std::max(1.0, vp->Fontsize.getValue()));
|
||||
font.setPixelSize(fontSize);
|
||||
datumLabel->setFont(font);
|
||||
|
||||
prepareGeometryChange();
|
||||
datumLabel->setDimString(labelText);
|
||||
datumLabel->setDimString(QString::fromStdString(labelText));
|
||||
datumLabel->setToleranceString();
|
||||
|
||||
datumLabel->setFramed(dim->TheoreticalExact.getValue());
|
||||
|
||||
Reference in New Issue
Block a user