File: dabstractunitformatter.h

package info (click to toggle)
dtk6core 6.0.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,828 kB
  • sloc: cpp: 22,748; ansic: 191; python: 68; xml: 58; makefile: 25; sh: 15
file content (37 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DABSTRACTUNITFORMATTER_H
#define DABSTRACTUNITFORMATTER_H

#include "dtkcore_global.h"

#include <QPair>
#include <QList>

DCORE_BEGIN_NAMESPACE

class LIBDTKCORESHARED_EXPORT DAbstractUnitFormatter
{
public:
    DAbstractUnitFormatter();
    ~DAbstractUnitFormatter();

protected:
    virtual int unitMax() const = 0;
    virtual int unitMin() const = 0;
    virtual uint unitConvertRate(int unitId) const = 0;
    virtual qreal unitValueMax(int unitId) const { return unitConvertRate(unitId) - 1; }
    virtual qreal unitValueMin(int unitId) const { Q_UNUSED(unitId); return 1; }
    virtual QString unitStr(int unitId) const = 0;

public:
    qreal formatAs(qreal value, int currentUnit, const int targetUnit) const;
    QPair<qreal, int> format(const qreal value, const int unit) const;
    QList<QPair<qreal, int>> formatAsUnitList(const qreal value, int unit) const;
};

DCORE_END_NAMESPACE

#endif // DABSTRACTUNITFORMATTER_H