source: trunk/qt/formatter.h @ 12429

Last change on this file since 12429 was 12429, checked in by jordan, 11 years ago

(trunk qt) #4236 "Update formatter functions to operate with signed integers" -- patch by taem

  • Property svn:keywords set to Date Rev Author Id
File size: 1.2 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 *
10 * $Id: formatter.h 12429 2011-05-12 20:21:27Z jordan $
11 */
12
13#ifndef QTR_UNITS
14#define QTR_UNITS
15
16#include <inttypes.h> /* uint64_t */
17
18#include <QString>
19#include <QObject>
20#include <QIcon>
21
22class Speed;
23
24class Formatter: public QObject
25{
26        Q_OBJECT
27
28    public:
29
30        Formatter( ) { }
31        virtual ~Formatter( ) { }
32
33    public:
34
35        static QString memToString( int64_t bytes );
36        static QString sizeToString( int64_t bytes );
37        static QString speedToString( const Speed& speed );
38        static QString percentToString( double x );
39        static QString ratioToString( double ratio );
40        static QString timeToString( int seconds );
41
42    public:
43
44        typedef enum { B, KB, MB, GB, TB } Size;
45        typedef enum { SPEED, SIZE, MEM } Type;
46        static QString unitStr( Type t, Size s ) { return unitStrings[t][s]; }
47        static void initUnits( );
48
49    private:
50
51        static QString unitStrings[3][5];
52};
53
54#endif
Note: See TracBrowser for help on using the repository browser.