Engauge Digitizer 2
Loading...
Searching...
No Matches
FormatCoordsUnitsStrategyNonPolarTheta.cpp
Go to the documentation of this file.
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
8#include "EngaugeAssert.h"
10#include "FormatDateTime.h"
12#include "Logger.h"
13#include <QLocale>
14#include "Transformation.h"
15
19
21 const QLocale &locale,
22 CoordUnitsNonPolarTheta coordUnits,
23 CoordUnitsDate coordUnitsDate,
24 CoordUnitsTime coordUnitsTime) const
25{
26 //LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToUnformatted";
27
28 double value;
29
30 switch (coordUnits) {
32 {
33 FormatDateTime format;
34 ENGAUGE_ASSERT (format.parseInput (coordUnitsDate,
35 coordUnitsTime,
36 string,
37 value) == QValidator::Acceptable);
38 }
39 break;
40
43 {
45 ENGAUGE_ASSERT (format.parseInput (string,
46 value) == QValidator::Acceptable);
47 }
48 break;
49
51 value = locale.toDouble (string);
52 break;
53
54 default:
55 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToFormatted";
56 ENGAUGE_ASSERT (false);
57 break;
58 }
59
60 return value;
61}
62
64 const QLocale &locale,
65 CoordUnitsNonPolarTheta coordUnits,
66 CoordUnitsDate coordUnitsDate,
67 CoordUnitsTime coordUnitsTime,
68 bool isXTheta,
69 const DocumentModelGeneral &modelGeneral,
70 const Transformation &transformation,
71 double valueUnformattedOther) const
72{
73 //LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
74
75 const char FORMAT ('g');
76
77 QString valueFormatted;
78
79 switch (coordUnits) {
81 {
82 FormatDateTime format;
83 valueFormatted = format.formatOutput (coordUnitsDate,
84 coordUnitsTime,
85 valueUnformatted);
86 }
87 break;
88
91 {
93 valueFormatted = format.formatOutput (coordUnits,
94 valueUnformatted,
95 isXTheta);
96 }
97 break;
98
100 valueFormatted = locale.toString (valueUnformatted,
101 FORMAT,
102 precisionDigitsForRawNumber (valueUnformatted,
103 valueUnformattedOther,
104 isXTheta,
105 modelGeneral,
106 transformation));
107 break;
108
109 default:
110 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
111 ENGAUGE_ASSERT (false);
112 break;
113 }
114
115 return valueFormatted;
116}
CoordUnitsDate
CoordUnitsNonPolarTheta
@ COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS
@ COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW
@ COORD_UNITS_NON_POLAR_THETA_NUMBER
@ COORD_UNITS_NON_POLAR_THETA_DATE_TIME
CoordUnitsTime
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Model for DlgSettingsGeneral and CmdSettingsGeneral.
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...
QString unformattedToFormatted(double valueUnformatted, const QLocale &locale, CoordUnitsNonPolarTheta coordUnits, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, bool isXTheta, const DocumentModelGeneral &modelGeneral, 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.
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12