DtkCore
DTK Core module
dabstractunitformatter.h
1/*
2 * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * any later version.
8 *
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.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef DABSTRACTUNITFORMATTER_H
19#define DABSTRACTUNITFORMATTER_H
20
21#include "dtkcore_global.h"
22
23#include <QPair>
24#include <QList>
25
26DCORE_BEGIN_NAMESPACE
27
28class LIBDTKCORESHARED_EXPORT DAbstractUnitFormatter
29{
30public:
33
34protected:
35 virtual int unitMax() const = 0;
36 virtual int unitMin() const = 0;
37 virtual uint unitConvertRate(int unitId) const = 0;
38 virtual qreal unitValueMax(int unitId) const { return unitConvertRate(unitId) - 1; }
39 virtual qreal unitValueMin(int unitId) const { Q_UNUSED(unitId); return 1; }
40 virtual QString unitStr(int unitId) const = 0;
41
42public:
43 qreal formatAs(qreal value, int currentUnit, const int targetUnit) const;
44 QPair<qreal, int> format(const qreal value, const int unit) const;
45 QList<QPair<qreal, int>> formatAsUnitList(const qreal value, int unit) const;
46};
47
48DCORE_END_NAMESPACE
49
50#endif // DABSTRACTUNITFORMATTER_H
DAbstractUnitFormatter 类是对拥有相同类型数据管理的接口类.
Definition: dabstractunitformatter.h:29
virtual int unitMin() const =0
返回列表中最小的单位.
virtual qreal unitValueMax(int unitId) const
返回列表中根据当前设置的转换单位的最大值. unitId 单元ID.
Definition: dabstractunitformatter.h:38
virtual qreal unitValueMin(int unitId) const
返回列表中根据当前设置的转换单位的最小值. unitId 单元ID.
Definition: dabstractunitformatter.h:39
virtual QString unitStr(int unitId) const =0
传入id,返回列表中对应的字符串. unitId 单元ID.
virtual uint unitConvertRate(int unitId) const =0
返回当前设置的转换单位. unitId 单元ID.
virtual int unitMax() const =0
返回列表中最大的单位.