Qt Virtual Chart Table (QVCT)
CUnitBearing.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_CUNITBEARING_HPP
20 #define QVCT_CUNITBEARING_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 class CUnitBearingSymbols; // see below
28 class CUnitBearingCodes; // see below
29 
31 
37 {
38 
39  //------------------------------------------------------------------------------
40  // CONSTANTS / STATIC
41  //------------------------------------------------------------------------------
42 
43 public:
45  enum EUnit {
46  DEG,
47  RAD,
48  GRAD,
49  UNDEFINED
50  };
51 
52 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 CUnitBearing;
97 
98  //------------------------------------------------------------------------------
99  // CONSTRUCTORS / DESTRUCTOR
100  //------------------------------------------------------------------------------
101 
102 private:
104  {
105  qMapSymbols.insert( CUnitBearing::DEG, QString::fromUtf8( "°" ) );
106  qMapSymbols.insert( CUnitBearing::RAD, QString::fromUtf8( "°r" ) );
107  qMapSymbols.insert( CUnitBearing::GRAD, QString::fromUtf8( "°g" ) );
108  };
109  QMap<CUnitBearing::EUnit,QString> qMapSymbols;
110 };
111 
114 {
115  friend class CUnitBearing;
116 
117  //------------------------------------------------------------------------------
118  // CONSTRUCTORS / DESTRUCTOR
119  //------------------------------------------------------------------------------
120 
121 private:
123  {
124  qMapCodes.insert( CUnitBearing::DEG, "deg" );
125  qMapCodes.insert( CUnitBearing::RAD, "rad" );
126  qMapCodes.insert( CUnitBearing::GRAD, "grad" );
127  };
128  QMap<CUnitBearing::EUnit,QString> qMapCodes;
129 };
130 
131 #endif // QVCT_CUNITBEARING_HPP
Container class for supported machine-friendly format/unit codes.
QMap< CUnitBearing::EUnit, QString > qMapCodes
Container class for supported human-readable format/unit symbols.
QMap< CUnitBearing::EUnit, QString > qMapSymbols
Bearing unit (deg,rad,grad) rendering/parsing class.
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
EUnit
Format/unit ID.
@ RAD
radians
@ UNDEFINED
undefined format/unit
@ DEG
degrees
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
static double toValue(double _fdValue, EUnit _eUnit)
Returns the converted value, using the specified format/unit.
static const CUnitBearingSymbols oUnitBearingSymbols
Container for supported human-readable format/unit symbols.
static const CUnitBearingCodes oUnitBearingCodes
Container for 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 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 fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.