Base: Quantity: return std::string

This commit is contained in:
Ladislav Michl
2024-07-13 13:07:27 +02:00
committed by Yorik van Havre
parent c11b37e312
commit 2ea8a633ac
58 changed files with 573 additions and 592 deletions

View File

@@ -28,6 +28,8 @@
#include <QTreeWidget>
#endif
#include <fmt/format.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
@@ -242,12 +244,10 @@ void NumberRange::throwIfOutOfRange(const Base::Quantity& value) const
if (value.getValue() < minimum || value.getValue() > maximum) {
Base::Quantity minVal(minimum, value.getUnit());
Base::Quantity maxVal(maximum, value.getUnit());
QString valStr = value.getUserString();
QString minStr = minVal.getUserString();
QString maxStr = maxVal.getUserString();
QString error = QString::fromLatin1("Value out of range (%1 out of [%2, %3])").arg(valStr, minStr, maxStr);
throw Base::ValueError(error.toStdString());
auto valStr = value.getUserString();
auto minStr = minVal.getUserString();
auto maxStr = maxVal.getUserString();
throw Base::ValueError(fmt::format("Value out of range ({} out of [{}, {}])", valStr, minStr, maxStr));
}
}
@@ -289,12 +289,12 @@ void DlgExpressionInput::checkExpression(const QString& text)
auto * n = Base::freecad_dynamic_cast<NumberExpression>(result.get());
if (n) {
Base::Quantity value = n->getQuantity();
QString msg = value.getUserString();
if (!value.isValid()) {
throw Base::ValueError("Not a number");
}
else if (!impliedUnit.isEmpty()) {
auto msg = value.getUserString();
if (!impliedUnit.isEmpty()) {
if (!value.getUnit().isEmpty() && value.getUnit() != impliedUnit)
throw Base::UnitsMismatchError("Unit mismatch between result and required unit");
@@ -302,7 +302,7 @@ void DlgExpressionInput::checkExpression(const QString& text)
}
else if (!value.getUnit().isEmpty()) {
msg += QString::fromUtf8(" (Warning: unit discarded)");
msg += " (Warning: unit discarded)";
QPalette p(ui->msg->palette());
p.setColor(QPalette::WindowText, Qt::red);
@@ -311,7 +311,7 @@ void DlgExpressionInput::checkExpression(const QString& text)
numberRange.throwIfOutOfRange(value);
ui->msg->setText(msg);
ui->msg->setText(QString::fromStdString(msg));
}
else {
ui->msg->setText(QString::fromStdString(result->toString()));