KUnitConversion::UnitCategory Class
class KUnitConversion::UnitCategoryClass 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) |
Public Functions
UnitCategory() | |
QStringList | allUnits() 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 | defaultUnit() const |
QString | description() const |
bool | hasOnlineConversionTable() const |
bool | hasUnit(const QString &unit) const |
KUnitConversion::CategoryId | id() const |
bool | isNull() const |
QList<KUnitConversion::Unit> | mostCommonUnits() const |
QString | name() const |
(since 6.0) KUnitConversion::UpdateJob * | syncConversionTable(std::chrono::seconds updateSkipPeriod = std::chrono::hours(24)) |
KUnitConversion::Unit | unit(KUnitConversion::UnitId unitId) const |
KUnitConversion::Unit | unit(const QString &s) const |
QList<KUnitConversion::Unit> | units() const |
bool | operator==(const KUnitConversion::UnitCategory &other) const |
Detailed Description
This is a class to define a category of units of measurement.
See also Converter, Unit, and 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
This function overloads UnitCategory::convert().
Convert value to another unit selected by enum.
value value to convert
toUnit unit to convert to.
Returns converted value
KUnitConversion::Value UnitCategory::convert(const KUnitConversion::Value &value, const KUnitConversion::Unit &toUnit) const
This function overloads UnitCategory::convert().
Convert value to another unit.
value value to convert
toUnit unit to be used for conversion
Returns converted value
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 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.