Debian Codegraph @

include/util/dabstractunitformatter.h

raw
1 // SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #ifndef DABSTRACTUNITFORMATTER_H
6 #define DABSTRACTUNITFORMATTER_H
7
8 #include "dtkcore_global.h"
9
10 #include <QPair>
11 #include <QList>
12
13 DCORE_BEGIN_NAMESPACE
14
15 class LIBDTKCORESHARED_EXPORT DAbstractUnitFormatter
16 {
17 public:
18 DAbstractUnitFormatter();
19 ~DAbstractUnitFormatter();
20
21 protected:
22 virtual int unitMax() const = 0;
23 virtual int unitMin() const = 0;
24 virtual uint unitConvertRate(int unitId) const = 0;
25 virtual qreal unitValueMax(int unitId) const { return unitConvertRate(unitId) - 1; }
26 virtual qreal unitValueMin(int unitId) const { Q_UNUSED(unitId); return 1; }
27 virtual QString unitStr(int unitId) const = 0;
28
29 public:
30 qreal formatAs(qreal value, int currentUnit, const int targetUnit) const;
31 QPair<qreal, int> format(const qreal value, const int unit) const;
32 QList<QPair<qreal, int>> formatAsUnitList(const qreal value, int unit) const;
33 };
34
35 DCORE_END_NAMESPACE
36
37 #endif // DABSTRACTUNITFORMATTER_H