KUnitConversion 5.109.0
converter.h
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
34class KUNITCONVERSION_EXPORT Converter
35{
36public:
49 Converter(const Converter &other);
50
55
56 // TODO KF6 de-inline
57#ifdef Q_COMPILER_RVALUE_REFS
62 Converter &operator=(Converter &&other)
63 {
64 swap(other);
65 return *this;
66 }
67#endif
68
69 // TODO KF6 remove
73 void swap(Converter &other)
74 {
75 d.swap(other.d);
76 }
77
78#if KUNITCONVERSION_ENABLE_DEPRECATED_SINCE(5, 91)
83 KUNITCONVERSION_DEPRECATED_VERSION(5, 91, "result is always true")
84 bool operator==(const Converter &other) const;
85
90 KUNITCONVERSION_DEPRECATED_VERSION(5, 91, "result is always false")
91 bool operator!=(const Converter &other) const;
92#endif
93
101 Value convert(const Value &value, const QString &toUnit = QString()) const;
102 Value convert(const Value &value, UnitId toUnit) const;
103 Value convert(const Value &value, const Unit &toUnit) const;
104
111 UnitCategory categoryForUnit(const QString &unit) const;
112
119 Unit unit(const QString &unitString) const;
120
127 Unit unit(UnitId unitId) const;
128
135 UnitCategory category(const QString &category) const;
136
143 UnitCategory category(CategoryId categoryId) const;
144
150 QList<UnitCategory> categories() const;
151
152private:
153 QExplicitlySharedDataPointer<ConverterPrivate> d;
154};
155
156} // KUnitConversion namespace
157
158#endif
Class for converting values between units of measurement.
Definition converter.h:35
QList< UnitCategory > categories() const
Returns a list of all unit categories.
Value convert(const Value &value, const QString &toUnit=QString()) const
Convert value to another unit.
Unit unit(UnitId unitId) const
Find unit for unit enum.
void swap(Converter &other)
Swaps this Converter with other.
Definition converter.h:73
Converter & operator=(const Converter &other)
Assignment operator, assign other to this.
Converter()
Creates a Converter instance.
~Converter()
Destroys this Converter instance.
UnitCategory categoryForUnit(const QString &unit) const
Find unit category for unit.
UnitCategory category(CategoryId categoryId) const
Find unit category.
Unit unit(const QString &unitString) const
Find unit for string unit.
UnitCategory category(const QString &category) const
Find unit category.
Converter(const Converter &other)
Copy constructor.
Class to define a category of units of measurement.
Definition unitcategory.h:35
Class to define a unit of measurement.
Definition unit.h:758
Class to hold a value in a unit of measurement.
Definition value.h:36