DtkCore
DTK Core module
ddisksizeformatter.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 DISKSIZEFORMATTER_H
19#define DISKSIZEFORMATTER_H
20
21#include "dabstractunitformatter.h"
22
23DCORE_BEGIN_NAMESPACE
24
25class LIBDTKCORESHARED_EXPORT DDiskSizeFormatter : public DAbstractUnitFormatter
26{
27public:
29
30 enum DiskUnits
31 {
32 B,
33 K,
34 M,
35 G,
36 T,
37 };
38
39 QString unitStr(int unitId) const override;
40
41 DDiskSizeFormatter rate(int rate);
42
43protected:
44 int unitMin() const override { return B; }
45 int unitMax() const override { return T; }
46 uint unitConvertRate(int unitId) const override { Q_UNUSED(unitId); return m_rate; }
47
48private:
49 int m_rate = 1000;
50};
51
52DCORE_END_NAMESPACE
53
54#endif // DISKSIZEFORMATTER_H
DAbstractUnitFormatter 类是对拥有相同类型数据管理的接口类.
Definition: dabstractunitformatter.h:29
virtual QString unitStr(int unitId) const =0
传入id,返回列表中对应的字符串. unitId 单元ID.
DDiskSizeFormatter 是用来获取磁盘容量单位的类, 通过枚举值.
Definition: ddisksizeformatter.h:26
int unitMin() const override
返回最小磁盘容量单位的枚举
Definition: ddisksizeformatter.h:44
uint unitConvertRate(int unitId) const override
返回当前的单位转换比率
Definition: ddisksizeformatter.h:46
int unitMax() const override
返回最大磁盘容量单位的枚举
Definition: ddisksizeformatter.h:45