KUnitConversion::UnitCategory

Search for usage in LXR

KUnitConversion::UnitCategory Class Reference

#include <unitcategory.h>

Public Member Functions

 UnitCategory ()
 
 UnitCategory (const UnitCategory &other)
 
QStringList allUnits () const
 
Value convert (const Value &value, const QString &toUnit=QString()) const
 
Value convert (const Value &value, const Unit &toUnit) const
 
Value convert (const Value &value, UnitId toUnit) const
 
Unit defaultUnit () const
 
QString description () const
 
bool hasOnlineConversionTable () const
 
bool hasUnit (const QString &unit) const
 
CategoryId id () const
 
bool isNull () const
 
QList< UnitmostCommonUnits () const
 
QString name () const
 
bool operator!= (const UnitCategory &other) const
 
UnitCategoryoperator= (const UnitCategory &other)
 
UnitCategoryoperator= (UnitCategory &&other)
 
bool operator== (const UnitCategory &other) const
 
UpdateJobsyncConversionTable (std::chrono::seconds updateSkipPeriod=std::chrono::hours(24))
 
Unit unit (const QString &s) const
 
Unit unit (UnitId unitId) const
 
QList< Unitunits () const
 

Protected Attributes

QExplicitlySharedDataPointer< UnitCategoryPrivate > d
 

Detailed Description

Class to define a category of units of measurement.

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

See also
Converter, Unit, Value
Author
Petri Damstén damu@.nosp@m.iki..nosp@m.fi
John Layt jlayt.nosp@m.@kde.nosp@m..org

Definition at line 40 of file unitcategory.h.

Constructor & Destructor Documentation

◆ UnitCategory() [1/2]

KUnitConversion::UnitCategory::UnitCategory ( )

Null constructor.

Definition at line 70 of file unitcategory.cpp.

◆ UnitCategory() [2/2]

KUnitConversion::UnitCategory::UnitCategory ( const UnitCategory & other)

Copy constructor, copy other to this.

Definition at line 80 of file unitcategory.cpp.

◆ ~UnitCategory()

KUnitConversion::UnitCategory::~UnitCategory ( )

Definition at line 85 of file unitcategory.cpp.

Member Function Documentation

◆ allUnits()

QStringList KUnitConversion::UnitCategory::allUnits ( ) const

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

Returns
list of units.

Definition at line 148 of file unitcategory.cpp.

◆ convert() [1/3]

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

Convert value to another unit selected by string.

Parameters
valuevalue to convert
toUnitunit to convert to. If empty default unit is used.
Returns
converted value

Definition at line 164 of file unitcategory.cpp.

◆ convert() [2/3]

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

Convert value to another unit.

Parameters
valuevalue to convert
toUnitunit to be used for conversion
Returns
converted value

Definition at line 181 of file unitcategory.cpp.

◆ convert() [3/3]

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

Convert value to another unit selected by enum.

Parameters
valuevalue to convert
toUnitunit to convert to.
Returns
converted value

Definition at line 173 of file unitcategory.cpp.

◆ defaultUnit()

Unit KUnitConversion::UnitCategory::defaultUnit ( ) const

Returns default unit.

Returns
default unit.

Definition at line 213 of file unitcategory.cpp.

◆ description()

QString KUnitConversion::UnitCategory::description ( ) const
Returns
unit category description

Definition at line 221 of file unitcategory.cpp.

◆ hasOnlineConversionTable()

bool KUnitConversion::UnitCategory::hasOnlineConversionTable ( ) const
Returns
true if category has conversion table that needs to be updated via online access, otherwise false
See also
syncConversionTable()

Definition at line 259 of file unitcategory.cpp.

◆ hasUnit()

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

Check if unit category has a unit.

Returns
True if unit is found

Definition at line 156 of file unitcategory.cpp.

◆ id()

CategoryId KUnitConversion::UnitCategory::id ( ) const
Returns
category id.

Definition at line 124 of file unitcategory.cpp.

◆ isNull()

bool KUnitConversion::UnitCategory::isNull ( ) const
Returns
returns true if this UnitCategory is null

Definition at line 119 of file unitcategory.cpp.

◆ mostCommonUnits()

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

Return most common units in this category.

Returns
list of units.

Definition at line 140 of file unitcategory.cpp.

◆ name()

QString KUnitConversion::UnitCategory::name ( ) const

Returns name for the unit category.

Returns
Translated name for category.

Definition at line 205 of file unitcategory.cpp.

◆ operator!=()

bool KUnitConversion::UnitCategory::operator!= ( const UnitCategory & other) const
Returns
true if this UnitCategory is not equal to the other UnitCategory.

Definition at line 110 of file unitcategory.cpp.

◆ operator=() [1/2]

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

Assignment operator, assign other to this.

Definition at line 89 of file unitcategory.cpp.

◆ operator=() [2/2]

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

Move-assigns other to this UnitCategory instance, transferring the ownership of the managed pointer to this instance.

Definition at line 95 of file unitcategory.cpp.

◆ operator==()

bool KUnitConversion::UnitCategory::operator== ( const UnitCategory & other) const
Returns
true if this UnitCategory is equal to the other UnitCategory.

Definition at line 101 of file unitcategory.cpp.

◆ syncConversionTable()

UpdateJob * KUnitConversion::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.
See also
UpdateJob
Since
6.0

Definition at line 264 of file unitcategory.cpp.

◆ unit() [1/2]

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

Return unit for string.

Returns
Pointer to unit class.

Definition at line 189 of file unitcategory.cpp.

◆ unit() [2/2]

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

Return unit for unit enum.

Returns
Pointer to unit class.

Definition at line 197 of file unitcategory.cpp.

◆ units()

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

Return units in this category.

Returns
list of units.

Definition at line 132 of file unitcategory.cpp.

Member Data Documentation

◆ d

QExplicitlySharedDataPointer<UnitCategoryPrivate> KUnitConversion::UnitCategory::d
protected

Definition at line 205 of file unitcategory.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.