Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
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. More...
 
 ~FormatDegreesMinutesSecondsBase ()
 
QValidator::State parseInput (const QString &stringUntrimmed, double &value) const
 Parse the input string into a number value. More...
 

Protected Member Functions

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

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 ( )

Single constructor.

Definition at line 22 of file FormatDegreesMinutesSecondsBase.cpp.

23 {
24 }
FormatDegreesMinutesSecondsBase::~FormatDegreesMinutesSecondsBase ( )

Definition at line 26 of file FormatDegreesMinutesSecondsBase.cpp.

27 {
28 }

Member Function Documentation

QString FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSeconds ( double  value) const
protected

Format as degrees, minutes and seconds without hemisphere.

Definition at line 30 of file FormatDegreesMinutesSecondsBase.cpp.

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

Format as degrees, minutes and seconds with hemisphere.

Definition at line 54 of file FormatDegreesMinutesSecondsBase.cpp.

56 {
57  //LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsBase::formatOutputDegreesMinutesSecondsNsew"
58  // << " value=" << value
59  // << " isNsHemisphere=" << (isNsHemisphere ? "true" : "false");
60 
61  // Only smallest resolution value is floating point
62  bool negative = (value < 0);
63  value = qAbs (value);
64  int degrees = qFloor (value);
65  value -= degrees;
66  int minutes = qFloor (value * DEGREES_TO_MINUTES);
67  value -= minutes * MINUTES_TO_DEGREES;
68  double seconds = value * DEGREES_TO_SECONDS;
69 
70  QString hemisphere;
71  if (isNsHemisphere) {
72  hemisphere = (negative ? "S" : "N");
73  } else {
74  hemisphere = (negative ? "W" : "E");
75  }
76 
77  return QString ("%1%2 %3%4 %5%6 %7")
78  .arg (degrees)
79  .arg (QChar (COORD_SYMBOL_DEGREES))
80  .arg (minutes)
81  .arg (QChar (COORD_SYMBOL_MINUTES_PRIME))
82  .arg (seconds)
84  .arg (hemisphere);
85 }
const double MINUTES_TO_DEGREES
const double DEGREES_TO_SECONDS
const int COORD_SYMBOL_MINUTES_PRIME
Definition: CoordSymbol.cpp:10
const int COORD_SYMBOL_SECONDS_DOUBLE_PRIME
Definition: CoordSymbol.cpp:12
const int COORD_SYMBOL_DEGREES
Mathematical symbols for degrees, minutes, seconds input/outputs from/to users.
Definition: CoordSymbol.cpp:9
const double DEGREES_TO_MINUTES
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 87 of file FormatDegreesMinutesSecondsBase.cpp.

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

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