Qt Virtual Chart Table (QVCT)
CUnitSpeed.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 
26 #ifndef QVCT_CUNITSPEED_HPP
27 #define QVCT_CUNITSPEED_HPP
28 
29 // QT
30 #include <QMap>
31 #include <QString>
32 
33 // QVCT
34 class CUnitSpeedSymbols; // see below
35 class CUnitSpeedCodes; // see below
36 
37 
39 
45 {
46 
47  //------------------------------------------------------------------------------
48  // CONSTANTS / STATIC
49  //------------------------------------------------------------------------------
50 
51 public:
53  enum EUnit {
54  M_S,
55  KM_H,
56  MI_H,
57  KT,
58  UNDEFINED
59  };
60 
61 private:
66 
67 public:
69  static const QMap<EUnit,QString> &symbols();
71  static QString toSymbol( EUnit _eUnit );
73  static EUnit fromSymbol( const QString& _rqsSymbol );
75  static const QMap<EUnit,QString> &codes();
77  static QString toCode( EUnit _eUnit );
79  static EUnit fromCode( const QString& _rqsCode );
81  static double toValue( double _fdValue, EUnit _eUnit );
83  static QString toString( double _fdValue, EUnit _eUnit, int _iPrecision = 0 );
85  static QString toString( double _fdValue );
87 
96  static double fromString( const QString& _rqString, EUnit _eUnit, bool* _pbOK = 0 );
98  static double fromString( const QString& _rqString, bool* _pbOK = 0 );
99 
100 };
101 
104 {
105  friend class CUnitSpeed;
106 
107  //------------------------------------------------------------------------------
108  // CONSTRUCTORS / DESTRUCTOR
109  //------------------------------------------------------------------------------
110 
111 private:
113  {
114  qMapSymbols.insert( CUnitSpeed::M_S, "m/s" );
115  qMapSymbols.insert( CUnitSpeed::KM_H, "km/h" );
116  qMapSymbols.insert( CUnitSpeed::MI_H, "mph" );
117  qMapSymbols.insert( CUnitSpeed::KT, "kt" );
118  };
119  QMap<CUnitSpeed::EUnit,QString> qMapSymbols;
120 };
121 
124 {
125  friend class CUnitSpeed;
126 
127  //------------------------------------------------------------------------------
128  // CONSTRUCTORS / DESTRUCTOR
129  //------------------------------------------------------------------------------
130 
131 private:
133  {
134  qMapCodes.insert( CUnitSpeed::M_S, "m_s" );
135  qMapCodes.insert( CUnitSpeed::KM_H, "km_h" );
136  qMapCodes.insert( CUnitSpeed::MI_H, "mi_h" );
137  qMapCodes.insert( CUnitSpeed::KT, "kt" );
138  };
139  QMap<CUnitSpeed::EUnit,QString> qMapCodes;
140 };
141 
142 #endif // QVCT_CUNITSPEED_HPP
Container class for supported machine-friendly format/unit codes.
Definition: CUnitSpeed.hpp:124
QMap< CUnitSpeed::EUnit, QString > qMapCodes
Definition: CUnitSpeed.hpp:138
Container class for supported human-readable format/unit symbols.
Definition: CUnitSpeed.hpp:104
QMap< CUnitSpeed::EUnit, QString > qMapSymbols
Definition: CUnitSpeed.hpp:118
Speed unit (m/s,km/h,mi/h,kt) rendering/parsing class.
Definition: CUnitSpeed.hpp:45
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
Definition: CUnitSpeed.cpp:36
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...
Definition: CUnitSpeed.cpp:78
static double fromString(const QString &_rqString, EUnit _eUnit, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
Definition: CUnitSpeed.cpp:96
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
Definition: CUnitSpeed.cpp:56
static double toValue(double _fdValue, EUnit _eUnit)
Returns the converted value, using the specified format/unit.
Definition: CUnitSpeed.cpp:66
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
Definition: CUnitSpeed.cpp:41
static const CUnitSpeedCodes oUnitSpeedCodes
Container for supported machine-friendly format/unit codes.
Definition: CUnitSpeed.hpp:65
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
Definition: CUnitSpeed.cpp:46
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
Definition: CUnitSpeed.cpp:61
static const CUnitSpeedSymbols oUnitSpeedSymbols
Container for supported human-readable format/unit symbols.
Definition: CUnitSpeed.hpp:63
EUnit
Format/unit ID.
Definition: CUnitSpeed.hpp:53
@ UNDEFINED
undefined format/unit
Definition: CUnitSpeed.hpp:58
@ KM_H
kilometers per hour [km/h]
Definition: CUnitSpeed.hpp:55
@ MI_H
statute miles per hour [mi/h]
Definition: CUnitSpeed.hpp:56
@ KT
nautical miles per hour (knots) [kt]
Definition: CUnitSpeed.hpp:57
@ M_S
meters per second [m/s]
Definition: CUnitSpeed.hpp:54
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.
Definition: CUnitSpeed.cpp:51