summaryrefslogtreecommitdiffstats
path: root/app/navigation_client.cpp
blob: 426bbebfa50f1772f6fe507a3fb76d38fe4a061b (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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);

    // connect the signal to qml inside function(addRoutePointsQml -> do_addRoutePoint)
    QObject::connect(this, SIGNAL(addRoutePointsQml(QVariant, QVariant, QVariant, QVariant)),
                         parent, SLOT(do_addRoutePoint(QVariant, QVariant, QVariant, QVariant)));

    // connect the signal to qml inside function(positionQml -> do_setCoordinate)
    QObject::connect(this, SIGNAL(positionQml(QVariant, QVariant,QVariant, QVariant)),
                         parent, SLOT(do_setCoordinate(QVariant, QVariant,QVariant, QVariant)));

    // connect the signal to qml inside function(stopdemoQml -> do_stopnavidemo)
    QObject::connect(this, SIGNAL(stopdemoQml()), parent, SLOT(do_stopnavidemo()));

    // connect the signal to qml inside function(arrivedestQml -> do_arrivedest)
    QObject::connect(this, SIGNAL(arrivedestQml()), parent, SLOT(do_arrivedest()));
}

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);
    }
}