improve whitespaces, fix typos

This commit is contained in:
wmayer 2016-08-05 10:00:12 +02:00
parent 7e310b2444
commit 5cb8873794
8 changed files with 263 additions and 189 deletions

View File

@ -27,14 +27,12 @@
#include <string>
#include <QString>
#include "Quantity.h"
//#include "UnitsApi.h"
#include <Base/Quantity.h>
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;
};

View File

@ -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);

View File

@ -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());

View File

@ -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
@ -42,11 +42,10 @@ public:
//virtual void setSchemaUnits(void);
//virtual void resetSchemaUnits(void);
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
@ -55,11 +54,10 @@ public:
//virtual void setSchemaUnits(void);
//virtual void resetSchemaUnits(void);
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
@ -68,7 +66,6 @@ public:
//virtual void setSchemaUnits(void);
//virtual void resetSchemaUnits(void);
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
};

View File

@ -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
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 < 10000.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){
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 < 10000.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) {
// 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){
}
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){
}
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){
}
else if (unit == Unit::Density) {
if (UnitValue < 0.0001) {
unitString = QString::fromLatin1("kg/m^3");
factor = 0.000000001;
}else if(UnitValue < 1.0){
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("kg/cm^3");
factor = 0.001;
}else{
}
else {
unitString = QString::fromLatin1("kg/mm^3");
factor = 1.0;
}
}else if (unit == Unit::ThermalConductivity){
if (UnitValue < 1000){
}
else if (unit == Unit::ThermalConductivity) {
if (UnitValue < 1000) {
unitString = QString::fromLatin1("W/mm/K");
factor = 1.0;
}else{
}
else {
unitString = QString::fromLatin1("W/m/K");
factor = 1000.0;
}
}else if (unit == Unit::ThermalExpansionCoefficient){
if(UnitValue < 0.001){
}
else if (unit == Unit::ThermalExpansionCoefficient) {
if (UnitValue < 0.001) {
unitString = QString::fromLatin1("um/m/K");
factor = 0.000001;
}else{
}
else {
unitString = QString::fromLatin1("mm/mm/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 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 -> scientific notation
}
else { // bigger -> scientific notation
unitString = QString::fromLatin1("Pa");
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);
QLocale Lc = QLocale::system();
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);

View File

@ -41,101 +41,127 @@ QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QStr
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
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){
}
else if (unit == Unit::ThermalConductivity) {
if (UnitValue < 1000) {
unitString = QString::fromLatin1("W/mm/K");
factor = 1.0;
}else{
}
else {
unitString = QString::fromLatin1("W/m/K");
factor = 1000.0;
}
}else if (unit == Unit::ThermalExpansionCoefficient){
if(UnitValue < 0.001){
}
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);
QLocale Lc = QLocale::system();
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);

View File

@ -39,7 +39,6 @@ class UnitsSchemaMKS: public UnitsSchema
{
public:
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
};