-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapWindow.cpp
127 lines (99 loc) · 4 KB
/
MapWindow.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
120
121
122
123
124
125
126
127
#include "MapWindow.h"
#include <QVBoxLayout>
#include <QMenuBar>
#include <QFileDialog>
#include <marble/GeoDataMultiGeometry.h>
#include <marble/GeoDataLineString.h>
#include <marble/GeoDataDocument.h>
#include <marble/MarbleModel.h>
#include <marble/GeoDataTreeModel.h>
#include <marble/GeoDataPlacemark.h>
#include <marble/GeoDataLineStyle.h>
#include <marble/GeoDataLinearRing.h>
#include <marble/MarbleWidgetInputHandler.h>
using namespace Marble;
MapWindow::MapWindow(QWidget *parent) : QWidget(parent), mapWidget(new Marble::MarbleWidget()), pointMap(nullptr), worker(MarbleWorker(this)), progressBar(QProgressBar(this)), amountOfPointsSlider(QSlider(Qt::Horizontal, this)), amountOfPointsLabel(QString("Showing 10 starting points"), this) {
this->connect(&worker, &MarbleWorker::mapUpdated, this, &MapWindow::receiveMapUpdated);
this->connect(mapWidget, &MarbleWidget::zoomChanged, this, &MapWindow::handleZoomChanged);
mapWidget->setProjection(Mercator);
mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
mapWidget->setShowCrosshairs(false);
mapWidget->setShowGrid(false);
mapWidget->setShowCompass(false);
mapWidget->setShowOverviewMap(false);
mapWidget->inputHandler()->setMouseButtonPopupEnabled(Qt::LeftButton, false);
//mapWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
// Get menu bar going
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(mapWidget);
QMenuBar *menuBar = new QMenuBar();
QMenu *fileMenu = new QMenu("File");
fileMenu->addAction("Load GML", this, SLOT(loadGml()));
fileMenu->addAction("Find starting points", this, SLOT(findStartingPoints()));
fileMenu->addAction("Quit");
this->connect(mapWidget, &MarbleWidget::mouseClickGeoPosition, this, &MapWindow::receiveMouseClicked);
this->connect(&amountOfPointsSlider, &QSlider::valueChanged, this, &MapWindow::receiveSliderMoved);
this->connect(&amountOfPointsSlider, &QSlider::sliderReleased, this, &MapWindow::receiveSliderReleased);
menuBar->addMenu(fileMenu);
layout->setMenuBar(menuBar);
amountOfPointsLabel.setAlignment(Qt::AlignCenter);
layout->addWidget(&amountOfPointsLabel);
amountOfPointsSlider.setTickInterval(1);
amountOfPointsSlider.setRange(1, 100);
amountOfPointsSlider.setValue(amountOfPoints);
layout->addWidget(&amountOfPointsSlider);
layout->addWidget(&progressBar);
layout->setStretchFactor(mapWidget, 1);
layout->setStretchFactor(&amountOfPointsLabel, 0);
}
void MapWindow::loadGml() {
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Load GML file"), "", tr("GML Files (*.gml);;All Files (*)"));
worker.loadData(fileNames);
}
void MapWindow::findStartingPoints() {
worker.findStartingPoints();
}
void MapWindow::receiveMouseClicked(float lon, float lat, GeoDataCoordinates::Unit unit) {
if (unit == GeoDataCoordinates::Radian) {
lon *= 180 / M_PI;
lat *= 180 / M_PI;
}
worker.receiveClick(lat,lon);
}
void MapWindow::exit() {
}
void MapWindow::receiveMapUpdated(GeoDataDocument *document, bool appendDocument, QString message, int percent) {
if (!appendDocument) {
for (GeoDataDocument *document : documents) {
mapWidget->model()->treeModel()->removeDocument(document);
delete document;
}
documents.clear();
}
if (document != nullptr) {
mapWidget->model()->treeModel()->addDocument(document);
documents.push_back(document);
}
progressBar.setMinimum(0);
progressBar.setMaximum(100);
progressBar.setValue(percent);
progressBar.setFormat(message);
}
void MapWindow::receiveSliderMoved(int newValue) {
QString amountOfPointsString("Showing %1 starting points");
if (newValue == 100) {
amountOfPointsString = amountOfPointsString.arg("all");
} else {
amountOfPointsString = amountOfPointsString.arg(newValue);
}
amountOfPointsLabel.setText(amountOfPointsString);
amountOfPoints = newValue;
if (!amountOfPointsSlider.isSliderDown()) {
receiveSliderReleased();
}
}
void MapWindow::receiveSliderReleased() {
worker.receiveRedrawStartingPoints(amountOfPoints);
}
void MapWindow::handleZoomChanged(int zoomLevel) {
}