Qt Virtual Chart Table (QVCT)
CUnitTimeDelta.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 #ifndef QVCT_CUNITTIMEDELTA_HPP
20 #define QVCT_CUNITTIMEDELTA_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 class CUnitTimeDeltaSymbols; // see below
28 class CUnitTimeDeltaCodes; // see below
29 
30 
32 
38 {
39 
40  //------------------------------------------------------------------------------
41  // CONSTANTS / STATIC
42  //------------------------------------------------------------------------------
43 
44 public:
46  enum EUnit {
47  HMS,
48  HM,
49  M,
50  S,
51  UNDEFINED
52  };
53 
54 private:
59 
60 public:
62  static const QMap<EUnit,QString> &symbols();
64  static QString toSymbol( EUnit _eUnit );
66  static EUnit fromSymbol( const QString& _rqsSymbol );
68  static const QMap<EUnit,QString> &codes();
70  static QString toCode( EUnit _eUnit );
72  static EUnit fromCode( const QString& _rqsCode );
74  static QString toString( double _fdValue, EUnit _eUnit, int _iPrecision = 0 );
76  static QString toString( double _fdValue );
78 
86  static double fromString( const QString& _rqString, bool* _pbOK = 0 );
87 
88 };
89 
92 {
93  friend class CUnitTimeDelta;
94 
95  //------------------------------------------------------------------------------
96  // CONSTRUCTORS / DESTRUCTOR
97  //------------------------------------------------------------------------------
98 
99 private:
101  {
102  qMapSymbols.insert( CUnitTimeDelta::HMS, "hhh:mm:ss" );
103  qMapSymbols.insert( CUnitTimeDelta::HM, "hhh:mm" );
104  qMapSymbols.insert( CUnitTimeDelta::M, "mmm'" );
105  qMapSymbols.insert( CUnitTimeDelta::S, "sss\"" );
106  };
107  QMap<CUnitTimeDelta::EUnit,QString> qMapSymbols;
108 };
109 
112 {
113  friend class CUnitTimeDelta;
114 
115  //------------------------------------------------------------------------------
116  // CONSTRUCTORS / DESTRUCTOR
117  //------------------------------------------------------------------------------
118 
119 private:
121  {
122  qMapCodes.insert( CUnitTimeDelta::HMS, "hms" );
123  qMapCodes.insert( CUnitTimeDelta::HM, "hm" );
124  qMapCodes.insert( CUnitTimeDelta::M, "m" );
125  qMapCodes.insert( CUnitTimeDelta::S, "s" );
126  };
127  QMap<CUnitTimeDelta::EUnit,QString> qMapCodes;
128 };
129 
130 #endif // QVCT_CUNITTIMEDELTA_HPP
Container class for supported machine-friendly format/unit codes.
QMap< CUnitTimeDelta::EUnit, QString > qMapCodes
Container class for supported human-readable format/unit symbols.
QMap< CUnitTimeDelta::EUnit, QString > qMapSymbols
Time difference (HMS, HM, M, S) rendering/parsing class.
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
static const CUnitTimeDeltaSymbols oUnitTimeDeltaSymbols
Container for supported human-readable format/unit symbols.
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
EUnit
Format/unit ID.
@ UNDEFINED
undefined format/unit
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
static double fromString(const QString &_rqString, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
static QString toString(double _fdValue, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
static const CUnitTimeDeltaCodes oUnitTimeDeltaCodes
Container for supported machine-friendly format/unit codes.