summaryrefslogtreecommitdiffstats
path: root/app/navigation_client.cpp
blob: f07f6c7cd64d9d53ade045e7a3b894c34d8ab8e4 (plain)
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
#include "navigation_client.h"

navigation_client::navigation_client(Navigation *navigation, QObject *parent) :
  m_navigation(navigation)
{
    QObject::connect(m_navigation, &Navigation::statusEvent, this, &navigation_client::statusEvent);
    QObject::connect(m_navigation, &Navigation::positionEvent, this, &navigation_client::positionEvent);
}

navigation_client::~navigation_client(){}

void navigation_client::statusEvent(QVariantMap data)
{
    if (!data.contains("state"))
        return;

    QString state = data["state"].toString();

    if (state == "arrived")
        emit arrivedestQml();

    if (state == "stopped" || state == "stop")
        emit stopdemoQml();
}

void navigation_client::positionEvent(QVariantMap data)
{
    if (!data.contains("position"))
        return;;

    QString position = data["position"].toString();

    if (position == "route") {
        double route_Lat_s = data["latitude"].toDouble();
        double route_Lon_s = data["longitude"].toDouble();
        double route_Lat_e = data["route_latitude"].toDouble();
        double route_Lon_e = data["route_longitude"].toDouble();

        emit addRoutePointsQml(route_Lat_s, route_Lon_s, route_Lat_e, route_Lon_e);
    }

    if (position == "car") {
        double cur_Lat_p = data["latitude"].toDouble();
        double cur_Lon_p = data["longitude"].toDouble();
        double cur_direction = data["direction"].toDouble();
        double cur_distance = data["distance"].toDouble();

        emit positionQml(cur_Lat_p, cur_Lon_p, cur_direction, cur_distance);
    }
}