-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMapController.cpp
More file actions
62 lines (51 loc) · 1.72 KB
/
MapController.cpp
File metadata and controls
62 lines (51 loc) · 1.72 KB
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
#include "MapController.h"
#include "DroneClass.h"
/*
* Used to emit signals to our QML functions.
* Keeps logic in cpp.
* https://doc.qt.io/qt-6/signalsandslots.html
*/
// Define constructor for MapController class
MapController::MapController(QObject *parent)
// Defines all variables within our map
: QObject(parent), m_currentMapType(0), m_supportedMapTypesCount(3)
{
}
void MapController::setCenterPosition(const QVariant &lat, const QVariant &lon)
{
QPair<double, double> newCenter(lat.toDouble(), lon.toDouble());
// updateCenter below
updateCenter(newCenter);
}
void MapController::setLocationMarking(const QVariant &lat, const QVariant &lon)
{
QPair<double, double> position(lat.toDouble(), lon.toDouble());
// addMarker below
addMarker(position);
}
// emit sends the data that our cpp logic did to our QML files
void MapController::changeMapType(int index)
{
if (index < m_supportedMapTypesCount) {
m_currentMapType = index;
emit mapTypeChanged(index);
qDebug() << "[MapController.cpp] Changed to map type:" << index;
} else {
qDebug() << "[MapController.cpp] Unsupported map type index:" << index;
}
}
void MapController::updateCenter(const QPair<double, double> ¢er)
{
// used to not emit the signal if the old center matches the new center
emit centerPositionChanged(QVariant(center.first), QVariant(center.second));
}
void MapController::addMarker(const QPair<double, double> &position)
{
// Stores markers on cpp side
m_markers.append(position);
emit locationMarked(QVariant(position.first), QVariant(position.second));
}
void MapController::setZoomLevel(double level)
{
emit zoomLevelChanged(level);
}