Qt Virtual Chart Table (QVCT)
CUnitPosition.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_CUNITPOSITION_HPP
20 #define QVCT_CUNITPOSITION_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 class CUnitPositionSymbols; // see below
28 class CUnitPositionCodes; // see below
29 
30 
32 
38 {
39 
40  //------------------------------------------------------------------------------
41  // CONSTANTS / STATIC
42  //------------------------------------------------------------------------------
43 
44 public:
46  enum EUnit {
47  DMS,
48  DM,
49  DEG,
50  RAD,
51  GRAD,
52  UNDEFINED
53  };
55  enum EType {
57  LATITUDE
58  };
59 
60 private:
65 
66 public:
68  static const QMap<EUnit,QString> &symbols();
70  static QString toSymbol( EUnit _eUnit );
72  static EUnit fromSymbol( const QString& _rqsSymbol );
74  static const QMap<EUnit,QString> &codes();
76  static QString toCode( EUnit _eUnit );
78  static EUnit fromCode( const QString& _rqsCode );
80  static QString toString( double _fdValue, EType _eType, EUnit _eUnit, int _iPrecision = 0 );
82  static QString toString( double _fdValue, EType _eType );
84 
92  static double fromString( const QString& _rqString, bool* _pbOK = 0 );
93 
94 };
95 
98 {
99  friend class CUnitPosition;
100 
101  //------------------------------------------------------------------------------
102  // CONSTRUCTORS / DESTRUCTOR
103  //------------------------------------------------------------------------------
104 
105 private:
107  {
108  qMapSymbols.insert( CUnitPosition::DMS, QString::fromUtf8( "ddd°mm'ss\"" ) );
109  qMapSymbols.insert( CUnitPosition::DM, QString::fromUtf8( "ddd°mm'" ) );
110  qMapSymbols.insert( CUnitPosition::DEG, QString::fromUtf8( "ddd°" ) );
111  qMapSymbols.insert( CUnitPosition::RAD, QString::fromUtf8( "rad°r" ) );
112  qMapSymbols.insert( CUnitPosition::GRAD, QString::fromUtf8( "grad°g" ) );
113  };
114  QMap<CUnitPosition::EUnit,QString> qMapSymbols;
115 };
116 
119 {
120  friend class CUnitPosition;
121 
122  //------------------------------------------------------------------------------
123  // CONSTRUCTORS / DESTRUCTOR
124  //------------------------------------------------------------------------------
125 
126 private:
128  {
129  qMapCodes.insert( CUnitPosition::DMS, "dms" );
130  qMapCodes.insert( CUnitPosition::DM, "dm" );
131  qMapCodes.insert( CUnitPosition::DEG, "deg" );
132  qMapCodes.insert( CUnitPosition::RAD, "rad" );
133  qMapCodes.insert( CUnitPosition::GRAD, "grad" );
134  };
135  QMap<CUnitPosition::EUnit,QString> qMapCodes;
136 };
137 
138 #endif // QVCT_CUNITPOSITION_HPP
Container class for supported machine-friendly format/unit codes.
QMap< CUnitPosition::EUnit, QString > qMapCodes
Container class for supported human-readable format/unit symbols.
QMap< CUnitPosition::EUnit, QString > qMapSymbols
Geographical position unit (D,DM,DMS,RAD,GRAD) rendering/parsing class.
EType
Position coordinate type ID.
static QString toString(double _fdValue, EType _eType, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static const CUnitPositionCodes oUnitPositionCodes
Container for supported machine-friendly format/unit codes.
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.
EUnit
Format/unit ID.
@ UNDEFINED
undefined format/unit
@ DM
degrees, minutes
@ DMS
degrees, minutes, seconds
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
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 EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
static const CUnitPositionSymbols oUnitPositionSymbols
Container for supported human-readable format/unit symbols.
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.