Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
FormatCoordsUnitsStrategyPolarTheta.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "EngaugeAssert.h"
8 #include "FormatCoordsUnitsStrategyPolarTheta.h"
9 #include "FormatDegreesMinutesSecondsPolarTheta.h"
10 #include "Logger.h"
11 #include <QLocale>
12 
14 {
15 }
16 
18  const QLocale &locale,
19  CoordUnitsPolarTheta coordUnits) const
20 {
21  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::formattedToUnformatted";
22 
23  double value;
24 
25  switch (coordUnits) {
26  case COORD_UNITS_POLAR_THETA_DEGREES:
27  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
28  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
29  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
30  {
32  ENGAUGE_ASSERT (format.parseInput (string,
33  value) == QValidator::Acceptable);
34  }
35  break;
36 
37  case COORD_UNITS_POLAR_THETA_GRADIANS:
38  case COORD_UNITS_POLAR_THETA_RADIANS:
39  case COORD_UNITS_POLAR_THETA_TURNS:
40  value = locale.toDouble (string);
41  break;
42 
43  default:
44  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
45  ENGAUGE_ASSERT (false);
46  break;
47  }
48 
49  return value;
50 }
51 
53  const QLocale &locale,
54  CoordUnitsPolarTheta coordUnits,
55  const Transformation &transformation,
56  double valueUnformattedOther) const
57 {
58  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormatted";
59 
60  const char FORMAT ('g');
61  const bool IS_X_THETA = true;
62 
63  QString valueFormatted;
64 
65  switch (coordUnits) {
66  case COORD_UNITS_POLAR_THETA_DEGREES:
67  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
68  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
69  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
70  {
72  valueFormatted = format.formatOutput (coordUnits,
73  valueUnformatted,
74  IS_X_THETA);
75  }
76  break;
77 
78  case COORD_UNITS_POLAR_THETA_GRADIANS:
79  case COORD_UNITS_POLAR_THETA_RADIANS:
80  case COORD_UNITS_POLAR_THETA_TURNS:
81  valueFormatted = locale.toString (valueUnformatted,
82  FORMAT,
83  precisionDigitsForRawNumber (valueUnformatted,
84  valueUnformattedOther,
85  IS_X_THETA,
86  transformation));
87  break;
88 
89  default:
90  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
91  ENGAUGE_ASSERT (false);
92  break;
93  }
94 
95  return valueFormatted;
96 }
Angular units according to CoordUnitsPolarTheta.
QValidator::State parseInput(const QString &stringUntrimmed, double &value) const
Parse the input string into a number value.
Affine transformation between screen and graph coordinates, based on digitized axis points...
int precisionDigitsForRawNumber(double valueUnformatted, double valueUnformattedOther, bool isXTheta, const Transformation &transformation) const
Compute precision for outputting an unformatted value, consistent with the resolution at the point wh...
QString unformattedToFormatted(double valueUnformatted, const QLocale &locale, CoordUnitsPolarTheta coordUnits, const Transformation &transformation, double valueUnformattedOther) const
Convert simple unformatted number to formatted string.
QString formatOutput(CoordUnitsPolarTheta coordUnits, double value, bool isXTheta) const
Format the degrees/minutes/seconds value. Distinguishing x/theta versus y/radius is required for N/S/...
double formattedToUnformatted(const QString &string, const QLocale &locale, CoordUnitsPolarTheta coordUnits) const
Convert formatted string to simple unformatted number.