improve whitespaces, fix typos
This commit is contained in:
parent
7e310b2444
commit
5cb8873794
|
@ -27,9 +27,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "Quantity.h"
|
#include <Base/Quantity.h>
|
||||||
|
|
||||||
//#include "UnitsApi.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Base {
|
namespace Base {
|
||||||
|
@ -53,15 +51,15 @@ class UnitsSchema
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~UnitsSchema(){}
|
virtual ~UnitsSchema(){}
|
||||||
/** get called if this schema gets activated.
|
/** Gets called if this schema gets activated.
|
||||||
* Here its theoretical possible that you can change the static factors
|
* Here it's theoretically possible that you can change the static factors
|
||||||
* for certain Units (e.g. mi = 1,8km instead of mi=1.6km).
|
* for certain units (e.g. mi = 1,8km instead of mi=1.6km).
|
||||||
*/
|
*/
|
||||||
virtual void setSchemaUnits(void){}
|
virtual void setSchemaUnits(void){}
|
||||||
/// if you use setSchemaUnits() you have also to impment this methode to undo your changes!
|
/// If you use setSchemaUnits() you also have to impment this method to undo your changes!
|
||||||
virtual void resetSchemaUnits(void){}
|
virtual void resetSchemaUnits(void){}
|
||||||
|
|
||||||
/// this methode translate the quantity in a string as the user may expect it
|
/// This method translates the quantity in a string as the user may expect it.
|
||||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)=0;
|
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,19 +43,23 @@ QString UnitsSchemaCentimeters::schemaTranslate(Base::Quantity quant,double &fac
|
||||||
// all length units in centimeters
|
// all length units in centimeters
|
||||||
unitString = QString::fromLatin1("cm");
|
unitString = QString::fromLatin1("cm");
|
||||||
factor = 10.0;
|
factor = 10.0;
|
||||||
}else if (unit == Unit::Area){
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
// all area units in square meters
|
// all area units in square meters
|
||||||
unitString = QString::fromLatin1("m^2");
|
unitString = QString::fromLatin1("m^2");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else if (unit == Unit::Volume){
|
}
|
||||||
|
else if (unit == Unit::Volume) {
|
||||||
// all area units in cubic meters
|
// all area units in cubic meters
|
||||||
unitString = QString::fromLatin1("m^3");
|
unitString = QString::fromLatin1("m^3");
|
||||||
factor = 1000000000.0;
|
factor = 1000000000.0;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
|
|
|
@ -70,56 +70,69 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
|
||||||
if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation
|
if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation
|
||||||
unitString = QString::fromLatin1("in");
|
unitString = QString::fromLatin1("in");
|
||||||
factor = 25.4;
|
factor = 25.4;
|
||||||
}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil)
|
}
|
||||||
|
else if(UnitValue < 2.54) { // smaller then 0.1 inch -> Thou (mil)
|
||||||
unitString = QString::fromLatin1("thou");
|
unitString = QString::fromLatin1("thou");
|
||||||
factor = 0.0254;
|
factor = 0.0254;
|
||||||
}else if(UnitValue < 304.8){
|
}
|
||||||
|
else if(UnitValue < 304.8) {
|
||||||
unitString = QString::fromLatin1("\"");
|
unitString = QString::fromLatin1("\"");
|
||||||
factor = 25.4;
|
factor = 25.4;
|
||||||
}else if(UnitValue < 914.4){
|
}
|
||||||
|
else if(UnitValue < 914.4) {
|
||||||
unitString = QString::fromLatin1("\'");
|
unitString = QString::fromLatin1("\'");
|
||||||
factor = 304.8;
|
factor = 304.8;
|
||||||
}else if(UnitValue < 1609344.0){
|
}else if(UnitValue < 1609344.0){
|
||||||
unitString = QString::fromLatin1("yd");
|
unitString = QString::fromLatin1("yd");
|
||||||
factor = 914.4;
|
factor = 914.4;
|
||||||
}else if(UnitValue < 1609344000.0 ){
|
}
|
||||||
|
else if(UnitValue < 1609344000.0) {
|
||||||
unitString = QString::fromLatin1("mi");
|
unitString = QString::fromLatin1("mi");
|
||||||
factor = 1609344.0;
|
factor = 1609344.0;
|
||||||
}else{ // bigger then 1000 mi -> scientific notation
|
}
|
||||||
|
else { // bigger then 1000 mi -> scientific notation
|
||||||
unitString = QString::fromLatin1("in");
|
unitString = QString::fromLatin1("in");
|
||||||
factor = 25.4;
|
factor = 25.4;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::Area){
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
// TODO Cascade for the Areas
|
// TODO Cascade for the Areas
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("in^2");
|
unitString = QString::fromLatin1("in^2");
|
||||||
factor = 645.16;
|
factor = 645.16;
|
||||||
}else if (unit == Unit::Volume){
|
}
|
||||||
|
else if (unit == Unit::Volume) {
|
||||||
// TODO Cascade for the Volume
|
// TODO Cascade for the Volume
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("in^3");
|
unitString = QString::fromLatin1("in^3");
|
||||||
factor = 16387.064;
|
factor = 16387.064;
|
||||||
}else if (unit == Unit::Mass){
|
}
|
||||||
|
else if (unit == Unit::Mass) {
|
||||||
// TODO Cascade for the wights
|
// TODO Cascade for the wights
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("lb");
|
unitString = QString::fromLatin1("lb");
|
||||||
factor = 0.45359237;
|
factor = 0.45359237;
|
||||||
}else if (unit == Unit::Pressure){
|
}
|
||||||
|
else if (unit == Unit::Pressure) {
|
||||||
if (UnitValue < 145.038) {// psi is the smallest
|
if (UnitValue < 145.038) {// psi is the smallest
|
||||||
unitString = QString::fromLatin1("psi");
|
unitString = QString::fromLatin1("psi");
|
||||||
factor = 0.145038;
|
factor = 0.145038;
|
||||||
}else if(UnitValue < 145038){
|
}
|
||||||
|
else if (UnitValue < 145038) {
|
||||||
unitString = QString::fromLatin1("ksi");
|
unitString = QString::fromLatin1("ksi");
|
||||||
factor = 145.038;
|
factor = 145.038;
|
||||||
}else{ // bigger then 1000 ksi -> psi + scientific notation
|
}
|
||||||
|
else { // bigger then 1000 ksi -> psi + scientific notation
|
||||||
unitString = QString::fromLatin1("psi");
|
unitString = QString::fromLatin1("psi");
|
||||||
factor = 0.145038;
|
factor = 0.145038;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else{
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
|
@ -127,9 +140,6 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
|
||||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||||
{
|
{
|
||||||
double UnitValue = std::abs(quant.getValue());
|
double UnitValue = std::abs(quant.getValue());
|
||||||
|
@ -145,41 +155,49 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double
|
||||||
//}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil)
|
//}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil)
|
||||||
// unitString = QString::fromLatin1("thou");
|
// unitString = QString::fromLatin1("thou");
|
||||||
// factor = 0.0254;
|
// factor = 0.0254;
|
||||||
}else{ // bigger then 1000 mi -> scientific notation
|
}
|
||||||
|
else { // bigger then 1000 mi -> scientific notation
|
||||||
unitString = QString::fromLatin1("in");
|
unitString = QString::fromLatin1("in");
|
||||||
factor = 25.4;
|
factor = 25.4;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::Area){
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
// TODO Cascade for the Areas
|
// TODO Cascade for the Areas
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("in^2");
|
unitString = QString::fromLatin1("in^2");
|
||||||
factor = 645.16;
|
factor = 645.16;
|
||||||
}else if (unit == Unit::Volume){
|
}
|
||||||
|
else if (unit == Unit::Volume) {
|
||||||
// TODO Cascade for the Volume
|
// TODO Cascade for the Volume
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("in^3");
|
unitString = QString::fromLatin1("in^3");
|
||||||
factor = 16387.064;
|
factor = 16387.064;
|
||||||
}else if (unit == Unit::Mass){
|
}
|
||||||
|
else if (unit == Unit::Mass) {
|
||||||
// TODO Cascade for the wights
|
// TODO Cascade for the wights
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromLatin1("lb");
|
unitString = QString::fromLatin1("lb");
|
||||||
factor = 0.45359237;
|
factor = 0.45359237;
|
||||||
}else if (unit == Unit::Pressure){
|
}
|
||||||
|
else if (unit == Unit::Pressure) {
|
||||||
if (UnitValue < 145.038) {// psi is the smallest
|
if (UnitValue < 145.038) {// psi is the smallest
|
||||||
unitString = QString::fromLatin1("psi");
|
unitString = QString::fromLatin1("psi");
|
||||||
factor = 0.145038;
|
factor = 0.145038;
|
||||||
//}else if(UnitValue < 145038){
|
//}else if(UnitValue < 145038){
|
||||||
// unitString = QString::fromLatin1("ksi");
|
// unitString = QString::fromLatin1("ksi");
|
||||||
// factor = 145.038;
|
// factor = 145.038;
|
||||||
}else{ // bigger then 1000 ksi -> psi + scientific notation
|
}
|
||||||
|
else { // bigger then 1000 ksi -> psi + scientific notation
|
||||||
unitString = QString::fromLatin1("psi");
|
unitString = QString::fromLatin1("psi");
|
||||||
factor = 0.145038;
|
factor = 0.145038;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
|
@ -187,8 +205,6 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double
|
||||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||||
{
|
{
|
||||||
// this schema expresses distances in feet + inches + fractions
|
// this schema expresses distances in feet + inches + fractions
|
||||||
|
@ -206,19 +222,23 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double
|
||||||
inches++;
|
inches++;
|
||||||
fraction = 0.0;
|
fraction = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the quantity is too small it is rounded to zero
|
// if the quantity is too small it is rounded to zero
|
||||||
if (std::abs(quant.getValue()) <= 1.5875)
|
if (std::abs(quant.getValue()) <= 1.5875)
|
||||||
return QString::fromLatin1("0");
|
return QString::fromLatin1("0");
|
||||||
|
|
||||||
// build representation
|
// build representation
|
||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
if (quant.getValue() < 0)
|
if (quant.getValue() < 0)
|
||||||
output << "-";
|
output << "-";
|
||||||
|
|
||||||
// feet
|
// feet
|
||||||
if (feet > 0) {
|
if (feet > 0) {
|
||||||
output << feet << "'";
|
output << feet << "'";
|
||||||
if ( (inches > 0) || (fraction > 0.0625) )
|
if ( (inches > 0) || (fraction > 0.0625) )
|
||||||
output << " ";
|
output << " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
// inches
|
// inches
|
||||||
if (inches > 0) {
|
if (inches > 0) {
|
||||||
output << inches;
|
output << inches;
|
||||||
|
@ -227,6 +247,7 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double
|
||||||
else
|
else
|
||||||
output << "\"";
|
output << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
// fraction
|
// fraction
|
||||||
if (fraction <= 0.0625) {}
|
if (fraction <= 0.0625) {}
|
||||||
else if (fraction > 0.8125)
|
else if (fraction > 0.8125)
|
||||||
|
@ -244,16 +265,20 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double
|
||||||
else
|
else
|
||||||
output << "1/8\"";
|
output << "1/8\"";
|
||||||
return QString::fromLatin1(output.str().c_str());
|
return QString::fromLatin1(output.str().c_str());
|
||||||
}else if (unit == Unit::Area){
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
unitString = QString::fromLatin1("sqft");
|
unitString = QString::fromLatin1("sqft");
|
||||||
factor = 92903.04;
|
factor = 92903.04;
|
||||||
}else if (unit == Unit::Volume){
|
}
|
||||||
|
else if (unit == Unit::Volume) {
|
||||||
unitString = QString::fromLatin1("cuft");
|
unitString = QString::fromLatin1("cuft");
|
||||||
factor = 28316846.592;
|
factor = 28316846.592;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Base {
|
||||||
|
|
||||||
|
|
||||||
/** The schema class for the imperial unit system
|
/** The schema class for the imperial unit system
|
||||||
* Here are the definiton for the imperial unit system.
|
* Here are the definitons for the imperial unit system.
|
||||||
* It also defines how the value/units get printed.
|
* It also defines how the value/units get printed.
|
||||||
*/
|
*/
|
||||||
class UnitsSchemaImperial1: public UnitsSchema
|
class UnitsSchemaImperial1: public UnitsSchema
|
||||||
|
@ -42,11 +42,10 @@ public:
|
||||||
//virtual void setSchemaUnits(void);
|
//virtual void setSchemaUnits(void);
|
||||||
//virtual void resetSchemaUnits(void);
|
//virtual void resetSchemaUnits(void);
|
||||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The schema class for the imperial unit system
|
/** The schema class for the imperial unit system
|
||||||
* Here are the definiton for the imperial unit system.
|
* Here are the definitons for the imperial unit system.
|
||||||
* It also defines how the value/units get printed.
|
* It also defines how the value/units get printed.
|
||||||
*/
|
*/
|
||||||
class UnitsSchemaImperialDecimal: public UnitsSchema
|
class UnitsSchemaImperialDecimal: public UnitsSchema
|
||||||
|
@ -55,11 +54,10 @@ public:
|
||||||
//virtual void setSchemaUnits(void);
|
//virtual void setSchemaUnits(void);
|
||||||
//virtual void resetSchemaUnits(void);
|
//virtual void resetSchemaUnits(void);
|
||||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The schema class for the imperial unit system
|
/** The schema class for the imperial unit system
|
||||||
* Here are the definiton for the imperial unit system.
|
* Here are the definitons for the imperial unit system.
|
||||||
* It also defines how the value/units get printed.
|
* It also defines how the value/units get printed.
|
||||||
*/
|
*/
|
||||||
class UnitsSchemaImperialBuilding: public UnitsSchema
|
class UnitsSchemaImperialBuilding: public UnitsSchema
|
||||||
|
@ -68,7 +66,6 @@ public:
|
||||||
//virtual void setSchemaUnits(void);
|
//virtual void setSchemaUnits(void);
|
||||||
//virtual void resetSchemaUnits(void);
|
//virtual void resetSchemaUnits(void);
|
||||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,100 +42,125 @@ QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant,double &factor
|
||||||
double UnitValue = std::abs(quant.getValue());
|
double UnitValue = std::abs(quant.getValue());
|
||||||
Unit unit = quant.getUnit();
|
Unit unit = quant.getUnit();
|
||||||
|
|
||||||
// now do special treatment on all cases seams nececarry:
|
// now do special treatment on all cases seems necessary:
|
||||||
if (unit == Unit::Length) { // Length handling ============================
|
if (unit == Unit::Length) { // Length handling ============================
|
||||||
if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation
|
if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation
|
||||||
unitString = QString::fromLatin1("mm");
|
unitString = QString::fromLatin1("mm");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 0.001){
|
}
|
||||||
|
else if(UnitValue < 0.001) {
|
||||||
unitString = QString::fromLatin1("nm");
|
unitString = QString::fromLatin1("nm");
|
||||||
factor = 0.000001;
|
factor = 0.000001;
|
||||||
}else if(UnitValue < 0.1){
|
}
|
||||||
|
else if (UnitValue < 0.1) {
|
||||||
unitString = QString::fromUtf8("\xC2\xB5m");
|
unitString = QString::fromUtf8("\xC2\xB5m");
|
||||||
factor = 0.001;
|
factor = 0.001;
|
||||||
}else if(UnitValue < 10000.0){
|
}
|
||||||
unitString = QString::fromLatin1("mm");
|
else if (UnitValue < 10000.0) {
|
||||||
factor = 1.0;
|
|
||||||
}else if(UnitValue < 10000000.0){
|
|
||||||
unitString = QString::fromLatin1("m");
|
|
||||||
factor = 1000.0;
|
|
||||||
}else if(UnitValue < 100000000000.0 ){
|
|
||||||
unitString = QString::fromLatin1("km");
|
|
||||||
factor = 1000000.0;
|
|
||||||
}else{ // bigger then 1000 km -> scientific notation
|
|
||||||
unitString = QString::fromLatin1("mm");
|
unitString = QString::fromLatin1("mm");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::Area){
|
else if (UnitValue < 10000000.0) {
|
||||||
|
unitString = QString::fromLatin1("m");
|
||||||
|
factor = 1000.0;
|
||||||
|
}
|
||||||
|
else if (UnitValue < 100000000000.0) {
|
||||||
|
unitString = QString::fromLatin1("km");
|
||||||
|
factor = 1000000.0;
|
||||||
|
}
|
||||||
|
else { // bigger then 1000 km -> scientific notation
|
||||||
|
unitString = QString::fromLatin1("mm");
|
||||||
|
factor = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
// TODO Cascade for the Areas
|
// TODO Cascade for the Areas
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if (unit == Unit::Angle){
|
}
|
||||||
|
else if (unit == Unit::Angle) {
|
||||||
// TODO Cascade for the Areas
|
// TODO Cascade for the Areas
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = QString::fromUtf8("\xC2\xB0");
|
unitString = QString::fromUtf8("\xC2\xB0");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if (unit == Unit::Mass){
|
}
|
||||||
|
else if (unit == Unit::Mass) {
|
||||||
// TODO Cascade for the wights
|
// TODO Cascade for the wights
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if (unit == Unit::Density){
|
}
|
||||||
|
else if (unit == Unit::Density) {
|
||||||
if (UnitValue < 0.0001) {
|
if (UnitValue < 0.0001) {
|
||||||
unitString = QString::fromLatin1("kg/m^3");
|
unitString = QString::fromLatin1("kg/m^3");
|
||||||
factor = 0.000000001;
|
factor = 0.000000001;
|
||||||
}else if(UnitValue < 1.0){
|
}
|
||||||
|
else if (UnitValue < 1.0) {
|
||||||
unitString = QString::fromLatin1("kg/cm^3");
|
unitString = QString::fromLatin1("kg/cm^3");
|
||||||
factor = 0.001;
|
factor = 0.001;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = QString::fromLatin1("kg/mm^3");
|
unitString = QString::fromLatin1("kg/mm^3");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::ThermalConductivity){
|
}
|
||||||
|
else if (unit == Unit::ThermalConductivity) {
|
||||||
if (UnitValue < 1000) {
|
if (UnitValue < 1000) {
|
||||||
unitString = QString::fromLatin1("W/mm/K");
|
unitString = QString::fromLatin1("W/mm/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = QString::fromLatin1("W/m/K");
|
unitString = QString::fromLatin1("W/m/K");
|
||||||
factor = 1000.0;
|
factor = 1000.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::ThermalExpansionCoefficient){
|
}
|
||||||
|
else if (unit == Unit::ThermalExpansionCoefficient) {
|
||||||
if (UnitValue < 0.001) {
|
if (UnitValue < 0.001) {
|
||||||
unitString = QString::fromLatin1("um/m/K");
|
unitString = QString::fromLatin1("um/m/K");
|
||||||
factor = 0.000001;
|
factor = 0.000001;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = QString::fromLatin1("mm/mm/K");
|
unitString = QString::fromLatin1("mm/mm/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::SpecificHeat){
|
}
|
||||||
|
else if (unit == Unit::SpecificHeat) {
|
||||||
unitString = QString::fromLatin1("J/kg/K");
|
unitString = QString::fromLatin1("J/kg/K");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else if (unit == Unit::ThermalTransferCoefficient){
|
}
|
||||||
|
else if (unit == Unit::ThermalTransferCoefficient) {
|
||||||
unitString = QString::fromLatin1("W/m^2/K");
|
unitString = QString::fromLatin1("W/m^2/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if ((unit == Unit::Pressure) || (unit == Unit::Stress)){
|
}
|
||||||
|
else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) {
|
||||||
if (UnitValue < 10.0) {// Pa is the smallest
|
if (UnitValue < 10.0) {// Pa is the smallest
|
||||||
unitString = QString::fromLatin1("Pa");
|
unitString = QString::fromLatin1("Pa");
|
||||||
factor = 0.001;
|
factor = 0.001;
|
||||||
}else if(UnitValue < 10000.0){
|
}
|
||||||
|
else if (UnitValue < 10000.0) {
|
||||||
unitString = QString::fromLatin1("kPa");
|
unitString = QString::fromLatin1("kPa");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 10000000.0){
|
}
|
||||||
|
else if (UnitValue < 10000000.0) {
|
||||||
unitString = QString::fromLatin1("MPa");
|
unitString = QString::fromLatin1("MPa");
|
||||||
factor = 1000.0;
|
factor = 1000.0;
|
||||||
}else if(UnitValue < 10000000000.0){
|
}
|
||||||
|
else if (UnitValue < 10000000000.0) {
|
||||||
unitString = QString::fromLatin1("GPa");
|
unitString = QString::fromLatin1("GPa");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else{ // bigger -> scientific notation
|
}
|
||||||
|
else { // bigger -> scientific notation
|
||||||
unitString = QString::fromLatin1("Pa");
|
unitString = QString::fromLatin1("Pa");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
|
|
|
@ -41,101 +41,127 @@ QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QStr
|
||||||
double UnitValue = std::abs(quant.getValue());
|
double UnitValue = std::abs(quant.getValue());
|
||||||
Unit unit = quant.getUnit();
|
Unit unit = quant.getUnit();
|
||||||
|
|
||||||
// now do special treatment on all cases seams nececarry:
|
// now do special treatment on all cases seems necessary:
|
||||||
if (unit == Unit::Length) { // Length handling ============================
|
if (unit == Unit::Length) { // Length handling ============================
|
||||||
if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation
|
if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation
|
||||||
unitString = QString::fromLatin1("mm");
|
unitString = QString::fromLatin1("mm");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 0.001){
|
}
|
||||||
|
else if(UnitValue < 0.001) {
|
||||||
unitString = QString::fromLatin1("nm");
|
unitString = QString::fromLatin1("nm");
|
||||||
factor = 0.000001;
|
factor = 0.000001;
|
||||||
}else if(UnitValue < 0.1){
|
}
|
||||||
|
else if(UnitValue < 0.1) {
|
||||||
unitString = QString::fromUtf8("\xC2\xB5m");
|
unitString = QString::fromUtf8("\xC2\xB5m");
|
||||||
factor = 0.001;
|
factor = 0.001;
|
||||||
}else if(UnitValue < 100.0){
|
}
|
||||||
unitString = QString::fromLatin1("mm");
|
else if(UnitValue < 100.0) {
|
||||||
factor = 1.0;
|
|
||||||
}else if(UnitValue < 10000000.0){
|
|
||||||
unitString = QString::fromLatin1("m");
|
|
||||||
factor = 1000.0;
|
|
||||||
}else if(UnitValue < 100000000000.0 ){
|
|
||||||
unitString = QString::fromLatin1("km");
|
|
||||||
factor = 1000000.0;
|
|
||||||
}else{ // bigger then 1000 km -> scientific notation
|
|
||||||
unitString = QString::fromLatin1("mm");
|
unitString = QString::fromLatin1("mm");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::Area){
|
else if(UnitValue < 10000000.0) {
|
||||||
|
unitString = QString::fromLatin1("m");
|
||||||
|
factor = 1000.0;
|
||||||
|
}
|
||||||
|
else if(UnitValue < 100000000000.0 ) {
|
||||||
|
unitString = QString::fromLatin1("km");
|
||||||
|
factor = 1000000.0;
|
||||||
|
}
|
||||||
|
else { // bigger then 1000 km -> scientific notation
|
||||||
|
unitString = QString::fromLatin1("mm");
|
||||||
|
factor = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (unit == Unit::Area) {
|
||||||
if (UnitValue < 100.0) {// smaller than 1 square cm
|
if (UnitValue < 100.0) {// smaller than 1 square cm
|
||||||
unitString = QString::fromLatin1("mm^2");
|
unitString = QString::fromLatin1("mm^2");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 10000000000000.0 ){
|
}
|
||||||
|
else if (UnitValue < 10000000000000.0) {
|
||||||
unitString = QString::fromLatin1("m^2");
|
unitString = QString::fromLatin1("m^2");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else{ // bigger then 1 square kilometer
|
}
|
||||||
|
else { // bigger then 1 square kilometer
|
||||||
unitString = QString::fromLatin1("km^2");
|
unitString = QString::fromLatin1("km^2");
|
||||||
factor = 1000000000000.0;
|
factor = 1000000000000.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::Mass){
|
}
|
||||||
|
else if (unit == Unit::Mass) {
|
||||||
// TODO Cascade for the wights
|
// TODO Cascade for the wights
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if (unit == Unit::Volume){
|
}
|
||||||
|
else if (unit == Unit::Volume) {
|
||||||
if (UnitValue < 1000000.0) {// smaller than 10 cubic cm
|
if (UnitValue < 1000000.0) {// smaller than 10 cubic cm
|
||||||
unitString = QString::fromLatin1("mm^3");
|
unitString = QString::fromLatin1("mm^3");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 1000000000000000000.0 ){
|
}
|
||||||
|
else if (UnitValue < 1000000000000000000.0) {
|
||||||
unitString = QString::fromLatin1("m^3");
|
unitString = QString::fromLatin1("m^3");
|
||||||
factor = 1000000000.0;
|
factor = 1000000000.0;
|
||||||
}else{ // bigger then 1 cubic kilometer
|
}
|
||||||
|
else { // bigger then 1 cubic kilometer
|
||||||
unitString = QString::fromLatin1("km^3");
|
unitString = QString::fromLatin1("km^3");
|
||||||
factor = 1000000000000000000.0;
|
factor = 1000000000000000000.0;
|
||||||
}
|
}
|
||||||
}else if ((unit == Unit::Pressure) || (unit == Unit::Stress)){
|
}
|
||||||
|
else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) {
|
||||||
if (UnitValue < 10.0) {// Pa is the smallest
|
if (UnitValue < 10.0) {// Pa is the smallest
|
||||||
unitString = QString::fromLatin1("Pa");
|
unitString = QString::fromLatin1("Pa");
|
||||||
factor = 0.001;
|
factor = 0.001;
|
||||||
}else if(UnitValue < 10000.0){
|
}
|
||||||
|
else if (UnitValue < 10000.0) {
|
||||||
unitString = QString::fromLatin1("kPa");
|
unitString = QString::fromLatin1("kPa");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else if(UnitValue < 10000000.0){
|
}
|
||||||
|
else if (UnitValue < 10000000.0) {
|
||||||
unitString = QString::fromLatin1("MPa");
|
unitString = QString::fromLatin1("MPa");
|
||||||
factor = 1000.0;
|
factor = 1000.0;
|
||||||
}else if(UnitValue < 10000000000.0){
|
}
|
||||||
|
else if (UnitValue < 10000000000.0) {
|
||||||
unitString = QString::fromLatin1("GPa");
|
unitString = QString::fromLatin1("GPa");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else{ // bigger then 1000 GPa -> scientific notation
|
}
|
||||||
|
else { // bigger then 1000 GPa -> scientific notation
|
||||||
unitString = QString::fromLatin1("Pa");
|
unitString = QString::fromLatin1("Pa");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::ThermalConductivity){
|
}
|
||||||
|
else if (unit == Unit::ThermalConductivity) {
|
||||||
if (UnitValue < 1000) {
|
if (UnitValue < 1000) {
|
||||||
unitString = QString::fromLatin1("W/mm/K");
|
unitString = QString::fromLatin1("W/mm/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = QString::fromLatin1("W/m/K");
|
unitString = QString::fromLatin1("W/m/K");
|
||||||
factor = 1000.0;
|
factor = 1000.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::ThermalExpansionCoefficient){
|
}
|
||||||
|
else if (unit == Unit::ThermalExpansionCoefficient) {
|
||||||
if (UnitValue < 0.001) {
|
if (UnitValue < 0.001) {
|
||||||
unitString = QString::fromLatin1("um/m/K");
|
unitString = QString::fromLatin1("um/m/K");
|
||||||
factor = 0.000001;
|
factor = 0.000001;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
unitString = QString::fromLatin1("m/m/K");
|
unitString = QString::fromLatin1("m/m/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
}else if (unit == Unit::SpecificHeat){
|
}
|
||||||
|
else if (unit == Unit::SpecificHeat) {
|
||||||
unitString = QString::fromLatin1("J/kg/K");
|
unitString = QString::fromLatin1("J/kg/K");
|
||||||
factor = 1000000.0;
|
factor = 1000000.0;
|
||||||
}else if (unit == Unit::ThermalTransferCoefficient){
|
}
|
||||||
|
else if (unit == Unit::ThermalTransferCoefficient) {
|
||||||
unitString = QString::fromLatin1("W/m^2/K");
|
unitString = QString::fromLatin1("W/m^2/K");
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
// default action for all cases without special treatment:
|
// default action for all cases without special treatment:
|
||||||
unitString = quant.getUnit().getString();
|
unitString = quant.getUnit().getString();
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||||
QLocale Lc = QLocale::system();
|
QLocale Lc = QLocale::system();
|
||||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||||
|
|
|
@ -39,7 +39,6 @@ class UnitsSchemaMKS: public UnitsSchema
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user