Pages
API Documentation
On this page

KUnitConversion::UnitCategory Class

Class to define a category of units of measurement. More...

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

List of all members, including inherited members

Public Functions

Detailed Description

This is a class to define a category of units of measurement.

See also Converter, Unit, Value

Member Function Documentation

UnitCategory::UnitCategory()

Null constructor

QStringList UnitCategory::allUnits() const

Returns all unit names, short names and unit synonyms in this category.

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

Convert value to another unit selected by string.

value value to convert

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

Returns converted value

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

Convert value to another unit selected by enum.

value value to convert

toUnit unit to convert to.

Returns converted value

This function overloads UnitCategory::convert().

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

Convert value to another unit.

value value to convert

toUnit unit to be used for conversion

Returns converted value

This function overloads UnitCategory::convert().

KUnitConversion::Unit UnitCategory::defaultUnit() const

Returns default unit.

QString UnitCategory::description() const

Returns unit category description

bool UnitCategory::hasOnlineConversionTable() const

Returns true if category has conversion table that needs to be updated via online access, otherwise false

See also syncConversionTable()

bool UnitCategory::hasUnit(const QString &unit) const

Returns if unit category has a unit.

KUnitConversion::CategoryId UnitCategory::id() const

Returns category id.

bool UnitCategory::isNull() const

Returns true if this UnitCategory is null

QList<KUnitConversion::Unit> UnitCategory::mostCommonUnits() const

Returns most common units in this category.

QString UnitCategory::name() const

Returns translated name for the unit category.

[since 6.0] KUnitConversion::UpdateJob *UnitCategory::syncConversionTable(std::chrono::seconds updateSkipPeriod = std::chrono::hours(24))

Request an update of the online conversion table when it is older than updateSkipPeriod.

Returned jobs are automatically deleted, ie. it is safe to ignore the return value if you do not care about being notified about the completion (or failure) of the update process. Calling this method while another update is already in progress will not trigger another update but instead allows you to watch the already ongoing update.

Performing conversions before the update has completed will return results based on the old conversion table, if available.

Note: This method must be called from the main thread!

Returns an UpdateJob if an update is necessary or already running, nullptr otherwise.

This function was introduced in Qt 6.0.

See also UpdateJob

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

Returns unit for unit enum.

KUnitConversion::Unit UnitCategory::unit(const QString &s) const

Returns unit for string.

QList<KUnitConversion::Unit> UnitCategory::units() const

Returns units in this category.

bool UnitCategory::operator==(const KUnitConversion::UnitCategory &other) const

Returns true if this UnitCategory is equal to the other UnitCategory.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.