-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainwindow.cpp
119 lines (89 loc) · 3.53 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QResizeEvent>
#include <QFileDialog>
#include <QStandardPaths>
#include "QGtifReader.h"
#include <QSettings>
#include <QMessageBox>
#include <QMenu>
#include "logging.h"
Q_LOGGING_CATEGORY_DEFAULT(MainWindow)
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->lblLogo->setStyleSheet(QStringLiteral("background-color : white;"));
connect(ui->lwPoints, &QListWidget::customContextMenuRequested, this, &MainWindow::onCustomContextMenuRequested);
_mapView = new MapView(ui->mapViewContainer);
connect(_mapView, &MapView::GeoCoordinateOnMap, this, &MainWindow::onClickedOnMap);
connect(_mapView, &MapView::pathBuildFinished, this, &MainWindow::onPathBuildFinished);
connect(qGtifReader, &QGtifReader::fileChanged, this, &MainWindow::onTifFileChanged);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onClickedOnMap(QGeoCoordinate coord)
{
using namespace Global;
ui->lblLatitude->setText(MakeGeoPrintable(coord.latitude(), GeoType::Latitude));
ui->lblLongitude->setText(MakeGeoPrintable(coord.longitude(),GeoType::Longitude));
ui->lblAltitude->setText(MakeMeterPrintable(coord.altitude()));
}
void MainWindow::onTifFileChanged()
{
ui->lblMapCoordType->setText(qGtifReader->getPCSInfo());
_mapView->resloveView();
}
void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
{
auto _currentItem = static_cast<QListWidgetItem *>(ui->lwPoints->itemAt(pos));
QMenu menu(ui->lwPoints);
if(_currentItem){
QAction *actRemove = new QAction(tr("&Remove"), &menu);
int index = ui->lwPoints->currentRow();
connect(actRemove, &QAction::triggered, [this, index]() { _mapView->removePathPointAt(index); });
menu.addAction(actRemove);
}
QAction *newAct = new QAction(tr("&Delete All"), &menu);
connect(newAct, &QAction::triggered, _mapView, &MapView::removeAllPathPoint);
menu.addAction(newAct);
menu.exec(ui->lwPoints->mapToGlobal(pos));
}
void MainWindow::onPathBuildFinished(QList<QPointF> points)
{
static QString format = QStringLiteral("%1 : %2");
QStringList labels;
for(int i = 1, len = points.size(); i < len; ++i) {
auto dist = qGtifReader->getDistanceMByPoint(points.at(i), points.at(i - 1));
auto text = format.arg(i).arg(Global::MakeMeterPrintable(dist));
labels << text;
}
ui->lwPoints->clear();
if(points.isEmpty())
return;
ui->lwPoints->addItems(labels);
}
void MainWindow::resizeEvent(QResizeEvent *)
{
_mapView->resize(ui->mapViewContainer->size());
ui->lblLogo->setPixmap(QPixmap(":/img/logo.png").scaled(ui->lblLogo->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void MainWindow::on_pushButton_clicked()
{
QString lastpath = Global::loadSettings(
QStringLiteral("lastpath"),
QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).at(0)
).toString();
QString path = QFileDialog::getOpenFileName(this, tr("Select tif"), lastpath, QStringLiteral("*.tif"));
if(path.isEmpty())
return;
Global::saveSettings(QStringLiteral("lastpath"), QFileInfo(path).canonicalPath());
if(!qGtifReader->setFilePath(path)) {
QMessageBox::critical(this, tr("Error"), tr("File format error"));
return;
}
setWindowTitle(path);
}