Engauge Digitizer  2
FormatCoordsUnitsStrategyPolarTheta.cpp
1 #include "EngaugeAssert.h"
2 #include "FormatCoordsUnitsStrategyPolarTheta.h"
3 #include "FormatDegreesMinutesSecondsPolarTheta.h"
4 #include "Logger.h"
5 #include <QLocale>
6 
8 {
9 }
10 
12  const QLocale &locale,
13  CoordUnitsPolarTheta coordUnits) const
14 {
15  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::formattedToUnformatted";
16 
17  double value;
18 
19  switch (coordUnits) {
20  case COORD_UNITS_POLAR_THETA_DEGREES:
21  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
22  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
23  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
24  {
26  ENGAUGE_ASSERT (format.parseInput (string,
27  value) == QValidator::Acceptable);
28  }
29  break;
30 
31  case COORD_UNITS_POLAR_THETA_GRADIANS:
32  case COORD_UNITS_POLAR_THETA_RADIANS:
33  case COORD_UNITS_POLAR_THETA_TURNS:
34  value = locale.toDouble(string);
35  break;
36 
37  default:
38  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
39  ENGAUGE_ASSERT (false);
40  break;
41  }
42 
43  return value;
44 }
45 
47  const QLocale &locale,
48  CoordUnitsPolarTheta coordUnits,
49  const Transformation &transformation,
50  double valueUnformattedOther) const
51 {
52  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormatted";
53 
54  const char FORMAT ('g');
55  const bool IS_X_THETA = true;
56 
57  QString valueFormatted;
58 
59  switch (coordUnits) {
60  case COORD_UNITS_POLAR_THETA_DEGREES:
61  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
62  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
63  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
64  {
66  valueFormatted = format.formatOutput (coordUnits,
67  valueUnformatted,
68  IS_X_THETA);
69  }
70  break;
71 
72  case COORD_UNITS_POLAR_THETA_GRADIANS:
73  case COORD_UNITS_POLAR_THETA_RADIANS:
74  case COORD_UNITS_POLAR_THETA_TURNS:
75  valueFormatted = locale.toString (valueUnformatted,
76  FORMAT,
77  precisionDigitsForRawNumber (valueUnformatted,
78  valueUnformattedOther,
79  IS_X_THETA,
80  transformation));
81  break;
82 
83  default:
84  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
85  ENGAUGE_ASSERT (false);
86  break;
87  }
88 
89  return valueFormatted;
90 }
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.