Base: Quantity: return std::string
This commit is contained in:
committed by
Yorik van Havre
parent
c11b37e312
commit
2ea8a633ac
@@ -115,8 +115,7 @@ std::shared_ptr<Material2DArray> MaterialYamlEntry::read2DArray(const YAML::Node
|
||||
|
||||
auto row = std::make_shared<QList<QVariant>>();
|
||||
for (std::size_t j = 0; j < yamlRow.size(); j++) {
|
||||
Base::Quantity qq =
|
||||
Base::Quantity::parse(QString::fromStdString(yamlRow[j].as<std::string>()));
|
||||
Base::Quantity qq = Base::Quantity::parse(yamlRow[j].as<std::string>());
|
||||
qq.setFormat(MaterialValue::getQuantityFormat());
|
||||
row->push_back(QVariant::fromValue(qq));
|
||||
}
|
||||
@@ -142,10 +141,8 @@ std::shared_ptr<Material3DArray> MaterialYamlEntry::read3DArray(const YAML::Node
|
||||
for (std::size_t depth = 0; depth < yamlArray.size(); depth++) {
|
||||
auto yamlDepth = yamlArray[depth];
|
||||
for (auto it = yamlDepth.begin(); it != yamlDepth.end(); it++) {
|
||||
auto depthValue =
|
||||
Base::Quantity::parse(QString::fromStdString(it->first.as<std::string>()));
|
||||
auto depthValue = Base::Quantity::parse(it->first.as<std::string>());
|
||||
depthValue.setFormat(MaterialValue::getQuantityFormat());
|
||||
|
||||
array3d->addDepth(depth, depthValue);
|
||||
|
||||
auto yamlTable = it->second;
|
||||
@@ -154,8 +151,7 @@ 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++) {
|
||||
auto qq = Base::Quantity::parse(
|
||||
QString::fromStdString(yamlRow[j].as<std::string>()));
|
||||
auto qq = Base::Quantity::parse(yamlRow[j].as<std::string>());
|
||||
qq.setFormat(MaterialValue::getQuantityFormat());
|
||||
row->push_back(qq);
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ QString MaterialValue::getYAMLString() const
|
||||
}
|
||||
if (getType() == MaterialValue::Quantity) {
|
||||
auto quantity = getValue().value<Base::Quantity>();
|
||||
yaml += quantity.getUserString();
|
||||
yaml += QString::fromStdString(quantity.getUserString());
|
||||
}
|
||||
else if (getType() == MaterialValue::Float) {
|
||||
auto value = getValue();
|
||||
@@ -500,7 +500,7 @@ QString Material2DArray::getYAMLString() const
|
||||
}
|
||||
yaml += QString::fromStdString("\"");
|
||||
auto quantity = column.value<Base::Quantity>();
|
||||
yaml += quantity.getUserString();
|
||||
yaml += QString::fromStdString(quantity.getUserString());
|
||||
yaml += QString::fromStdString("\"");
|
||||
}
|
||||
|
||||
@@ -814,7 +814,7 @@ QString Material3DArray::getYAMLString() const
|
||||
}
|
||||
|
||||
yaml += QString::fromStdString("\"");
|
||||
auto value = getDepthValue(depth).getUserString();
|
||||
auto value = QString::fromStdString(getDepthValue(depth).getUserString());
|
||||
yaml += value;
|
||||
yaml += QString::fromStdString("\": [");
|
||||
|
||||
@@ -844,7 +844,7 @@ QString Material3DArray::getYAMLString() const
|
||||
}
|
||||
yaml += QString::fromStdString("\"");
|
||||
// Base::Quantity quantity = column.value<Base::Quantity>();
|
||||
yaml += column.getUserString();
|
||||
yaml += QString::fromStdString(column.getUserString());
|
||||
yaml += QString::fromStdString("\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ QString MaterialProperty::getString() const
|
||||
}
|
||||
if (getType() == MaterialValue::Quantity) {
|
||||
auto quantity = getValue().value<Base::Quantity>();
|
||||
return quantity.getUserString();
|
||||
return QString::fromStdString(quantity.getUserString());
|
||||
}
|
||||
if (getType() == MaterialValue::Float) {
|
||||
auto value = getValue();
|
||||
@@ -266,7 +266,7 @@ QVariant MaterialProperty::getColumnNull(int column) const
|
||||
|
||||
switch (valueType) {
|
||||
case MaterialValue::Quantity: {
|
||||
Base::Quantity quant = Base::Quantity(0, getColumnUnits(column));
|
||||
Base::Quantity quant = Base::Quantity(0, getColumnUnits(column).toStdString());
|
||||
return QVariant::fromValue(quant);
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ void MaterialProperty::setValue(const QString& value)
|
||||
}
|
||||
else if (_valuePtr->getType() == MaterialValue::Quantity) {
|
||||
try {
|
||||
setQuantity(Base::Quantity::parse(value));
|
||||
setQuantity(Base::Quantity::parse(value.toStdString()));
|
||||
}
|
||||
catch (const Base::ParserError& e) {
|
||||
Base::Console().Log("MaterialProperty::setValue Error '%s' - '%s'\n",
|
||||
@@ -392,12 +392,12 @@ void MaterialProperty::setQuantity(const Base::Quantity& value)
|
||||
|
||||
void MaterialProperty::setQuantity(double value, const QString& units)
|
||||
{
|
||||
setQuantity(Base::Quantity(value, units));
|
||||
setQuantity(Base::Quantity(value, units.toStdString()));
|
||||
}
|
||||
|
||||
void MaterialProperty::setQuantity(const QString& value)
|
||||
{
|
||||
setQuantity(Base::Quantity::parse(value));
|
||||
setQuantity(Base::Quantity::parse(value.toStdString()));
|
||||
}
|
||||
|
||||
void MaterialProperty::setList(const QList<QVariant>& value)
|
||||
@@ -1038,7 +1038,7 @@ Material::getValueString(const std::map<QString, std::shared_ptr<MaterialPropert
|
||||
if (value.isNull()) {
|
||||
return {};
|
||||
}
|
||||
return value.value<Base::Quantity>().getUserString();
|
||||
return QString::fromStdString(value.value<Base::Quantity>().getUserString());
|
||||
}
|
||||
if (property->getType() == MaterialValue::Float) {
|
||||
auto value = property->getValue();
|
||||
|
||||
@@ -72,16 +72,13 @@ void ArrayDelegate::paint(QPainter* painter,
|
||||
auto* tableModel = dynamic_cast<const AbstractArrayModel*>(index.model());
|
||||
painter->save();
|
||||
|
||||
if (tableModel->newRow(index)) {
|
||||
painter->drawText(option.rect, 0, QString());
|
||||
}
|
||||
else {
|
||||
QString text;
|
||||
if (!tableModel->newRow(index)) {
|
||||
QVariant item = tableModel->data(index);
|
||||
auto quantity = item.value<Base::Quantity>();
|
||||
QString text = quantity.getUserString();
|
||||
painter->drawText(option.rect, 0, text);
|
||||
text = QString::fromStdString(quantity.getUserString());
|
||||
}
|
||||
|
||||
painter->drawText(option.rect, 0, text);
|
||||
painter->restore();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -93,7 +93,7 @@ QVariant Array2DModel::data(const QModelIndex& index, int role) const
|
||||
try {
|
||||
auto column = _property->getColumnType(index.column());
|
||||
if (column == Materials::MaterialValue::Quantity) {
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(index.column()));
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(index.column()).toStdString());
|
||||
qq.setFormat(Materials::MaterialValue::getQuantityFormat());
|
||||
return QVariant::fromValue(qq);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ QVariant Array3DDepthModel::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
|
||||
try {
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(0));
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(0).toStdString());
|
||||
qq.setFormat(Materials::MaterialValue::getQuantityFormat());
|
||||
return QVariant::fromValue(qq);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ bool Array3DDepthModel::insertRows(int row, int count, const QModelIndex& parent
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
auto qq = Base::Quantity(0, _property->getColumnUnits(0));
|
||||
auto qq = Base::Quantity(0, _property->getColumnUnits(0).toStdString());
|
||||
qq.setFormat(Materials::MaterialValue::getQuantityFormat());
|
||||
_value->addDepth(row, qq);
|
||||
}
|
||||
@@ -395,7 +395,7 @@ QVariant Array3DModel::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
|
||||
try {
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(index.column() + 1));
|
||||
Base::Quantity qq = Base::Quantity(0, _property->getColumnUnits(index.column() + 1).toStdString());
|
||||
qq.setFormat(Materials::MaterialValue::getQuantityFormat());
|
||||
return QVariant::fromValue(qq);
|
||||
}
|
||||
|
||||
@@ -103,15 +103,13 @@ void BaseDelegate::paintQuantity(QPainter* painter,
|
||||
painter->drawText(option.rect, 0, QString());
|
||||
}
|
||||
else {
|
||||
QString text;
|
||||
QVariant item = getValue(index);
|
||||
auto quantity = item.value<Base::Quantity>();
|
||||
if (quantity.isValid()) {
|
||||
QString text = quantity.getUserString();
|
||||
painter->drawText(option.rect, 0, text);
|
||||
}
|
||||
else {
|
||||
painter->drawText(option.rect, 0, QString());
|
||||
text = QString::fromStdString(quantity.getUserString());
|
||||
}
|
||||
painter->drawText(option.rect, 0, text);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
|
||||
Reference in New Issue
Block a user