QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RUnit Class Reference

Conversion methods for units. More...

#include <RUnit.h>

Static Public Member Functions

static RVector convert (const RVector &value, RS::Unit source, RS::Unit dest)
 
static double convert (double value, RS::Unit source, RS::Unit dest)
 
static QString doubleToString (double value, double prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false, char decimalSeparator=RDEFAULT_DOT)
 Converts a double into a string which is as short as possible.
 
static QString doubleToString (double value, int prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false, char decimalSeparator=RDEFAULT_DOT)
 Converts a double into a string which is as short as possible.
 
static QString doubleToStringDec (double value, int prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false, char decimalSeparator=RDEFAULT_DOT)
 
static QString formatAngle (double angle, RS::AngleFormat format, int prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false, char decimalSeparator=RDEFAULT_DOT)
 Formats the given angle with the given format.
 
static QString formatArchitectural (double length, RS::Unit unit, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false)
 Formats the given length in architectural format (e.g.
 
static QString formatDecimal (double length, RS::Unit unit, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false, char decimalSeparator=RDEFAULT_DOT)
 Formats the given length in decimal (normal) format (e.g.
 
static QString formatEngineering (double length, RS::Unit unit, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false)
 Formats the given length in engineering format (e.g.
 
static QString formatFractional (double length, RS::Unit unit, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false)
 Formats the given length in fractional format (e.g.
 
static QString formatLinear (double length, RS::Unit unit, RS::LinearFormat format, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false, char decimalSeparator=RDEFAULT_DOT)
 Formats the given length in the given format.
 
static QString formatScientific (double length, RS::Unit unit, int prec, bool showUnit=false, bool showLeadingZeroes=true, bool showTrailingZeroes=false, bool onlyPreciseResult=false)
 Formats the given length in scientific format (e.g.
 
static double getFactorToM (RS::Unit unit)
 
static QString getLabel (double v, RDocument &document, int precisionOverride=RDEFAULT_MIN1, bool forceSuppressTrailingZeroes=false, bool onlyPreciseResult=false, char decimalSeparator=RDEFAULT_DOT)
 Copyright (c) 2011-2018 by Andrew Mustun.
 
static bool isMetric (RS::Unit unit)
 
static RS::Unit parseUnit (const QString &str)
 
static QString unitToName (RS::Unit unit, bool tr=true)
 
static QString unitToSymbol (RS::Unit unit, bool asText=false)
 

Detailed Description

Conversion methods for units.

Scriptable:\nThis class is available in script environments.\n

Member Function Documentation

◆ convert() [1/2]

RVector RUnit::convert ( const RVector & value,
RS::Unit source,
RS::Unit dest )
static

◆ convert() [2/2]

double RUnit::convert ( double value,
RS::Unit source,
RS::Unit dest )
static

◆ doubleToString() [1/2]

QString RUnit::doubleToString ( double value,
double prec,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
char decimalSeparator = RDEFAULT_DOT )
static

Converts a double into a string which is as short as possible.

Parameters
valueThe double value
precPrecision e.g. a precision of 1 would mean that a value of 2.12030 will be converted to "2.1". 2.000 is always just "2").

◆ doubleToString() [2/2]

QString RUnit::doubleToString ( double value,
int prec,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
char decimalSeparator = RDEFAULT_DOT )
static

Converts a double into a string which is as short as possible.

Parameters
valueThe double value
precPrecision

◆ doubleToStringDec()

static QString RUnit::doubleToStringDec ( double value,
int prec,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
char decimalSeparator = RDEFAULT_DOT )
inlinestatic

◆ formatAngle()

QString RUnit::formatAngle ( double angle,
RS::AngleFormat format,
int prec,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
char decimalSeparator = RDEFAULT_DOT )
static

Formats the given angle with the given format.

Parameters
angleThe angle (always in rad).
formatFormat of the string.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125)

\ret String with the formatted angle.

◆ formatArchitectural()

QString RUnit::formatArchitectural ( double length,
RS::Unit unit,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false )
static

Formats the given length in architectural format (e.g.

5' 4 1/2").

Parameters
lengthThe length in the current unit of the drawing.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125) &
showUnitAppend unit to the value.

◆ formatDecimal()

QString RUnit::formatDecimal ( double length,
RS::Unit unit,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false,
char decimalSeparator = RDEFAULT_DOT )
static

Formats the given length in decimal (normal) format (e.g.

2.5).

Parameters
lengthThe length in the current unit of the drawing.
precPrecision of the value (e.g. 0.001) &
showUnitAppend unit to the value.

◆ formatEngineering()

QString RUnit::formatEngineering ( double length,
RS::Unit unit,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false )
static

Formats the given length in engineering format (e.g.

5' 4.5").

Parameters
lengthThe length in the current unit of the drawing.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125) &
showUnitAppend unit to the value.

◆ formatFractional()

QString RUnit::formatFractional ( double length,
RS::Unit unit,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false )
static

Formats the given length in fractional format (e.g.

3 1/64).

Parameters
lengthThe length in the current unit of the drawing.
unitShould be inches.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125) &
showUnitAppend unit to the value.

◆ formatLinear()

QString RUnit::formatLinear ( double length,
RS::Unit unit,
RS::LinearFormat format,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false,
char decimalSeparator = RDEFAULT_DOT )
static

Formats the given length in the given format.

Parameters
lengthThe length in the current unit of the drawing.
formatFormat of the string.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125) &
showUnitAppend unit to the value.

◆ formatScientific()

QString RUnit::formatScientific ( double length,
RS::Unit unit,
int prec,
bool showUnit = false,
bool showLeadingZeroes = true,
bool showTrailingZeroes = false,
bool onlyPreciseResult = false )
static

Formats the given length in scientific format (e.g.

2.5E7).

Parameters
lengthThe length in the current unit of the drawing.
precPrecision of the value (e.g. 0.001 or 1/128 = 0.0078125) &
showUnitAppend unit to the value.

◆ getFactorToM()

double RUnit::getFactorToM ( RS::Unit unit)
static

◆ getLabel()

QString RUnit::getLabel ( double v,
RDocument & document,
int precisionOverride = RDEFAULT_MIN1,
bool forceSuppressTrailingZeroes = false,
bool onlyPreciseResult = false,
char decimalSeparator = RDEFAULT_DOT )
static

Copyright (c) 2011-2018 by Andrew Mustun.

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD.

Returns
A presentable label for the given value. The number locale is used to determine if the decimal point is a dot or a comma.
See also
RSettings::getNumberLocale()

◆ isMetric()

bool RUnit::isMetric ( RS::Unit unit)
static

◆ parseUnit()

RS::Unit RUnit::parseUnit ( const QString & str)
static

◆ unitToName()

QString RUnit::unitToName ( RS::Unit unit,
bool tr = true )
static
Returns
a string representing the given unit (e.g. "Millimeter"). translated if tr is true (the default).

◆ unitToSymbol()

QString RUnit::unitToSymbol ( RS::Unit unit,
bool asText = false )
static
Returns
a short string representing the given unit (e.g. "mm" or """)

The documentation for this class was generated from the following files: