new userString methode
This commit is contained in:
parent
3a3afa0783
commit
87c4741fac
|
@ -39,8 +39,10 @@
|
|||
# pragma warning(disable : 4335) // disable MAC file format warning on VC
|
||||
#endif
|
||||
|
||||
|
||||
using namespace Base;
|
||||
|
||||
double Quantity::defaultFactor = 1.0;
|
||||
|
||||
|
||||
Quantity::Quantity()
|
||||
{
|
||||
|
@ -117,18 +119,23 @@ Quantity& Quantity::operator = (const Quantity &New)
|
|||
return *this;
|
||||
}
|
||||
|
||||
double Quantity::getUserPrefered(QString &unitString)const
|
||||
QString Quantity::getUserString(double &factor,QString &unitString)
|
||||
{
|
||||
return Base::UnitsApi::schemaPrefUnit(_Unit,unitString).getValue() * _Value;
|
||||
return Base::UnitsApi::schemaTranslate(*this,factor,unitString);
|
||||
}
|
||||
|
||||
std::string Quantity::getUserString(void)const
|
||||
{
|
||||
std::stringstream sstream;
|
||||
sstream << _Value << _Unit.getString();
|
||||
//TODO: implementing
|
||||
return sstream.str();
|
||||
}
|
||||
|
||||
//double Quantity::getUserPrefered(QString &unitString)const
|
||||
//{
|
||||
// return Base::UnitsApi::schemaPrefUnit(_Unit,unitString).getValue() * _Value;
|
||||
//}
|
||||
//
|
||||
//std::string Quantity::getUserString(void)const
|
||||
//{
|
||||
// std::stringstream sstream;
|
||||
// sstream << _Value << _Unit.getString();
|
||||
// //TODO: implementing
|
||||
// return sstream.str();
|
||||
//}
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool Quantity::isDimensionless(void)const
|
||||
|
|
|
@ -62,9 +62,10 @@ public:
|
|||
//@}
|
||||
|
||||
/// transfer to user prefered unit/potence
|
||||
double getUserPrefered() const { QString dummy; return getUserPrefered(dummy); }
|
||||
double getUserPrefered(QString &unitString) const;
|
||||
std::string getUserString(void)const;
|
||||
QString getUserString(double &factor=defaultFactor,QString &unitString=QString());
|
||||
//double getUserPrefered() const { QString dummy; return getUserPrefered(dummy); }
|
||||
//double getUserPrefered(QString &unitString) const;
|
||||
//std::string getUserString(void)const;
|
||||
|
||||
static Quantity parse(const char* buffer);
|
||||
|
||||
|
@ -167,6 +168,7 @@ public:
|
|||
|
||||
|
||||
//@}
|
||||
static double defaultFactor;
|
||||
|
||||
|
||||
protected:
|
||||
|
|
|
@ -57,6 +57,7 @@ using namespace Base;
|
|||
// return QString::fromLatin1(QuantityNames[t]);
|
||||
//}
|
||||
// === static attributes ================================================
|
||||
double UnitsApi::defaultFactor = 1.0;
|
||||
|
||||
UnitsSchema *UnitsApi::UserPrefSystem = new UnitsSchemaInternal();
|
||||
|
||||
|
@ -103,15 +104,11 @@ void UnitsApi::setSchema(UnitSystem s)
|
|||
|
||||
// === static translation methodes ==========================================
|
||||
|
||||
QString UnitsApi::schemaTranslate(Base::Quantity quant)
|
||||
QString UnitsApi::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
return UserPrefSystem->schemaTranslate(quant);
|
||||
return UserPrefSystem->schemaTranslate(quant,factor,unitString);
|
||||
}
|
||||
|
||||
Base::Quantity UnitsApi::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
{
|
||||
return UserPrefSystem->schemaPrefUnit(unit,outUnitString);
|
||||
}
|
||||
|
||||
//QString UnitsApi::toStrWithUserPrefs(QuantityType t,double Value)
|
||||
//{
|
||||
|
|
|
@ -62,13 +62,7 @@ public:
|
|||
*/
|
||||
static void setSchema(UnitSystem s);
|
||||
|
||||
|
||||
/// raw parser interface to calculat units (only from and to internal)
|
||||
//tatic Quantity translateUnit(const char*);
|
||||
//static Quantity translateUnit(const QString &);
|
||||
|
||||
static QString schemaTranslate(Base::Quantity quant);
|
||||
static Base::Quantity schemaPrefUnit(const Base::Unit &unit,QString &outUnitString);
|
||||
static QString schemaTranslate(Base::Quantity quant,double &factor=defaultFactor,QString &unitString=QString());
|
||||
/// generate a value for a quantity with default user prefered system
|
||||
static double toDbl(PyObject *ArgObj,const Base::Unit &u=Base::Unit());
|
||||
/// generate a value for a quantity with default user prefered system
|
||||
|
@ -87,6 +81,8 @@ public:
|
|||
// Python interface
|
||||
static PyMethodDef Methods[];
|
||||
|
||||
static double defaultFactor;
|
||||
|
||||
|
||||
protected:
|
||||
// not used at the moment
|
||||
|
|
|
@ -50,9 +50,7 @@ class UnitsSchema
|
|||
{
|
||||
public:
|
||||
/// this methode translate the quantity in a string as the user may expect it
|
||||
virtual QString schemaTranslate(Base::Quantity quant)=0;
|
||||
// returns the prefered unit as string and the quantity to translate
|
||||
virtual Base::Quantity schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)=0;
|
||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)=0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -34,25 +34,25 @@
|
|||
using namespace Base;
|
||||
|
||||
|
||||
QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant)
|
||||
QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = quant.getValue();
|
||||
Unit unit = quant.getUnit();
|
||||
|
||||
return QString::fromAscii("%1 %2").arg(UnitValue).arg(QString::fromAscii(unit.getString().c_str()));
|
||||
}
|
||||
|
||||
Base::Quantity UnitsSchemaImperial1::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
{
|
||||
if(unit == Unit::Length){
|
||||
outUnitString = QString::fromAscii("\"");
|
||||
return Base::Quantity(1/25.40,Unit::Length);
|
||||
}else if(unit == Unit::Mass){
|
||||
outUnitString = QString::fromAscii("lb");
|
||||
return Base::Quantity(1/0.45359237,Unit::Length);
|
||||
}else{
|
||||
outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
return Base::Quantity(1,unit);
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
//Base::Quantity UnitsSchemaImperial1::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
//{
|
||||
// if(unit == Unit::Length){
|
||||
// outUnitString = QString::fromAscii("\"");
|
||||
// return Base::Quantity(1/25.40,Unit::Length);
|
||||
// }else if(unit == Unit::Mass){
|
||||
// outUnitString = QString::fromAscii("lb");
|
||||
// return Base::Quantity(1/0.45359237,Unit::Length);
|
||||
// }else{
|
||||
// outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
// return Base::Quantity(1,unit);
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -39,8 +39,8 @@ namespace Base {
|
|||
class UnitsSchemaImperial1: public UnitsSchema
|
||||
{
|
||||
public:
|
||||
virtual QString schemaTranslate(Base::Quantity quant);
|
||||
Base::Quantity schemaPrefUnit(const Base::Unit &unit,QString &outUnitString);
|
||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -34,22 +34,22 @@
|
|||
using namespace Base;
|
||||
|
||||
|
||||
QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant)
|
||||
QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = quant.getValue();
|
||||
Unit unit = quant.getUnit();
|
||||
|
||||
return QString::fromAscii("%1 %2").arg(UnitValue).arg(QString::fromAscii(unit.getString().c_str()));
|
||||
}
|
||||
|
||||
Base::Quantity UnitsSchemaInternal::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
{
|
||||
if(unit == Unit::Length){
|
||||
outUnitString = QString::fromAscii("mm");
|
||||
return Base::Quantity(1.0,Unit::Length);
|
||||
}else{
|
||||
outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
return Base::Quantity(1,unit);
|
||||
}
|
||||
//
|
||||
//Base::Quantity UnitsSchemaInternal::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
//{
|
||||
// if(unit == Unit::Length){
|
||||
// outUnitString = QString::fromAscii("mm");
|
||||
// return Base::Quantity(1.0,Unit::Length);
|
||||
// }else{
|
||||
// outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
// return Base::Quantity(1,unit);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ namespace Base {
|
|||
class UnitsSchemaInternal: public UnitsSchema
|
||||
{
|
||||
public:
|
||||
virtual QString schemaTranslate(Base::Quantity quant);
|
||||
Base::Quantity schemaPrefUnit(const Base::Unit &unit,QString &outUnitString);
|
||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -34,22 +34,22 @@
|
|||
using namespace Base;
|
||||
|
||||
|
||||
QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant)
|
||||
QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = quant.getValue();
|
||||
Unit unit = quant.getUnit();
|
||||
|
||||
return QString::fromAscii("%1 %2").arg(UnitValue).arg(QString::fromAscii(unit.getString().c_str()));
|
||||
}
|
||||
|
||||
Base::Quantity UnitsSchemaMKS::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
{
|
||||
if(unit == Unit::Length){
|
||||
outUnitString = QString::fromAscii("m");
|
||||
return Base::Quantity(1/1000.0,Unit::Length);
|
||||
}else{
|
||||
outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
return Base::Quantity(1,unit);
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
//Base::Quantity UnitsSchemaMKS::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
//{
|
||||
// if(unit == Unit::Length){
|
||||
// outUnitString = QString::fromAscii("m");
|
||||
// return Base::Quantity(1/1000.0,Unit::Length);
|
||||
// }else{
|
||||
// outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
// return Base::Quantity(1,unit);
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -38,8 +38,8 @@ namespace Base {
|
|||
class UnitsSchemaMKS: public UnitsSchema
|
||||
{
|
||||
public:
|
||||
virtual QString schemaTranslate(Base::Quantity quant);
|
||||
Base::Quantity schemaPrefUnit(const Base::Unit &unit,QString &outUnitString);
|
||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -655,13 +655,10 @@ QVariant PropertyUnitItem::toString(const QVariant& Value) const
|
|||
const std::vector<App::Property*>& prop = getPropertyData();
|
||||
if (!prop.empty() && prop.front()->getTypeId().isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
|
||||
Base::Quantity value = static_cast<const App::PropertyQuantity*>(prop.front())->getQuantityValue();
|
||||
value.getUserPrefered(unit);
|
||||
unit.prepend(QLatin1String(" "));
|
||||
unit = value.getUserString();
|
||||
}
|
||||
|
||||
QString data = QString::fromAscii("%1 %2").arg(val,0,'f',decimals()).arg(unit);
|
||||
|
||||
return QVariant(data);
|
||||
return QVariant(unit);
|
||||
}
|
||||
|
||||
QVariant PropertyUnitItem::value(const App::Property* prop) const
|
||||
|
@ -669,7 +666,7 @@ QVariant PropertyUnitItem::value(const App::Property* prop) const
|
|||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyQuantity::getClassTypeId()));
|
||||
Base::Quantity value = static_cast<const App::PropertyQuantity*>(prop)->getQuantityValue();
|
||||
QString unitString;
|
||||
return QVariant(value.getUserPrefered(unitString));
|
||||
return QVariant(value.getValue());
|
||||
}
|
||||
|
||||
void PropertyUnitItem::setValue(const QVariant& value)
|
||||
|
@ -684,12 +681,10 @@ void PropertyUnitItem::setValue(const QVariant& value)
|
|||
return;
|
||||
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
|
||||
Base::Quantity value = static_cast<const App::PropertyQuantity*>(prop.front())->getQuantityValue();
|
||||
value.getUserPrefered(unit);
|
||||
unit.prepend(QLatin1String(" "));
|
||||
unit = value.getUserString();
|
||||
}
|
||||
|
||||
QString data = QString::fromAscii("'%1%2'").arg(val,0,'f',decimals()).arg(unit);
|
||||
setPropertyValue(data);
|
||||
setPropertyValue(unit);
|
||||
}
|
||||
|
||||
QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||
|
@ -712,9 +707,10 @@ void PropertyUnitItem::setEditorData(QWidget *editor, const QVariant& data) cons
|
|||
else if (prop.front()->getTypeId().isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
|
||||
Base::Quantity value = static_cast<const App::PropertyQuantity*>(prop.front())->getQuantityValue();
|
||||
QString unitString;
|
||||
value.getUserPrefered(unitString);
|
||||
unitString.prepend(QLatin1String(" "));
|
||||
sb->setSuffix(unitString);
|
||||
//double factor;
|
||||
//value.getUserString(unitString);
|
||||
//unitString.prepend(QLatin1String(" "));
|
||||
//sb->setSuffix(unitString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user