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 * \class KUnitConversion::Converter
25 * \inmodule KUnitConversion
26 *
27 * \brief Class for converting values between units of measurement.
28 *
29 * This is a class to convert values between different units of measurement.
30 *
31 * \sa Unit, UnitCategory, Value
32 */
33class KUNITCONVERSION_EXPORT Converter
34{
35public:
36 /*!
37 * Creates a Converter instance.
38 */
39 Converter();
40
41 ~Converter();
42
43 Converter(const Converter &other);
44
45 Converter &operator=(const Converter &other);
46
47 Converter &operator=(Converter &&other);
48
49 /*!
50 * Convert value to another unit.
51 *
52 * \a value value to convert
53 *
54 * \a toUnit unit to convert to. If empty default unit is used.
55 *
56 * Returns converted value
57 **/
58 Value convert(const Value &value, const QString &toUnit = QString()) const;
59
60 /*!
61 * \overload Converter::convert()
62 */
63 Value convert(const Value &value, UnitId toUnit) const;
64
65 /*!
66 * \overload Converter::convert()
67 */
68 Value convert(const Value &value, const Unit &toUnit) const;
69
70 /*!
71 * Find unit category for unit.
72 *
73 * \a unit unit to find category for.
74 *
75 * Returns unit category for unit
76 **/
77 UnitCategory categoryForUnit(const QString &unit) const;
78
79 /*!
80 * Find unit for string unit.
81 *
82 * \a unitString unit string to find unit for.
83 *
84 * Returns unit for string unit
85 **/
86 Unit unit(const QString &unitString) const;
87
88 /*!
89 * Find unit for unit enum.
90 *
91 * \a unitId unit enum to find unit for.
92 *
93 * Returns unit for string unit
94 **/
95 Unit unit(UnitId unitId) const;
96
97 /*!
98 * Find unit category.
99 *
100 * \a category name of the category to find (length, area, mass, etc.).
101 *
102 * Returns unit category named category or invalid category.
103 **/
104 UnitCategory category(const QString &category) const;
105
106 /*!
107 * Find unit category.
108 *
109 * \a categoryId id of the category to find (LengthCategory, AreaCategory, etc.).
110 *
111 * Returns unit category which id is categoryId or invalid category.
112 **/
113 UnitCategory category(CategoryId categoryId) const;
114
115 /*!
116 * Returns a list of all 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