Engauge Digitizer  2
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 "DocumentModelGeneral.h"
8 #include "EngaugeAssert.h"
9 #include "FormatCoordsUnitsStrategyPolarTheta.h"
10 #include "FormatDegreesMinutesSecondsPolarTheta.h"
11 #include "Logger.h"
12 #include <QLocale>
13 
15 {
16 }
17 
19  const QLocale &locale,
20  CoordUnitsPolarTheta coordUnits) const
21 {
22  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::formattedToUnformatted";
23 
24  double value;
25 
26  switch (coordUnits) {
27  case COORD_UNITS_POLAR_THETA_DEGREES:
28  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
29  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
30  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
31  {
33  ENGAUGE_ASSERT (format.parseInput (string,
34  value) == QValidator::Acceptable);
35  }
36  break;
37 
38  case COORD_UNITS_POLAR_THETA_GRADIANS:
39  case COORD_UNITS_POLAR_THETA_RADIANS:
40  case COORD_UNITS_POLAR_THETA_TURNS:
41  value = locale.toDouble (string);
42  break;
43 
44  default:
45  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
46  ENGAUGE_ASSERT (false);
47  break;
48  }
49 
50  return value;
51 }
52 
54  const QLocale &locale,
55  CoordUnitsPolarTheta coordUnits,
56  const DocumentModelGeneral &modelGeneral,
57  const Transformation &transformation,
58  double valueUnformattedOther) const
59 {
60  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormatted";
61 
62  const char FORMAT ('g');
63  const bool IS_X_THETA = true;
64 
65  QString valueFormatted;
66 
67  switch (coordUnits) {
68  case COORD_UNITS_POLAR_THETA_DEGREES:
69  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
70  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
71  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
72  {
74  valueFormatted = format.formatOutput (coordUnits,
75  valueUnformatted,
76  IS_X_THETA);
77  }
78  break;
79 
80  case COORD_UNITS_POLAR_THETA_GRADIANS:
81  case COORD_UNITS_POLAR_THETA_RADIANS:
82  case COORD_UNITS_POLAR_THETA_TURNS:
83  valueFormatted = locale.toString (valueUnformatted,
84  FORMAT,
85  precisionDigitsForRawNumber (valueUnformatted,
86  valueUnformattedOther,
87  IS_X_THETA,
88  modelGeneral,
89  transformation));
90  break;
91 
92  default:
93  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
94  ENGAUGE_ASSERT (false);
95  break;
96  }
97 
98  return valueFormatted;
99 }
Model for DlgSettingsGeneral and CmdSettingsGeneral.
double formattedToUnformatted(const QString &string, const QLocale &locale, CoordUnitsPolarTheta coordUnits) const
Convert formatted string to simple unformatted number.
Angular units according to CoordUnitsPolarTheta.
Affine transformation between screen and graph coordinates, based on digitized axis points...
QString unformattedToFormatted(double valueUnformatted, const QLocale &locale, CoordUnitsPolarTheta coordUnits, const DocumentModelGeneral &modelGeneral, 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/...
int precisionDigitsForRawNumber(double valueUnformatted, double valueUnformattedOther, bool isXTheta, const DocumentModelGeneral &modelGeneral, const Transformation &transformation) const
Compute precision for outputting an unformatted value, consistent with the resolution at the point wh...
QValidator::State parseInput(const QString &stringUntrimmed, double &value) const
Parse the input string into a number value.