Engauge Digitizer 2
Loading...
Searching...
No Matches
FormatDegreesMinutesSecondsBase Class Reference

Common input parsing and output formatting for degrees/minutes/seconds values. More...

#include <FormatDegreesMinutesSecondsBase.h>

Inheritance diagram for FormatDegreesMinutesSecondsBase:
Inheritance graph
Collaboration diagram for FormatDegreesMinutesSecondsBase:
Collaboration graph

Public Member Functions

 FormatDegreesMinutesSecondsBase ()
 Single constructor.
 ~FormatDegreesMinutesSecondsBase ()
QValidator::State parseInput (const QString &stringUntrimmed, double &value) const
 Parse the input string into a number value.

Protected Member Functions

QString formatOutputDegreesMinutesSeconds (double value) const
 Format as degrees, minutes and seconds without hemisphere.
QString formatOutputDegreesMinutesSecondsNsew (double value, bool isNsHemisphere) const
 Format as degrees, minutes and seconds with hemisphere.

Detailed Description

Common input parsing and output formatting for degrees/minutes/seconds values.

Definition at line 14 of file FormatDegreesMinutesSecondsBase.h.

Constructor & Destructor Documentation

◆ FormatDegreesMinutesSecondsBase()

FormatDegreesMinutesSecondsBase::FormatDegreesMinutesSecondsBase ( )

Single constructor.

Definition at line 23 of file FormatDegreesMinutesSecondsBase.cpp.

24{
25}

◆ ~FormatDegreesMinutesSecondsBase()

FormatDegreesMinutesSecondsBase::~FormatDegreesMinutesSecondsBase ( )

Definition at line 27 of file FormatDegreesMinutesSecondsBase.cpp.

28{
29}

Member Function Documentation

◆ formatOutputDegreesMinutesSeconds()

QString FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSeconds ( double value) const
protected

Format as degrees, minutes and seconds without hemisphere.

Definition at line 31 of file FormatDegreesMinutesSecondsBase.cpp.

32{
33 //LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSeconds"
34 // << " value=" << value;
35
36 // Only smallest resolution value is floating point
37 bool negative = (value < 0);
38 value = qAbs (value);
39 int degrees = qFloor (value);
40 value -= degrees;
41 int minutes = qFloor (value * DEGREES_TO_MINUTES);
42 value -= minutes * MINUTES_TO_DEGREES;
43 double seconds = value * DEGREES_TO_SECONDS;
44 degrees *= (negative ? -1.0 : 1.0);
45
46 return QString ("%1%2 %3%4 %5%6")
47 .arg (degrees)
48 .arg (QChar (COORD_SYMBOL_DEGREES))
49 .arg (minutes)
50 .arg (QChar (COORD_SYMBOL_MINUTES_PRIME))
51 .arg (seconds)
53}
const int COORD_SYMBOL_DEGREES
Mathematical symbols for degrees, minutes, seconds input/outputs from/to users.
const int COORD_SYMBOL_MINUTES_PRIME
const int COORD_SYMBOL_SECONDS_DOUBLE_PRIME
const double DEGREES_TO_MINUTES
const double DEGREES_TO_SECONDS
const double MINUTES_TO_DEGREES

◆ formatOutputDegreesMinutesSecondsNsew()

QString FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSecondsNsew ( double value,
bool isNsHemisphere ) const
protected

Format as degrees, minutes and seconds with hemisphere.

Definition at line 55 of file FormatDegreesMinutesSecondsBase.cpp.

57{
58 //LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSecondsNsew"
59 // << " value=" << value
60 // << " isNsHemisphere=" << (isNsHemisphere ? "true" : "false");
61
62 // Only smallest resolution value is floating point
63 bool negative = (value < 0);
64 value = qAbs (value);
65 int degrees = qFloor (value);
66 value -= degrees;
67 int minutes = qFloor (value * DEGREES_TO_MINUTES);
68 value -= minutes * MINUTES_TO_DEGREES;
69 double seconds = value * DEGREES_TO_SECONDS;
70
71 QString hemisphere;
72 if (isNsHemisphere) {
73 hemisphere = (negative ? "S" : "N");
74 } else {
75 hemisphere = (negative ? "W" : "E");
76 }
77
78 return QString ("%1%2 %3%4 %5%6 %7")
79 .arg (degrees)
80 .arg (QChar (COORD_SYMBOL_DEGREES))
81 .arg (minutes)
82 .arg (QChar (COORD_SYMBOL_MINUTES_PRIME))
83 .arg (seconds)
85 .arg (hemisphere);
86}

◆ parseInput()

QValidator::State FormatDegreesMinutesSecondsBase::parseInput ( const QString & stringUntrimmed,
double & value ) const

Parse the input string into a number value.

Success flag is false if the parsing failed. Either signed values or hemisphere (North, South, East, West) values can be accepted irregardless of the output format selected by the user. Leading/trailing spaces are trimmed. Leading/trailing spaces are trimmed (=ignored)

Definition at line 88 of file FormatDegreesMinutesSecondsBase.cpp.

90{
91 //LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsBase::parseInput"
92 // << " string=" << stringUntrimmed.toLatin1().data();
93
94 const QString string = stringUntrimmed.trimmed ();
95
96 if (string.isEmpty()) {
97
98 return QValidator::Intermediate;
99 }
100
101 // Split on spaces
102 QStringList fields = string.split (QRegularExpression ("\\s+"),
104
105 QString field0, field1, field2; // Degrees, minutes and seconds components
106 if (fields.count() == 0) {
107 return QValidator::Invalid; // Empty
108 } else {
109 field0 = fields.at(0);
110 if (fields.count() > 1) {
111 field1 = fields.at(1);
112 if (fields.count() > 2) {
113 field2 = fields.at(2);
114 if (fields.count() > 3) {
115 return QValidator::Invalid; // Too many values
116 }
117 }
118 }
119 }
120
121 stripSymbols (field0,
122 field1,
123 field2);
124
125 int pos;
126
127 // Validators
128 QDoubleValidator valDegrees;
129 QDoubleValidator valMinutesOrSeconds;
130 valMinutesOrSeconds.setBottom (0);
131
132 double valueDegrees = 0, valueMinutes = 0, valueSeconds = 0;
133
134 // Required degrees
135 QValidator::State state = valDegrees.validate (field0,
136 pos);
137 if (state == QValidator::Acceptable) {
138
139 valueDegrees = field0.toDouble();
140
141 if (fields.count() > 1) {
142
143 // Optional minutes
144 state = valMinutesOrSeconds.validate (field1,
145 pos);
146 if (state == QValidator::Acceptable) {
147
148 valueMinutes = field1.toDouble();
149
150 if (fields.count() > 2) {
151
152 // Optional seconds
153 state = valMinutesOrSeconds.validate (field2,
154 pos);
155 if (state == QValidator::Acceptable) {
156
157 valueSeconds = field2.toDouble();
158
159 }
160 }
161 }
162 }
163 }
164
165 if (state == QValidator::Acceptable) {
166 if (valueDegrees < 0) {
167
168 // Apply the negative sign on the degrees components to minutes and seconds components also
169 value = valueDegrees - valueMinutes * MINUTES_TO_DEGREES - valueSeconds * SECONDS_TO_DEGREES;
170
171 } else {
172
173 // All components are positive
174 value = valueDegrees + valueMinutes * MINUTES_TO_DEGREES + valueSeconds * SECONDS_TO_DEGREES;
175
176 }
177 }
178
179 return state;
180}
const double SECONDS_TO_DEGREES
static Qt::SplitBehavior SkipEmptyParts()
SplitBehavior.

The documentation for this class was generated from the following files: