Engauge Digitizer 2
Loading...
Searching...
No Matches
FormatCoordsUnitsStrategyNonPolarTheta.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 "FormatCoordsUnitsStrategyNonPolarTheta.h"
9#include "FormatDateTime.h"
10#include "FormatDegreesMinutesSecondsNonPolarTheta.h"
11#include "Logger.h"
12#include <QLocale>
13#include "Transformation.h"
14
18
20 const QLocale &locale,
21 CoordUnitsNonPolarTheta coordUnits,
22 CoordUnitsDate coordUnitsDate,
23 CoordUnitsTime coordUnitsTime) const
24{
25 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToUnformatted";
26
27 double value;
28
29 switch (coordUnits) {
30 case COORD_UNITS_NON_POLAR_THETA_DATE_TIME:
31 {
32 FormatDateTime format;
33 ENGAUGE_ASSERT (format.parseInput (coordUnitsDate,
34 coordUnitsTime,
35 string,
36 value) == QValidator::Acceptable);
37 }
38 break;
39
40 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS:
41 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
42 {
44 ENGAUGE_ASSERT (format.parseInput (string,
45 value) == QValidator::Acceptable);
46 }
47 break;
48
49 case COORD_UNITS_NON_POLAR_THETA_NUMBER:
50 value = locale.toDouble (string);
51 break;
52
53 default:
54 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToFormatted";
55 ENGAUGE_ASSERT (false);
56 break;
57 }
58
59 return value;
60}
61
63 const QLocale &locale,
64 CoordUnitsNonPolarTheta coordUnits,
65 CoordUnitsDate coordUnitsDate,
66 CoordUnitsTime coordUnitsTime,
67 bool isXTheta,
68 const Transformation &transformation,
69 double valueUnformattedOther) const
70{
71 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
72
73 const char FORMAT ('g');
74
75 QString valueFormatted;
76
77 switch (coordUnits) {
78 case COORD_UNITS_NON_POLAR_THETA_DATE_TIME:
79 {
80 FormatDateTime format;
81 valueFormatted = format.formatOutput (coordUnitsDate,
82 coordUnitsTime,
83 valueUnformatted);
84 }
85 break;
86
87 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS:
88 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
89 {
91 valueFormatted = format.formatOutput (coordUnits,
92 valueUnformatted,
93 isXTheta);
94 }
95 break;
96
97 case COORD_UNITS_NON_POLAR_THETA_NUMBER:
98 valueFormatted = locale.toString (valueUnformatted,
99 FORMAT,
100 precisionDigitsForRawNumber (valueUnformatted,
101 valueUnformattedOther,
102 isXTheta,
103 transformation));
104 break;
105
106 default:
107 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
108 ENGAUGE_ASSERT (false);
109 break;
110 }
111
112 return valueFormatted;
113}
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, CoordUnitsNonPolarTheta coordUnits, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, bool isXTheta, const Transformation &transformation, double valueUnformattedOther) const
Convert simple unformatted number to formatted string.
double formattedToUnformatted(const QString &string, const QLocale &locale, CoordUnitsNonPolarTheta coordUnits, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime) const
Convert formatted string to simple unformatted number.
Input parsing and output formatting for date/time values.
QValidator::State parseInput(CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QString &stringUntrimmed, double &value) const
Parse the input string into a time value.
QString formatOutput(CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, double value) const
Format the date/time value according to date/time format settings.
QValidator::State parseInput(const QString &stringUntrimmed, double &value) const
Parse the input string into a number value.
Angular units according to CoordUnitsNonPolarTheta.
QString formatOutput(CoordUnitsNonPolarTheta coordUnits, double value, bool isXTheta) const
Format the degrees/minutes/seconds value. Distinguishing x/theta versus y/radius is required for N/S/...
Affine transformation between screen and graph coordinates, based on digitized axis points.