KUnitConversion::Converter Class

class KUnitConversion::Converter

Class for converting values between units of measurement. More...

Header: #include <Converter>
CMake: find_package(KF6 REQUIRED COMPONENTS UnitConversion)
target_link_libraries(mytarget PRIVATE KF6::UnitConversion)

Public Functions

Converter()
QList<KUnitConversion::UnitCategory> categories() const
KUnitConversion::UnitCategory category(KUnitConversion::CategoryId categoryId) const
KUnitConversion::UnitCategory category(const QString &category) const
KUnitConversion::UnitCategory categoryForUnit(const QString &unit) const
KUnitConversion::Value convert(const KUnitConversion::Value &value, const QString &toUnit = QString()) const
KUnitConversion::Value convert(const KUnitConversion::Value &value, KUnitConversion::UnitId toUnit) const
KUnitConversion::Value convert(const KUnitConversion::Value &value, const KUnitConversion::Unit &toUnit) const
KUnitConversion::Unit unit(KUnitConversion::UnitId unitId) const
KUnitConversion::Unit unit(const QString &unitString) const

Detailed Description

This is a class to convert values between different units of measurement.

See also Unit, UnitCategory, and Value.

Member Function Documentation

Converter::Converter()

Creates a Converter instance.

QList<KUnitConversion::UnitCategory> Converter::categories() const

Returns a list of all unit categories.

KUnitConversion::UnitCategory Converter::category(KUnitConversion::CategoryId categoryId) const

Find unit category.

categoryId id of the category to find (LengthCategory, AreaCategory, etc.).

Returns unit category which id is categoryId or invalid category.

KUnitConversion::UnitCategory Converter::category(const QString &category) const

Find unit category.

category name of the category to find (length, area, mass, etc.).

Returns unit category named category or invalid category.

KUnitConversion::UnitCategory Converter::categoryForUnit(const QString &unit) const

Find unit category for unit.

unit unit to find category for.

Returns unit category for unit

KUnitConversion::Value Converter::convert(const KUnitConversion::Value &value, const QString &toUnit = QString()) const

Convert value to another unit.

value value to convert

toUnit unit to convert to. If empty default unit is used.

Returns converted value

KUnitConversion::Value Converter::convert(const KUnitConversion::Value &value, KUnitConversion::UnitId toUnit) const

This function overloads Converter::convert().

KUnitConversion::Value Converter::convert(const KUnitConversion::Value &value, const KUnitConversion::Unit &toUnit) const

This function overloads Converter::convert().

KUnitConversion::Unit Converter::unit(KUnitConversion::UnitId unitId) const

Find unit for unit enum.

unitId unit enum to find unit for.

Returns unit for string unit

KUnitConversion::Unit Converter::unit(const QString &unitString) const

Find unit for string unit.

unitString unit string to find unit for.

Returns unit for string unit