KPublicTransport

onboardstatus.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "onboardstatus.h"
7#include "onboardstatusmanager_p.h"
8
9#include <KPublicTransport/Journey>
10
11#include <cmath>
12
13using namespace KPublicTransport;
14
15namespace KPublicTransport {
16class OnboardStatusPrivate
17{
18public:
19 int positionUpdateInterval = -1;
20 int journeyUpdateInterval = -1;
21};
22}
23
24OnboardStatus::OnboardStatus(QObject *parent)
25 : QObject(parent)
26 , d(new OnboardStatusPrivate)
27{
28 auto mgr = OnboardStatusManager::instance();
29 connect(mgr, &OnboardStatusManager::statusChanged, this, &OnboardStatus::statusChanged);
30 connect(mgr, &OnboardStatusManager::positionChanged, this, &OnboardStatus::positionChanged);
31 connect(mgr, &OnboardStatusManager::supportsPositionChanged, this, &OnboardStatus::supportsPositionChanged);
32 connect(mgr, &OnboardStatusManager::journeyChanged, this, &OnboardStatus::journeyChanged);
33 connect(mgr, &OnboardStatusManager::supportsJourneyChanged, this, &OnboardStatus::supportsJourneyChanged);
34 OnboardStatusManager::instance()->registerFrontend(this);
35}
36
37OnboardStatus::~OnboardStatus()
38{
39 OnboardStatusManager::instance()->unregisterFrontend(this);
40}
41
42OnboardStatus::Status OnboardStatus::status() const
43{
44 return OnboardStatusManager::instance()->status();
45}
46
47float OnboardStatus::latitude() const
48{
49 return OnboardStatusManager::instance()->currentPosition().latitude;
50}
51
52float OnboardStatus::longitude() const
53{
54 return OnboardStatusManager::instance()->currentPosition().longitude;
55}
56
58{
59 return OnboardStatusManager::instance()->currentPosition().hasCoordinate();
60}
61
63{
64 return OnboardStatusManager::instance()->supportsPosition();
65}
66
67float OnboardStatus::speed() const
68{
69 return OnboardStatusManager::instance()->currentPosition().speed;
70}
71
72bool OnboardStatus::hasSpeed() const
73{
74 return !std::isnan(speed());
75}
76
77float OnboardStatus::heading() const
78{
79 return OnboardStatusManager::instance()->currentPosition().heading;
80}
81
82bool OnboardStatus::hasHeading() const
83{
84 return !std::isnan(heading());
85}
86
87float OnboardStatus::altitude() const
88{
89 return OnboardStatusManager::instance()->currentPosition().altitude;
90}
91
92bool OnboardStatus::hasAltitude() const
93{
94 return !std::isnan(altitude());
95}
96
98{
99 return OnboardStatusManager::instance()->currentJourney();
100}
101
102bool OnboardStatus::hasJourney() const
103{
104 return !OnboardStatusManager::instance()->currentJourney().sections().empty();
105}
106
108{
109 return OnboardStatusManager::instance()->supportsJourney();
110}
111
113{
114 return d->positionUpdateInterval;
115}
116
117void OnboardStatus::setPositionUpdateInterval(int interval)
118{
119 if (d->positionUpdateInterval == interval) {
120 return;
121 }
122
123 d->positionUpdateInterval = interval;
124 Q_EMIT updateIntervalChanged();
125}
126
127int OnboardStatus::journeyUpdateInterval() const
128{
129 return d->journeyUpdateInterval;
130}
131
132void OnboardStatus::setJourneyUpdateInterval(int interval)
133{
134 if (d->journeyUpdateInterval == interval) {
135 return;
136 }
137
138 d->journeyUpdateInterval = interval;
139 Q_EMIT updateIntervalChanged();
140}
141
143{
144 OnboardStatusManager::instance()->requestPosition();
145}
146
148{
149 OnboardStatusManager::instance()->requestJourney();
150}
151
153{
154 OnboardStatusManager::instance()->requestPermissions();
155}
156
157#include "moc_onboardstatus.cpp"
A journey plan.
Definition journey.h:246
float altitude
Current altitude in meters, NAN if unknown.
bool supportsJourney
Whether the backend supports querying for the journey.
bool supportsPosition
Whether the backend supports querying for the geographic position.
Q_INVOKABLE void requestPermissions()
Request application permission needed for Wi-Fi montioring.
float speed
Current speed in km/h.
Q_INVOKABLE void requestPosition()
Request one time update of the position status.
bool hasPosition
Whether the geographic position is currently available.
float heading
Current heading in degree, NAN if unknown.
bool hasJourney
Whether there is journey information available.
int positionUpdateInterval
Update polling intervals in seconds.
KPublicTransport::Journey journey
The current journey.
float latitude
Current geographic position, NAN if not available.
Q_INVOKABLE void requestJourney()
Request one time journey data update, if available.
Query operations and data types for accessing realtime public transport information from online servi...
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.