Commit 4b69460c authored by DonLakeFlyer's avatar DonLakeFlyer

Allow translation of cm/px units

parent 98db1bee
......@@ -28,8 +28,9 @@ const qreal FactMetaData::UnitConsts_s::secondsPerHour = 3600.0;
const qreal FactMetaData::UnitConsts_s::knotsToKPH = 1.852; // exact, hence weird base for knotsToMetersPerSecond
// Length
const qreal FactMetaData::UnitConsts_s::milesToMeters = 1609.344;
const qreal FactMetaData::UnitConsts_s::feetToMeters = 0.3048;
const qreal FactMetaData::UnitConsts_s::milesToMeters = 1609.344;
const qreal FactMetaData::UnitConsts_s::feetToMeters = 0.3048;
const qreal FactMetaData::UnitConsts_s::inchesToCentimeters = 2.54;
// Built in translations for all Facts
const FactMetaData::BuiltInTranslation_s FactMetaData::_rgBuiltInTranslations[] = {
......@@ -42,10 +43,12 @@ const FactMetaData::BuiltInTranslation_s FactMetaData::_rgBuiltInTranslations[]
const FactMetaData::AppSettingsTranslation_s FactMetaData::_rgAppSettingsTranslations[] = {
{ "m", "m", false, UnitsSettings::DistanceUnitsMeters, FactMetaData::_defaultTranslator, FactMetaData::_defaultTranslator },
{ "meters", "meters", false, UnitsSettings::DistanceUnitsMeters, FactMetaData::_defaultTranslator, FactMetaData::_defaultTranslator },
{ "cm/px", "cm/px", false, UnitsSettings::DistanceUnitsMeters, FactMetaData::_defaultTranslator, FactMetaData::_defaultTranslator },
{ "m/s", "m/s", true, UnitsSettings::SpeedUnitsMetersPerSecond, FactMetaData::_defaultTranslator, FactMetaData::_defaultTranslator },
{ "m^2", "m^2", false, UnitsSettings::AreaUnitsSquareMeters, FactMetaData::_defaultTranslator, FactMetaData::_defaultTranslator },
{ "m", "ft", false, UnitsSettings::DistanceUnitsFeet, FactMetaData::_metersToFeet, FactMetaData::_feetToMeters },
{ "meters", "ft", false, UnitsSettings::DistanceUnitsFeet, FactMetaData::_metersToFeet, FactMetaData::_feetToMeters },
{ "cm/px", "in/px", false, UnitsSettings::DistanceUnitsFeet, FactMetaData::_centimetersToInches, FactMetaData::_inchesToCentimeters },
{ "m^2", "km^2", false, UnitsSettings::AreaUnitsSquareKilometers, FactMetaData::_squareMetersToSquareKilometers, FactMetaData::_squareKilometersToSquareMeters },
{ "m^2", "ha", false, UnitsSettings::AreaUnitsHectares, FactMetaData::_squareMetersToHectares, FactMetaData::_hectaresToSquareMeters },
{ "m^2", "ft^2", false, UnitsSettings::AreaUnitsSquareFeet, FactMetaData::_squareMetersToSquareFeet, FactMetaData::_squareFeetToSquareMeters },
......@@ -552,6 +555,16 @@ QVariant FactMetaData::_normToPercent(const QVariant& normalized)
return QVariant(normalized.toDouble() * 100.0);
}
QVariant FactMetaData::_centimetersToInches(const QVariant& centimeters)
{
return QVariant(centimeters.toDouble() * 1.0/constants.inchesToCentimeters);
}
QVariant FactMetaData::_inchesToCentimeters(const QVariant& inches)
{
return QVariant(inches.toDouble() * constants.inchesToCentimeters);
}
void FactMetaData::setRawUnits(const QString& rawUnits)
{
_rawUnits = rawUnits;
......
......@@ -175,6 +175,8 @@ private:
static QVariant _knotsToMetersPerSecond(const QVariant& knots);
static QVariant _percentToNorm(const QVariant& percent);
static QVariant _normToPercent(const QVariant& normalized);
static QVariant _centimetersToInches(const QVariant& centimeters);
static QVariant _inchesToCentimeters(const QVariant& inches);
struct AppSettingsTranslation_s {
const char* rawUnits;
......@@ -218,6 +220,7 @@ private:
static const qreal knotsToKPH;
static const qreal milesToMeters;
static const qreal feetToMeters;
static const qreal inchesToCentimeters;
} constants;
struct BuiltInTranslation_s {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment