-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElaNavigationRouter.cpp
68 lines (63 loc) · 2.35 KB
/
ElaNavigationRouter.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
#include "ElaNavigationRouter.h"
#include "ElaNavigationRouterPrivate.h"
Q_SINGLETON_CREATE_CPP(ElaNavigationRouter)
Q_PROPERTY_CREATE_Q_CPP(ElaNavigationRouter, int, MaxRouteCount)
ElaNavigationRouter::ElaNavigationRouter(QObject* parent)
: QObject{parent}, d_ptr(new ElaNavigationRouterPrivate())
{
Q_D(ElaNavigationRouter);
d->q_ptr = this;
d->_pMaxRouteCount = 25;
}
ElaNavigationRouter::~ElaNavigationRouter()
{
}
ElaNavigationRouterType::NavigationRouteType ElaNavigationRouter::navigationRoute(QObject* routeObject, QString routeFunctionName, const QVariantMap& routeData, Qt::ConnectionType connectionType)
{
Q_D(ElaNavigationRouter);
if (!routeObject)
{
return ElaNavigationRouterType::ObjectInvalid;
}
if (routeFunctionName.isEmpty())
{
return ElaNavigationRouterType::FunctionNameInvalid;
}
if (d->_routeQueue.isEmpty())
{
Q_EMIT navigationRouterStateChanged(true);
}
else
{
if (d->_routeQueue.count() >= d->_pMaxRouteCount)
{
d->_routeQueue.dequeue();
}
}
QVariantMap saveData;
saveData.insert("ElaRouteObject", QVariant::fromValue<QObject*>(routeObject));
saveData.insert("ElaRouteFunctionName", routeFunctionName);
saveData.insert("ElaRouteData", routeData);
saveData.insert("ElaRouteConnectionType", QVariant::fromValue<Qt::ConnectionType>(connectionType));
d->_routeQueue.enqueue(saveData);
return ElaNavigationRouterType::Success;
}
void ElaNavigationRouter::navigationRouteBack()
{
Q_D(ElaNavigationRouter);
int routeQueneCount = d->_routeQueue.count();
if (routeQueneCount > 0)
{
if (routeQueneCount == 1)
{
Q_EMIT navigationRouterStateChanged(false);
}
QVariantMap routeSaveData = d->_routeQueue.last();
d->_routeQueue.removeLast();
QObject* routeObject = routeSaveData.value("ElaRouteObject").value<QObject*>();
QString routeFunctionName = routeSaveData.value("ElaRouteFunctionName").toString();
QVariantMap routeData = routeSaveData.value("ElaRouteData").toMap();
Qt::ConnectionType connectionType = routeSaveData.value("ElaRouteConnectionType").value<Qt::ConnectionType>();
QMetaObject::invokeMethod(routeObject, routeFunctionName.toLocal8Bit().constData(), connectionType, Q_ARG(QVariantMap, routeData));
}
}