11#include <QDoubleValidator>
13#include <QRegularExpression>
37 bool negative = (value < 0);
39 int degrees = qFloor (value);
44 degrees *= (negative ? -1.0 : 1.0);
46 return QString (
"%1%2 %3%4 %5%6")
56 bool isNsHemisphere)
const
63 bool negative = (value < 0);
65 int degrees = qFloor (value);
73 hemisphere = (negative ?
"S" :
"N");
75 hemisphere = (negative ?
"W" :
"E");
78 return QString (
"%1%2 %3%4 %5%6 %7")
94 const QString
string = stringUntrimmed.trimmed ();
96 if (
string.isEmpty()) {
98 return QValidator::Intermediate;
102 QStringList fields =
string.split (QRegularExpression (
"\\s+"),
105 QString field0, field1, field2;
106 if (fields.count() == 0) {
107 return QValidator::Invalid;
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;
121 stripSymbols (field0,
128 QDoubleValidator valDegrees;
129 QDoubleValidator valMinutesOrSeconds;
130 valMinutesOrSeconds.setBottom (0);
132 double valueDegrees = 0, valueMinutes = 0, valueSeconds = 0;
135 QValidator::State state = valDegrees.validate (field0,
137 if (state == QValidator::Acceptable) {
139 valueDegrees = field0.toDouble();
141 if (fields.count() > 1) {
144 state = valMinutesOrSeconds.validate (field1,
146 if (state == QValidator::Acceptable) {
148 valueMinutes = field1.toDouble();
150 if (fields.count() > 2) {
153 state = valMinutesOrSeconds.validate (field2,
155 if (state == QValidator::Acceptable) {
157 valueSeconds = field2.toDouble();
165 if (state == QValidator::Acceptable) {
166 if (valueDegrees < 0) {
182void FormatDegreesMinutesSecondsBase::stripSymbols (QString &field0,
184 QString &field2)
const
186 const int FIELD_WIDTH = 0, BASE_8 = 8, BASE_16 = 16;
189 QString strExpDegrees = QString (
".*\\0%1$")
192 QRegularExpression regExpDegrees (strExpDegrees);
194 if (regExpDegrees.match (field0).hasMatch()) {
195 field0 = field0.left (field0.count() - 1);
199 QString strExpMinutes = QString (
".*[\\0%1\\x%2]$")
203 QRegularExpression regExpMinutes (strExpMinutes);
205 if (regExpMinutes.match (field1).hasMatch()) {
206 field1 = field1.left (field1.count() - 1);
210 QString strExpSeconds1Char = QString (
".*[\\x%1\\x%2]$")
213 QString strExpSeconds2Chars = QString (
".*\\0%1\\0%2$")
217 QRegularExpression regExpSeconds1Char (strExpSeconds1Char), regExpSeconds2Chars (strExpSeconds2Chars);
219 if (regExpSeconds1Char.match (field2).hasMatch()) {
220 field2 = field2.left (field2.count() - 1);
222 if (regExpSeconds2Chars.match (field2).hasMatch()) {
223 field2 = field2.left (field2.count() - 2);
const int COORD_SYMBOL_SECONDS_QUOTATIONS
const int COORD_SYMBOL_MINUTES_APOSTROPHE
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
static Qt::SplitBehavior SkipEmptyParts()
SplitBehavior.