From 5cb8873794efefa67a42778cb221dd1f8dc10d29 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 5 Aug 2016 10:00:12 +0200 Subject: [PATCH] improve whitespaces, fix typos --- src/Base/UnitsSchema.h | 16 ++- src/Base/UnitsSchemaCentimeters.cpp | 12 +- src/Base/UnitsSchemaImperial1.cpp | 101 ++++++++++------ src/Base/UnitsSchemaImperial1.h | 15 +-- src/Base/UnitsSchemaInternal.cpp | 173 ++++++++++++++++------------ src/Base/UnitsSchemaInternal.h | 2 +- src/Base/UnitsSchemaMKS.cpp | 130 ++++++++++++--------- src/Base/UnitsSchemaMKS.h | 3 +- 8 files changed, 263 insertions(+), 189 deletions(-) diff --git a/src/Base/UnitsSchema.h b/src/Base/UnitsSchema.h index 674ab882a..0e7d8842c 100644 --- a/src/Base/UnitsSchema.h +++ b/src/Base/UnitsSchema.h @@ -27,14 +27,12 @@ #include #include -#include "Quantity.h" - -//#include "UnitsApi.h" +#include namespace Base { -/** Units systems*/ +/** Units systems */ enum UnitSystem { SI1 = 0 , /** internal (mm,kg,s) SI system (http://en.wikipedia.org/wiki/International_System_of_Units) */ SI2 = 1 , /** MKS (m,kg,s) SI system */ @@ -53,15 +51,15 @@ class UnitsSchema { public: virtual ~UnitsSchema(){} - /** get called if this schema gets activated. - * Here its theoretical possible that you can change the static factors - * for certain Units (e.g. mi = 1,8km instead of mi=1.6km). + /** Gets called if this schema gets activated. + * 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). */ 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){} - /// 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; }; diff --git a/src/Base/UnitsSchemaCentimeters.cpp b/src/Base/UnitsSchemaCentimeters.cpp index 14f34c82c..2e4b34f5a 100644 --- a/src/Base/UnitsSchemaCentimeters.cpp +++ b/src/Base/UnitsSchemaCentimeters.cpp @@ -39,23 +39,27 @@ using namespace Base; QString UnitsSchemaCentimeters::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString) { Unit unit = quant.getUnit(); - if(unit == Unit::Length){ + if (unit == Unit::Length) { // all length units in centimeters unitString = QString::fromLatin1("cm"); factor = 10.0; - }else if (unit == Unit::Area){ + } + else if (unit == Unit::Area) { // all area units in square meters unitString = QString::fromLatin1("m^2"); factor = 1000000.0; - }else if (unit == Unit::Volume){ + } + else if (unit == Unit::Volume) { // all area units in cubic meters unitString = QString::fromLatin1("m^3"); factor = 1000000000.0; - }else{ + } + else { // default action for all cases without special treatment: unitString = quant.getUnit().getString(); factor = 1.0; } + //return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString); QLocale Lc = QLocale::system(); Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator); diff --git a/src/Base/UnitsSchemaImperial1.cpp b/src/Base/UnitsSchemaImperial1.cpp index 099ce7156..f4a476a40 100644 --- a/src/Base/UnitsSchemaImperial1.cpp +++ b/src/Base/UnitsSchemaImperial1.cpp @@ -66,60 +66,73 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto // mm/kg/s. And all combined units have to be calculated from there! // now do special treatment on all cases seems necessary: - if(unit == Unit::Length){ // Length handling ============================ - if(UnitValue < 0.00000254){// smaller then 0.001 thou -> inch and scientific notation + if (unit == Unit::Length) { // Length handling ============================ + if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation unitString = QString::fromLatin1("in"); 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"); factor = 0.0254; - }else if(UnitValue < 304.8){ + } + else if(UnitValue < 304.8) { unitString = QString::fromLatin1("\""); factor = 25.4; - }else if(UnitValue < 914.4){ + } + else if(UnitValue < 914.4) { unitString = QString::fromLatin1("\'"); factor = 304.8; }else if(UnitValue < 1609344.0){ unitString = QString::fromLatin1("yd"); factor = 914.4; - }else if(UnitValue < 1609344000.0 ){ + } + else if(UnitValue < 1609344000.0) { unitString = QString::fromLatin1("mi"); factor = 1609344.0; - }else{ // bigger then 1000 mi -> scientific notation + } + else { // bigger then 1000 mi -> scientific notation unitString = QString::fromLatin1("in"); factor = 25.4; } - }else if (unit == Unit::Area){ + } + else if (unit == Unit::Area) { // TODO Cascade for the Areas // default action for all cases without special treatment: unitString = QString::fromLatin1("in^2"); factor = 645.16; - }else if (unit == Unit::Volume){ + } + else if (unit == Unit::Volume) { // TODO Cascade for the Volume // default action for all cases without special treatment: unitString = QString::fromLatin1("in^3"); factor = 16387.064; - }else if (unit == Unit::Mass){ + } + else if (unit == Unit::Mass) { // TODO Cascade for the wights // default action for all cases without special treatment: unitString = QString::fromLatin1("lb"); factor = 0.45359237; - }else if (unit == Unit::Pressure){ - if(UnitValue < 145.038){// psi is the smallest - unitString = QString::fromLatin1("psi"); - factor = 0.145038; - }else if(UnitValue < 145038){ - unitString = QString::fromLatin1("ksi"); - factor = 145.038; - }else{ // bigger then 1000 ksi -> psi + scientific notation + } + else if (unit == Unit::Pressure) { + if (UnitValue < 145.038) {// psi is the smallest unitString = QString::fromLatin1("psi"); factor = 0.145038; } - }else{ + else if (UnitValue < 145038) { + unitString = QString::fromLatin1("ksi"); + factor = 145.038; + } + else { // bigger then 1000 ksi -> psi + scientific notation + unitString = QString::fromLatin1("psi"); + factor = 0.145038; + } + } + else{ // default action for all cases without special treatment: unitString = quant.getUnit().getString(); factor = 1.0; } + //return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString); QLocale Lc = QLocale::system(); 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); } - - - QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString) { double UnitValue = std::abs(quant.getValue()); @@ -138,48 +148,56 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double // mm/kg/s. And all combined units have to be calculated from there! // now do special treatment on all cases seems necessary: - if(unit == Unit::Length){ // Length handling ============================ - if(UnitValue < 0.00000254){// smaller then 0.001 thou -> inch and scientific notation + if (unit == Unit::Length) { // Length handling ============================ + if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation unitString = QString::fromLatin1("in"); factor = 25.4; //}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil) // unitString = QString::fromLatin1("thou"); // factor = 0.0254; - }else{ // bigger then 1000 mi -> scientific notation + } + else { // bigger then 1000 mi -> scientific notation unitString = QString::fromLatin1("in"); factor = 25.4; } - }else if (unit == Unit::Area){ + } + else if (unit == Unit::Area) { // TODO Cascade for the Areas // default action for all cases without special treatment: unitString = QString::fromLatin1("in^2"); factor = 645.16; - }else if (unit == Unit::Volume){ + } + else if (unit == Unit::Volume) { // TODO Cascade for the Volume // default action for all cases without special treatment: unitString = QString::fromLatin1("in^3"); factor = 16387.064; - }else if (unit == Unit::Mass){ + } + else if (unit == Unit::Mass) { // TODO Cascade for the wights // default action for all cases without special treatment: unitString = QString::fromLatin1("lb"); factor = 0.45359237; - }else if (unit == Unit::Pressure){ - if(UnitValue < 145.038){// psi is the smallest + } + else if (unit == Unit::Pressure) { + if (UnitValue < 145.038) {// psi is the smallest unitString = QString::fromLatin1("psi"); factor = 0.145038; //}else if(UnitValue < 145038){ // unitString = QString::fromLatin1("ksi"); // factor = 145.038; - }else{ // bigger then 1000 ksi -> psi + scientific notation + } + else { // bigger then 1000 ksi -> psi + scientific notation unitString = QString::fromLatin1("psi"); factor = 0.145038; } - }else{ + } + else { // default action for all cases without special treatment: unitString = quant.getUnit().getString(); factor = 1.0; } + //return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString); QLocale Lc = QLocale::system(); Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator); @@ -187,14 +205,12 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString); } - - QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString) { // this schema expresses distances in feet + inches + fractions // ex: 3'- 4 1/4" Unit unit = quant.getUnit(); - if(unit == Unit::Length){ + if (unit == Unit::Length) { unitString = QString::fromLatin1("in"); factor = 25.4; double inchValue = std::abs(quant.getValue())/25.4; @@ -206,19 +222,23 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double inches++; fraction = 0.0; } + // if the quantity is too small it is rounded to zero if (std::abs(quant.getValue()) <= 1.5875) return QString::fromLatin1("0"); + // build representation std::stringstream output; if (quant.getValue() < 0) output << "-"; + // feet if (feet > 0) { output << feet << "'"; if ( (inches > 0) || (fraction > 0.0625) ) output << " "; } + // inches if (inches > 0) { output << inches; @@ -227,6 +247,7 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double else output << "\""; } + // fraction if (fraction <= 0.0625) {} else if (fraction > 0.8125) @@ -244,16 +265,20 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double else output << "1/8\""; return QString::fromLatin1(output.str().c_str()); - }else if (unit == Unit::Area){ + } + else if (unit == Unit::Area) { unitString = QString::fromLatin1("sqft"); factor = 92903.04; - }else if (unit == Unit::Volume){ + } + else if (unit == Unit::Volume) { unitString = QString::fromLatin1("cuft"); factor = 28316846.592; - }else{ + } + else { unitString = quant.getUnit().getString(); factor = 1.0; } + QLocale Lc = QLocale::system(); Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator); QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals()); diff --git a/src/Base/UnitsSchemaImperial1.h b/src/Base/UnitsSchemaImperial1.h index 48a939e2a..214ec4a2a 100644 --- a/src/Base/UnitsSchemaImperial1.h +++ b/src/Base/UnitsSchemaImperial1.h @@ -33,7 +33,7 @@ namespace Base { /** 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. */ class UnitsSchemaImperial1: public UnitsSchema @@ -41,12 +41,11 @@ class UnitsSchemaImperial1: public UnitsSchema public: //virtual void setSchemaUnits(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 - * 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. */ class UnitsSchemaImperialDecimal: public UnitsSchema @@ -54,12 +53,11 @@ class UnitsSchemaImperialDecimal: public UnitsSchema public: //virtual void setSchemaUnits(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 - * 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. */ class UnitsSchemaImperialBuilding: public UnitsSchema @@ -67,8 +65,7 @@ class UnitsSchemaImperialBuilding: public UnitsSchema public: //virtual void setSchemaUnits(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); }; diff --git a/src/Base/UnitsSchemaInternal.cpp b/src/Base/UnitsSchemaInternal.cpp index 52ec0c480..f80d2fca0 100644 --- a/src/Base/UnitsSchemaInternal.cpp +++ b/src/Base/UnitsSchemaInternal.cpp @@ -42,100 +42,125 @@ QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant,double &factor double UnitValue = std::abs(quant.getValue()); Unit unit = quant.getUnit(); - // now do special treatment on all cases seams nececarry: - if(unit == Unit::Length){ // Length handling ============================ - if(UnitValue < 0.000000001){// smaller then 0.001 nm -> scientific notation + // now do special treatment on all cases seems necessary: + if (unit == Unit::Length) { // Length handling ============================ + if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation unitString = QString::fromLatin1("mm"); factor = 1.0; - }else if(UnitValue < 0.001){ + } + else if(UnitValue < 0.001) { unitString = QString::fromLatin1("nm"); factor = 0.000001; - }else if(UnitValue < 0.1){ + } + else if (UnitValue < 0.1) { unitString = QString::fromUtf8("\xC2\xB5m"); factor = 0.001; - }else if(UnitValue < 10000.0){ + } + else if (UnitValue < 10000.0) { unitString = QString::fromLatin1("mm"); factor = 1.0; - }else if(UnitValue < 10000000.0){ + } + else if (UnitValue < 10000000.0) { unitString = QString::fromLatin1("m"); factor = 1000.0; - }else if(UnitValue < 100000000000.0 ){ + } + else if (UnitValue < 100000000000.0) { unitString = QString::fromLatin1("km"); factor = 1000000.0; - }else{ // bigger then 1000 km -> scientific notation + } + else { // bigger then 1000 km -> scientific notation unitString = QString::fromLatin1("mm"); factor = 1.0; } - }else if (unit == Unit::Area){ + } + else if (unit == Unit::Area) { // TODO Cascade for the Areas // default action for all cases without special treatment: unitString = quant.getUnit().getString(); factor = 1.0; - }else if (unit == Unit::Angle){ - // TODO Cascade for the Areas - // default action for all cases without special treatment: - unitString = QString::fromUtf8("\xC2\xB0"); - factor = 1.0; - }else if (unit == Unit::Mass){ - // TODO Cascade for the wights - // default action for all cases without special treatment: - unitString = quant.getUnit().getString(); - factor = 1.0; - }else if (unit == Unit::Density){ - if(UnitValue < 0.0001){ - unitString = QString::fromLatin1("kg/m^3"); - factor = 0.000000001; - }else if(UnitValue < 1.0){ - unitString = QString::fromLatin1("kg/cm^3"); - factor = 0.001; - }else{ - unitString = QString::fromLatin1("kg/mm^3"); - factor = 1.0; - } - }else if (unit == Unit::ThermalConductivity){ - if (UnitValue < 1000){ - unitString = QString::fromLatin1("W/mm/K"); - factor = 1.0; - }else{ - unitString = QString::fromLatin1("W/m/K"); - factor = 1000.0; - } - }else if (unit == Unit::ThermalExpansionCoefficient){ - if(UnitValue < 0.001){ - unitString = QString::fromLatin1("um/m/K"); - factor = 0.000001; - }else{ - unitString = QString::fromLatin1("mm/mm/K"); - factor = 1.0; - } - }else if (unit == Unit::SpecificHeat){ - unitString = QString::fromLatin1("J/kg/K"); - factor = 1000000.0; - }else if (unit == Unit::ThermalTransferCoefficient){ - unitString = QString::fromLatin1("W/m^2/K"); - factor = 1.0; - }else if ((unit == Unit::Pressure) || (unit == Unit::Stress)){ - if(UnitValue < 10.0){// Pa is the smallest - unitString = QString::fromLatin1("Pa"); - factor = 0.001; - }else if(UnitValue < 10000.0){ - unitString = QString::fromLatin1("kPa"); - factor = 1.0; - }else if(UnitValue < 10000000.0){ - unitString = QString::fromLatin1("MPa"); - factor = 1000.0; - }else if(UnitValue < 10000000000.0){ - unitString = QString::fromLatin1("GPa"); - factor = 1000000.0; - }else{ // bigger -> scientific notation - unitString = QString::fromLatin1("Pa"); - factor = 1.0; - } - }else{ - // default action for all cases without special treatment: - unitString = quant.getUnit().getString(); - factor = 1.0; } + else if (unit == Unit::Angle) { + // TODO Cascade for the Areas + // default action for all cases without special treatment: + unitString = QString::fromUtf8("\xC2\xB0"); + factor = 1.0; + } + else if (unit == Unit::Mass) { + // TODO Cascade for the wights + // default action for all cases without special treatment: + unitString = quant.getUnit().getString(); + factor = 1.0; + } + else if (unit == Unit::Density) { + if (UnitValue < 0.0001) { + unitString = QString::fromLatin1("kg/m^3"); + factor = 0.000000001; + } + else if (UnitValue < 1.0) { + unitString = QString::fromLatin1("kg/cm^3"); + factor = 0.001; + } + else { + unitString = QString::fromLatin1("kg/mm^3"); + factor = 1.0; + } + } + else if (unit == Unit::ThermalConductivity) { + if (UnitValue < 1000) { + unitString = QString::fromLatin1("W/mm/K"); + factor = 1.0; + } + else { + unitString = QString::fromLatin1("W/m/K"); + factor = 1000.0; + } + } + else if (unit == Unit::ThermalExpansionCoefficient) { + if (UnitValue < 0.001) { + unitString = QString::fromLatin1("um/m/K"); + factor = 0.000001; + } + else { + unitString = QString::fromLatin1("mm/mm/K"); + factor = 1.0; + } + } + else if (unit == Unit::SpecificHeat) { + unitString = QString::fromLatin1("J/kg/K"); + factor = 1000000.0; + } + else if (unit == Unit::ThermalTransferCoefficient) { + unitString = QString::fromLatin1("W/m^2/K"); + factor = 1.0; + } + else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) { + if (UnitValue < 10.0) {// Pa is the smallest + unitString = QString::fromLatin1("Pa"); + factor = 0.001; + } + else if (UnitValue < 10000.0) { + unitString = QString::fromLatin1("kPa"); + factor = 1.0; + } + else if (UnitValue < 10000000.0) { + unitString = QString::fromLatin1("MPa"); + factor = 1000.0; + } + else if (UnitValue < 10000000000.0) { + unitString = QString::fromLatin1("GPa"); + factor = 1000000.0; + } + else { // bigger -> scientific notation + unitString = QString::fromLatin1("Pa"); + factor = 1.0; + } + } + else { + // default action for all cases without special treatment: + unitString = quant.getUnit().getString(); + factor = 1.0; + } + //return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString); QLocale Lc = QLocale::system(); Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator); diff --git a/src/Base/UnitsSchemaInternal.h b/src/Base/UnitsSchemaInternal.h index e3edbce69..c37449e61 100644 --- a/src/Base/UnitsSchemaInternal.h +++ b/src/Base/UnitsSchemaInternal.h @@ -40,7 +40,7 @@ namespace Base { class UnitsSchemaInternal: public UnitsSchema { public: - virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString); + virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString); }; diff --git a/src/Base/UnitsSchemaMKS.cpp b/src/Base/UnitsSchemaMKS.cpp index a851fefa1..50b799028 100644 --- a/src/Base/UnitsSchemaMKS.cpp +++ b/src/Base/UnitsSchemaMKS.cpp @@ -39,104 +39,130 @@ using namespace Base; QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString) { double UnitValue = std::abs(quant.getValue()); - Unit unit = quant.getUnit(); + Unit unit = quant.getUnit(); - // now do special treatment on all cases seams nececarry: - if(unit == Unit::Length){ // Length handling ============================ - if(UnitValue < 0.000000001){// smaller then 0.001 nm -> scientific notation - unitString = QString::fromLatin1("mm"); - factor = 1.0; - }else if(UnitValue < 0.001){ - unitString = QString::fromLatin1("nm"); - factor = 0.000001; - }else if(UnitValue < 0.1){ - unitString = QString::fromUtf8("\xC2\xB5m"); - factor = 0.001; - }else if(UnitValue < 100.0){ - unitString = QString::fromLatin1("mm"); - 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 + // now do special treatment on all cases seems necessary: + if (unit == Unit::Length) { // Length handling ============================ + if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation unitString = QString::fromLatin1("mm"); factor = 1.0; } - }else if (unit == Unit::Area){ - if(UnitValue < 100.0){// smaller than 1 square cm + else if(UnitValue < 0.001) { + unitString = QString::fromLatin1("nm"); + factor = 0.000001; + } + else if(UnitValue < 0.1) { + unitString = QString::fromUtf8("\xC2\xB5m"); + factor = 0.001; + } + else if(UnitValue < 100.0) { + unitString = QString::fromLatin1("mm"); + 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"); + factor = 1.0; + } + } + else if (unit == Unit::Area) { + if (UnitValue < 100.0) {// smaller than 1 square cm unitString = QString::fromLatin1("mm^2"); factor = 1.0; - }else if(UnitValue < 10000000000000.0 ){ + } + else if (UnitValue < 10000000000000.0) { unitString = QString::fromLatin1("m^2"); factor = 1000000.0; - }else{ // bigger then 1 square kilometer + } + else { // bigger then 1 square kilometer unitString = QString::fromLatin1("km^2"); factor = 1000000000000.0; } - }else if (unit == Unit::Mass){ + } + else if (unit == Unit::Mass) { // TODO Cascade for the wights // default action for all cases without special treatment: unitString = quant.getUnit().getString(); factor = 1.0; - }else if (unit == Unit::Volume){ - if(UnitValue < 1000000.0){// smaller than 10 cubic cm + } + else if (unit == Unit::Volume) { + if (UnitValue < 1000000.0) {// smaller than 10 cubic cm unitString = QString::fromLatin1("mm^3"); factor = 1.0; - }else if(UnitValue < 1000000000000000000.0 ){ + } + else if (UnitValue < 1000000000000000000.0) { unitString = QString::fromLatin1("m^3"); factor = 1000000000.0; - }else{ // bigger then 1 cubic kilometer + } + else { // bigger then 1 cubic kilometer unitString = QString::fromLatin1("km^3"); factor = 1000000000000000000.0; } - }else if ((unit == Unit::Pressure) || (unit == Unit::Stress)){ - if(UnitValue < 10.0){// Pa is the smallest + } + else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) { + if (UnitValue < 10.0) {// Pa is the smallest unitString = QString::fromLatin1("Pa"); factor = 0.001; - }else if(UnitValue < 10000.0){ + } + else if (UnitValue < 10000.0) { unitString = QString::fromLatin1("kPa"); factor = 1.0; - }else if(UnitValue < 10000000.0){ + } + else if (UnitValue < 10000000.0) { unitString = QString::fromLatin1("MPa"); factor = 1000.0; - }else if(UnitValue < 10000000000.0){ + } + else if (UnitValue < 10000000000.0) { unitString = QString::fromLatin1("GPa"); factor = 1000000.0; - }else{ // bigger then 1000 GPa -> scientific notation + } + else { // bigger then 1000 GPa -> scientific notation unitString = QString::fromLatin1("Pa"); factor = 1.0; } - }else if (unit == Unit::ThermalConductivity){ - if (UnitValue < 1000){ - unitString = QString::fromLatin1("W/mm/K"); - factor = 1.0; - }else{ - unitString = QString::fromLatin1("W/m/K"); - factor = 1000.0; - } - }else if (unit == Unit::ThermalExpansionCoefficient){ - if(UnitValue < 0.001){ + } + else if (unit == Unit::ThermalConductivity) { + if (UnitValue < 1000) { + unitString = QString::fromLatin1("W/mm/K"); + factor = 1.0; + } + else { + unitString = QString::fromLatin1("W/m/K"); + factor = 1000.0; + } + } + else if (unit == Unit::ThermalExpansionCoefficient) { + if (UnitValue < 0.001) { unitString = QString::fromLatin1("um/m/K"); factor = 0.000001; - }else{ + } + else { unitString = QString::fromLatin1("m/m/K"); factor = 1.0; } - }else if (unit == Unit::SpecificHeat){ + } + else if (unit == Unit::SpecificHeat) { unitString = QString::fromLatin1("J/kg/K"); factor = 1000000.0; - }else if (unit == Unit::ThermalTransferCoefficient){ + } + else if (unit == Unit::ThermalTransferCoefficient) { unitString = QString::fromLatin1("W/m^2/K"); factor = 1.0; - }else{ + } + else { // default action for all cases without special treatment: unitString = quant.getUnit().getString(); 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(); Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator); QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals()); diff --git a/src/Base/UnitsSchemaMKS.h b/src/Base/UnitsSchemaMKS.h index 6049b36d4..19712eb2d 100644 --- a/src/Base/UnitsSchemaMKS.h +++ b/src/Base/UnitsSchemaMKS.h @@ -38,8 +38,7 @@ namespace Base { class UnitsSchemaMKS: public UnitsSchema { public: - virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString); - + virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString); };