116 lines
4.0 KiB
C++
Executable File
116 lines
4.0 KiB
C++
Executable File
|
|
|
|
|
|
#include <QApplication>
|
|
#include <QDialog>
|
|
#include <QPushButton>
|
|
#include <QVBoxLayout>
|
|
#include <QLabel>
|
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
|
#include "lts_coord_widget.h"
|
|
|
|
static void updateLabel(const QPointF &coord, QLabel *lbl, int prec)
|
|
{
|
|
QString mgrs = LtsCoordTrans::mgrsFromGeographic(coord.x(), coord.y(), prec);
|
|
QString str = QStringLiteral("mgrs: %1, lon: %2, lat: %3")
|
|
.arg(mgrs)
|
|
.arg(coord.x() * LtsCoordTrans::rad2deg(), 0, 'f', 10)
|
|
.arg(coord.y() * LtsCoordTrans::rad2deg(), 0, 'f', 10);
|
|
lbl->setText(str);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
LtsCoordTrans::UtmCoordinate base(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD00")));
|
|
QPointF topLeft(base.geographic(+50000, -50000));
|
|
QPointF bottomRight(base.geographic(-50000, 50000));
|
|
LtsCoordTrans::getMgrsSquares(QRectF(topLeft, bottomRight), true, true);
|
|
|
|
QDialog *dialog(new QDialog);
|
|
QVBoxLayout *lay(new QVBoxLayout(dialog));
|
|
|
|
|
|
const QPointF defCoord(QPointF(53.0, 8.0) * LtsCoordTrans::deg2rad());
|
|
|
|
LtsCoordWidget::LtsCoordWidget *wMgrs5(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS, dialog));
|
|
wMgrs5->setWithResetButton(true);
|
|
wMgrs5->setCoordinate(defCoord, true);
|
|
lay->addWidget(wMgrs5);
|
|
QLabel *lbl5(new QLabel(dialog));
|
|
lay->addWidget(lbl5);
|
|
QObject::connect(wMgrs5, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
|
lbl5, [lbl5](const QPointF & coord)
|
|
{
|
|
updateLabel(coord, lbl5, 5);
|
|
});
|
|
|
|
|
|
LtsCoordWidget::LtsCoordWidget *wMgrs7(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7, dialog));
|
|
wMgrs7->setWithResetButton(true);
|
|
wMgrs7->setCoordinate(defCoord, true);
|
|
lay->addWidget(wMgrs7);
|
|
QLabel *lbl7(new QLabel(dialog));
|
|
lay->addWidget(lbl7);
|
|
QObject::connect(wMgrs7, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
|
wMgrs7, [lbl7](const QPointF & coord)
|
|
{
|
|
updateLabel(coord, lbl7, 7);
|
|
});
|
|
|
|
|
|
LtsCoordWidget::LtsCoordWidget *w84(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
|
w84->setWithResetButton(true);
|
|
w84->setCoordinate(defCoord, true);
|
|
lay->addWidget(w84);
|
|
QLabel *lbl84(new QLabel(dialog));
|
|
lay->addWidget(lbl84);
|
|
QObject::connect(w84, &LtsCoordWidget::LtsCoordWidget::coordinateChanged,
|
|
w84, [lbl84](const QPointF & coord)
|
|
{
|
|
updateLabel(coord, lbl84, 11);
|
|
});
|
|
|
|
|
|
QHBoxLayout *hLay = new QHBoxLayout;
|
|
lay->addLayout(hLay);
|
|
LtsCoordWidget::LtsCoordWidget *wChange(new LtsCoordWidget::LtsCoordWidget(LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84, dialog));
|
|
wChange->setWithResetButton(true);
|
|
wChange->setCoordinate(defCoord, true);
|
|
hLay->addWidget(wChange);
|
|
QPushButton *pbReset(new QPushButton(QStringLiteral("With Reset"), dialog));
|
|
hLay->addWidget(pbReset);
|
|
QObject::connect(pbReset, &QPushButton::clicked,
|
|
wChange, [wChange]() { wChange->setWithResetButton(!wChange->withResetButton());});
|
|
QPushButton *pbNext(new QPushButton(QStringLiteral("Next Type"), dialog));
|
|
hLay->addWidget(pbNext);
|
|
QObject::connect(pbNext, &QPushButton::clicked,
|
|
wChange, [wChange]()
|
|
{
|
|
LtsCoordWidget::LtsCoordWidget::DisplayType dt = wChange->displayType();
|
|
switch (dt)
|
|
{
|
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5:
|
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7; break;
|
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS7:
|
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84; break;
|
|
case LtsCoordWidget::LtsCoordWidget::DisplayType::WGS84:
|
|
dt = LtsCoordWidget::LtsCoordWidget::DisplayType::MGRS5; break;
|
|
default:
|
|
break;
|
|
}
|
|
wChange->setDisplayType(dt);
|
|
});
|
|
|
|
|
|
QPushButton *pb(new QPushButton(QStringLiteral("Quit"), dialog));
|
|
lay->addWidget(pb);
|
|
QObject::connect(pb, &QPushButton::clicked, qApp, QCoreApplication::quit);
|
|
|
|
dialog->show();
|
|
int ret = app.exec();
|
|
delete dialog;
|
|
return ret;
|
|
}
|