3 #include "ui_InputCoordinateForm.h" 6 #include "../../../geometry/Coord2D.h" 7 #include "../Exception.h" 9 #include "../canvas/MapDisplay.h" 14 #include <QDoubleValidator> 15 #include <QPushButton> 16 #include <QRegularExpression> 33 void ParseDMS(
const QRegularExpressionMatch& match,
int&
d,
int& m,
int& s)
39 QStringList texts = match.capturedTexts();
41 bool negative =
false;
43 for(
int i = 1; i < texts.size(); i++)
45 int v = texts.at(i).toInt(&ok);
52 d = v * ((negative) ? -1 : 1);
69 if(texts.at(i).compare(
"-") == 0)
90 QString aux(
"^(-)?(\\d{1,3})?");
92 aux += QString(QChar(0260)) +=
" *(\\d{1,2})?' *(\\d{1,2})?''$";
94 QRegularExpression r(aux);
98 QRegularExpressionMatch match = r.match(dmsS.remove(
" "));
100 if(!match.hasMatch())
101 return QValidator::Invalid;
106 if((d == 999) || (m == 999) || (s == 999))
107 return QValidator::Intermediate;
110 if(!((d >= -180) && (d <= 180)))
111 return QValidator::Invalid;
114 if(!((m >= 0) && (m <= 60)))
115 return QValidator::Invalid;
118 if(!((s >= 0) && (s <= 60)))
119 return QValidator::Invalid;
121 return QValidator::Acceptable;
158 dS = QString::number(d);
159 int diff = 4 - dS.size();
161 for(
int i = 0; i < diff; i++)
170 mS = QString::number(m);
171 int diff = 2 - mS.size();
173 for(
int i = 0; i < diff; i++)
182 sS = QString::number(s);
183 int diff = 2 - sS.size();
185 for(
int i = 0; i < diff; i++)
189 return dS + QString(QChar(0260)) +
" " + mS +
"' " + sS +
"''";
204 res = QString(
"###9" + QString(QChar(0260)) +
" 00\' 00\'\'");
220 double DMS2DD(
const int&
d,
const int& m,
const int& s)
222 bool negativeValue =
false;
227 negativeValue =
true;
233 double coord = dd + (m / 60.0) + (s / 3600.0);
235 coord *= (negativeValue) ? -1 : 1;
254 degree =
static_cast<int>(value);
256 minute =
static_cast<int>(ll * 60);
257 ll = (ll * 60.) - minute;
260 return GetDMSAsString(degree, minute, static_cast<int>(std::ceil(second)));
276 llx = center.
getX() - w/2,
277 lly = center.
getY() - h/2,
278 urx = center.
getX() + w/2,
279 ury = center.
getY() + h/2;
315 State
validate(QString& value,
int&)
const override 325 void fixup(QString& value)
const override 333 if(state == QValidator::Intermediate)
344 m_ui(new
Ui::InputCoordinateForm),
345 m_validator(nullptr),
352 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
365 if(!
m_ui->m_DMS_checkButton->isChecked())
376 lat =
m_ui->m_Latitude_lineEdit->text().toDouble(&ok);
381 lon =
m_ui->m_Longitude_lineEdit->text().toDouble(&ok);
388 m_ui->m_Latitude_lineEdit->setText(
DD2DMS(lat));
389 m_ui->m_Longitude_lineEdit->setText(
DD2DMS(lon));
394 if(!
m_ui->m_DD_checkButton->isChecked())
406 if(state != QValidator::Invalid)
411 if(state != QValidator::Invalid)
416 m_ui->m_Latitude_lineEdit->setText(QString::number(lat));
417 m_ui->m_Longitude_lineEdit->setText(QString::number(lon));
429 if(srid != displaySrid)
434 if(srid != displaySrid)
447 if(
m_ui->m_Latitude_lineEdit->text().isEmpty() ||
m_ui->m_Longitude_lineEdit->text().isEmpty())
448 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
450 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
452 if(
m_ui->m_Latitude_lineEdit->hasAcceptableInput() &&
m_ui->m_Latitude_lineEdit->hasAcceptableInput())
453 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
455 m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
469 m_ui->m_Latitude_lineEdit->setInputMask(mask);
472 m_ui->m_Longitude_lineEdit->setInputMask(mask);
480 if(
m_ui->m_DMS_checkButton->isChecked())
490 if(state != QValidator::Invalid)
496 if(state != QValidator::Invalid)
511 x =
m_ui->m_Latitude_lineEdit->text().toDouble(&ok);
515 y =
m_ui->m_Longitude_lineEdit->text().toDouble(&ok);
Class used to evaluate the coordinates given as degree-minute-second values.
DMSValidator(QWidget *parent=nullptr)
Constructor.
double getWidth() const
It returns the envelope width.
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
~DMSValidator() override=default
Destructor.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void fixup(QString &value) const override
Used to try to fix some errors on value.
double getX() const
It returns the x-coordinate.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
double getHeight() const
It returns the envelope height.
State validate(QString &value, int &) const override
Verifies if the value is a degree-minute-second valid value.