2
* Copyright (C) 2007-2009 Petri Damstén <damu@iki.fi>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#ifndef CONVERSION_UNIT_H
21
#define CONVERSION_UNIT_H
24
#include <QStringList>
25
#include "plasmaconversion_export.h"
32
class PLASMACONVERSION_EXPORT Complex
36
virtual ~Complex() {};
37
virtual double toDefault(double) const = 0;
38
virtual double fromDefault(double) const = 0;
41
class PLASMACONVERSION_EXPORT Unit : public QObject
44
Unit(QObject* parent = 0);
45
explicit Unit(QObject* parent, const QString& singular, const QString& plural,
46
const QString& symbol, double multiplier,
47
const QStringList& synonyms = QStringList());
48
explicit Unit(QObject* parent, const QString& singular, const QString& plural,
49
const QString& symbol, const Complex* multiplier,
50
const QStringList& synonyms = QStringList());
53
* @return translated name for unit.
55
QString singular() const;
58
* @return translated name for unit (plural).
60
QString plural() const;
63
* @return symbol for the unit.
65
QString symbol() const;
68
* @return singular or plural based on value.
70
QString toString(double value) const;
73
* @return unit multiplier.
75
double multiplier() const;
78
* Set unit multiplier.
80
void setMultiplier(double multiplier);
83
* @return unit category.
85
UnitCategory* category() const;
88
* @return if unit is valid.
93
double toDefault(double value) const;
94
double fromDefault(double value) const;
97
friend class UnitCategory;
102
#define U(n, p, s, m, sy) (new Conversion::Unit(this, n, p, s, m, QStringList() sy))
104
} // Conversion namespace