Materials: Change display of Quantity values
The default display type of quantity objects is fixed point resulting in insufficient accuracy when changing unit systems, or when the values are small. This fix changes the default format from 'Fixed' to the more apt 'Default' format. This allows the displayed values to scale as appropriate. Fixes #18149
This commit is contained in:
committed by
Chris Hennes
parent
939506007d
commit
7e1b1abddd
@@ -117,6 +117,7 @@ std::shared_ptr<Material2DArray> MaterialYamlEntry::read2DArray(const YAML::Node
|
||||
for (std::size_t j = 0; j < yamlRow.size(); j++) {
|
||||
Base::Quantity qq =
|
||||
Base::Quantity::parse(QString::fromStdString(yamlRow[j].as<std::string>()));
|
||||
qq.setFormat(MaterialValue::getQuantityFormat());
|
||||
row->push_back(QVariant::fromValue(qq));
|
||||
}
|
||||
array2d->addRow(row);
|
||||
@@ -143,6 +144,7 @@ std::shared_ptr<Material3DArray> MaterialYamlEntry::read3DArray(const YAML::Node
|
||||
for (auto it = yamlDepth.begin(); it != yamlDepth.end(); it++) {
|
||||
auto depthValue =
|
||||
Base::Quantity::parse(QString::fromStdString(it->first.as<std::string>()));
|
||||
depthValue.setFormat(MaterialValue::getQuantityFormat());
|
||||
|
||||
array3d->addDepth(depth, depthValue);
|
||||
|
||||
@@ -152,8 +154,10 @@ std::shared_ptr<Material3DArray> MaterialYamlEntry::read3DArray(const YAML::Node
|
||||
|
||||
auto row = std::make_shared<QList<Base::Quantity>>();
|
||||
for (std::size_t j = 0; j < yamlRow.size(); j++) {
|
||||
row->push_back(Base::Quantity::parse(
|
||||
QString::fromStdString(yamlRow[j].as<std::string>())));
|
||||
auto qq = Base::Quantity::parse(
|
||||
QString::fromStdString(yamlRow[j].as<std::string>()));
|
||||
qq.setFormat(MaterialValue::getQuantityFormat());
|
||||
row->push_back(qq);
|
||||
}
|
||||
array3d->addRow(depth, row);
|
||||
}
|
||||
|
||||
@@ -311,6 +311,11 @@ QString MaterialValue::getYAMLString() const
|
||||
return yaml;
|
||||
}
|
||||
|
||||
const Base::QuantityFormat MaterialValue::getQuantityFormat()
|
||||
{
|
||||
return Base::QuantityFormat(Base::QuantityFormat::NumberFormat::Default, PRECISION);
|
||||
}
|
||||
|
||||
//===
|
||||
|
||||
TYPESYSTEM_SOURCE(Materials::Material2DArray, Materials::MaterialValue)
|
||||
|
||||
@@ -107,6 +107,11 @@ public:
|
||||
static QString escapeString(const QString& source);
|
||||
static ValueType mapType(const QString& stringType);
|
||||
|
||||
static const Base::QuantityFormat getQuantityFormat();
|
||||
|
||||
// The precision is based on the value from the original materials editor
|
||||
static const int PRECISION = 6;
|
||||
|
||||
protected:
|
||||
MaterialValue(ValueType type, ValueType inherited);
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@ using namespace Materials;
|
||||
|
||||
TYPESYSTEM_SOURCE(Materials::MaterialProperty, Materials::ModelProperty)
|
||||
|
||||
int const MaterialProperty::PRECISION = 6;
|
||||
|
||||
MaterialProperty::MaterialProperty()
|
||||
{
|
||||
_valuePtr = std::make_shared<MaterialValue>(MaterialValue::None);
|
||||
@@ -134,7 +132,7 @@ QString MaterialProperty::getString() const
|
||||
if (value.isNull()) {
|
||||
return {};
|
||||
}
|
||||
return QString(QLatin1String("%L1")).arg(value.toFloat(), 0, 'g', PRECISION);
|
||||
return QString(QLatin1String("%L1")).arg(value.toFloat(), 0, 'g', MaterialValue::PRECISION);
|
||||
}
|
||||
return getValue().toString();
|
||||
}
|
||||
@@ -180,7 +178,7 @@ QString MaterialProperty::getDictionaryString() const
|
||||
if (getType() == MaterialValue::Quantity) {
|
||||
auto quantity = getValue().value<Base::Quantity>();
|
||||
auto string = QString(QLatin1String("%1 %2"))
|
||||
.arg(quantity.getValue(), 0, 'g', PRECISION)
|
||||
.arg(quantity.getValue(), 0, 'g', MaterialValue::PRECISION)
|
||||
.arg(quantity.getUnit().getString());
|
||||
return string;
|
||||
}
|
||||
@@ -189,7 +187,7 @@ QString MaterialProperty::getDictionaryString() const
|
||||
if (value.isNull()) {
|
||||
return {};
|
||||
}
|
||||
return QString(QLatin1String("%1")).arg(value.toFloat(), 0, 'g', PRECISION);
|
||||
return QString(QLatin1String("%1")).arg(value.toFloat(), 0, 'g', MaterialValue::PRECISION);
|
||||
}
|
||||
return getValue().toString();
|
||||
}
|
||||
@@ -387,7 +385,9 @@ void MaterialProperty::setFloat(const QString& value)
|
||||
|
||||
void MaterialProperty::setQuantity(const Base::Quantity& value)
|
||||
{
|
||||
_valuePtr->setValue(QVariant(QVariant::fromValue(value)));
|
||||
auto quantity = value;
|
||||
quantity.setFormat(MaterialValue::getQuantityFormat());
|
||||
_valuePtr->setValue(QVariant(QVariant::fromValue(quantity)));
|
||||
}
|
||||
|
||||
void MaterialProperty::setQuantity(double value, const QString& units)
|
||||
@@ -1046,7 +1046,7 @@ Material::getValueString(const std::map<QString, std::shared_ptr<MaterialPropert
|
||||
return {};
|
||||
}
|
||||
return QString(QLatin1String("%L1"))
|
||||
.arg(value.toFloat(), 0, 'g', MaterialProperty::PRECISION);
|
||||
.arg(value.toFloat(), 0, 'g', MaterialValue::PRECISION);
|
||||
}
|
||||
return property->getValue().toString();
|
||||
}
|
||||
|
||||
@@ -140,11 +140,6 @@ public:
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
// void save(QTextStream& stream);
|
||||
|
||||
// Define precision for displaying floating point values
|
||||
static int const PRECISION;
|
||||
|
||||
protected:
|
||||
void setType(const QString& type);
|
||||
// void setType(MaterialValue::ValueType type) { _valueType = type; }
|
||||
|
||||
Reference in New Issue
Block a user