1/*
2 * SPDX-FileCopyrightText: 2008-2009 Petri Damstén <damu@iki.fi>
3 * SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#ifndef KUNITCONVERSION_CONVERTER_H
9#define KUNITCONVERSION_CONVERTER_H
10
11#include <kunitconversion/kunitconversion_export.h>
12
13#include "unitcategory.h"
14
15#include <QExplicitlySharedDataPointer>
16
17namespace KUnitConversion
18{
19class Value;
20class UnitCategory;
21class ConverterPrivate;
22
23/**
24 * @short Class for converting values between units of measurement
25 *
26 * This is a class to convert values between different units of measurement.
27 *
28 * @see Unit, UnitCategory, Value
29 *
30 * @author Petri Damstén <damu@iki.fi>
31 * @author John Layt <jlayt@kde.org>
32 */
33
34class KUNITCONVERSION_EXPORT Converter
35{
36public:
37 /**
38 * Creates a Converter instance.
39 */
40 Converter();
41 /**
42 * Destroys this Converter instance.
43 */
44 ~Converter();
45 /**
46 * Copy constructor.
47 * @param other existing Converter instance.
48 */
49 Converter(const Converter &other);
50
51 /**
52 * Assignment operator, assign @p other to this.
53 **/
54 Converter &operator=(const Converter &other);
55
56 /**
57 * Move-assigns @p other to this Converter instance, transferring the
58 * ownership of the managed pointer to this instance.
59 **/
60 Converter &operator=(Converter &&other);
61
62 /**
63 * Convert value to another unit.
64 *
65 * @param value value to convert
66 * @param toUnit unit to convert to. If empty default unit is used.
67 * @return converted value
68 **/
69 Value convert(const Value &value, const QString &toUnit = QString()) const;
70 Value convert(const Value &value, UnitId toUnit) const;
71 Value convert(const Value &value, const Unit &toUnit) const;
72
73 /**
74 * Find unit category for unit.
75 *
76 * @param unit unit to find category for.
77 * @return unit category for unit
78 **/
79 UnitCategory categoryForUnit(const QString &unit) const;
80
81 /**
82 * Find unit for string unit.
83 *
84 * @param unitString unit string to find unit for.
85 * @return unit for string unit
86 **/
87 Unit unit(const QString &unitString) const;
88
89 /**
90 * Find unit for unit enum.
91 *
92 * @param unitId unit enum to find unit for.
93 * @return unit for string unit
94 **/
95 Unit unit(UnitId unitId) const;
96
97 /**
98 * Find unit category.
99 *
100 * @param category name of the category to find (length, area, mass, etc.).
101 * @return unit category named category or invalid category.
102 **/
103 UnitCategory category(const QString &category) const;
104
105 /**
106 * Find unit category.
107 *
108 * @param categoryId id of the category to find (LengthCategory, AreaCategory, etc.).
109 * @return unit category which id is categoryId or invalid category.
110 **/
111 UnitCategory category(CategoryId categoryId) const;
112
113 /**
114 * Returns a list of all unit categories.
115 *
116 * @return list of unit categories.
117 **/
118 QList<UnitCategory> categories() const;
119
120private:
121 QExplicitlySharedDataPointer<ConverterPrivate> d;
122};
123
124} // KUnitConversion namespace
125
126#endif
127

source code of kunitconversion/src/converter.h