Qt Virtual Chart Table (QVCT)
CUnitDistance.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_CUNITDISTANCE_HPP
20 #define QVCT_CUNITDISTANCE_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 class CUnitDistanceSymbols; // see below
28 
29 
31 
37 {
38 
39  //------------------------------------------------------------------------------
40  // CONSTANTS / STATIC
41  //------------------------------------------------------------------------------
42 
43 public:
45  enum EUnit {
46  M,
47  KM,
48  FT,
49  MI,
50  NM,
51  UNDEFINED
52  };
53 
54 private:
57 
58 public:
60  static const QMap<EUnit,QString> &symbols();
62  static QString toSymbol( EUnit _eUnit );
64  static EUnit fromSymbol( const QString& _rqsSymbol );
66  static const QMap<EUnit,QString> &codes();
68  static QString toCode( EUnit _eUnit );
70  static EUnit fromCode( const QString& _rqsCode );
72  static double toValue( double _fdValue, EUnit _eUnit );
74  static QString toString( double _fdValue, EUnit _eUnit, int _iPrecision = 0 );
76  static QString toString( double _fdValue );
78 
87  static double fromString( const QString& _rqString, EUnit _eUnit = UNDEFINED, bool* _pbOK = 0 );
89  static double fromString( const QString& _rqString, bool* _pbOK = 0 );
90 
91 };
92 
95 {
96  friend class CUnitDistance;
97 
98  //------------------------------------------------------------------------------
99  // CONSTRUCTORS / DESTRUCTOR
100  //------------------------------------------------------------------------------
101 
102 private:
104  {
105  qMapSymbols.insert( CUnitDistance::M, "m" );
106  qMapSymbols.insert( CUnitDistance::KM, "km" );
107  qMapSymbols.insert( CUnitDistance::FT, "ft" );
108  qMapSymbols.insert( CUnitDistance::MI, "mi" );
109  qMapSymbols.insert( CUnitDistance::NM, "nm" );
110  };
111  QMap<CUnitDistance::EUnit,QString> qMapSymbols;
112 };
113 
114 #endif // QVCT_CUNITDISTANCE_HPP
Container class for supported human-readable format/unit symbols.
QMap< CUnitDistance::EUnit, QString > qMapSymbols
Distance unit (m,km,ft,mi,nm) rendering/parsing class.
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
EUnit
Format/unit ID.
@ MI
statute miles [mi]
@ KM
kilometers [km]
@ FT
feet [ft]
@ NM
nautical miles [nm]
@ UNDEFINED
undefined format/unit
@ M
meters [m]
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
static const CUnitDistanceSymbols oUnitDistanceSymbols
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 double fromString(const QString &_rqString, EUnit _eUnit=UNDEFINED, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
static double toValue(double _fdValue, EUnit _eUnit)
Returns the converted value, using the specified format/unit.
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...