refs #314, new propertyBy methods (nested indexes) for PQs

This commit is contained in:
Klaus Basan
2014-08-18 01:49:55 +02:00
parent e109d73ba2
commit f4a94aa8ff
2 changed files with 79 additions and 0 deletions

View File

@@ -310,6 +310,66 @@ namespace BlackMisc
this->m_value = json.value("value").toDouble();
}
/*
* Property
*/
template <class MU, class PQ> QVariant CPhysicalQuantity<MU, PQ>::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toQVariant(); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexValue:
return QVariant(this->m_value);
case IndexUnit:
return this->m_unit.toQVariant();
case IndexValueRounded0DigitsWithUnit:
return QVariant(this->valueRoundedWithUnit(0));
case IndexValueRounded1DigitsWithUnit:
return QVariant(this->valueRoundedWithUnit(1));
case IndexValueRounded2DigitsWithUnit:
return QVariant(this->valueRoundedWithUnit(2));
case IndexValueRounded3DigitsWithUnit:
return QVariant(this->valueRoundedWithUnit(3));
case IndexValueRounded6DigitsWithUnit:
return QVariant(this->valueRoundedWithUnit(6));
default:
return CValueObject::propertyByIndex(index);
}
}
/*
* Property
*/
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::setPropertyByIndex(const QVariant &variant, const CPropertyIndex &index)
{
if (index.isMyself())
{
this->fromQVariant(variant);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexValue:
this->m_value = variant.toDouble();
break;
case IndexUnit:
this->m_unit.fromQVariant(variant);
break;
case IndexValueRounded0DigitsWithUnit:
case IndexValueRounded1DigitsWithUnit:
case IndexValueRounded2DigitsWithUnit:
case IndexValueRounded3DigitsWithUnit:
case IndexValueRounded6DigitsWithUnit:
this->parseFromString(variant.toString());
break;
default:
CValueObject::setPropertyByIndex(variant, index);
break;
}
}
/*
* metaTypeId
*/