Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
4eb10601
Commit
4eb10601
authored
Oct 06, 2021
by
Volker Krause
Browse files
Extend JourneySection to be able to hold individual transport data
parent
b8a388e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/lib/datatypes/individualtransport.cpp
View file @
4eb10601
...
...
@@ -38,6 +38,11 @@ bool IndividualTransport::operator==(const IndividualTransport &other) const
return
d
->
mode
==
other
.
mode
()
&&
d
->
qualifier
==
other
.
qualifier
();
}
bool
IndividualTransport
::
operator
!=
(
const
IndividualTransport
&
other
)
const
{
return
d
->
mode
!=
other
.
mode
()
||
d
->
qualifier
!=
other
.
qualifier
();
}
QJsonObject
IndividualTransport
::
toJson
(
const
IndividualTransport
&
it
)
{
return
Json
::
toJson
(
it
);
...
...
src/lib/datatypes/individualtransport.h
View file @
4eb10601
...
...
@@ -44,6 +44,7 @@ public:
IndividualTransport
(
Mode
mode
,
Qualifier
qualifier
=
None
);
bool
operator
==
(
const
IndividualTransport
&
other
)
const
;
bool
operator
!=
(
const
IndividualTransport
&
other
)
const
;
/** Serializes one object to JSON. */
static
QJsonObject
toJson
(
const
IndividualTransport
&
it
);
...
...
src/lib/datatypes/journey.cpp
View file @
4eb10601
...
...
@@ -50,6 +50,7 @@ public:
Platform
departurePlatformLayout
;
Vehicle
arrivalVehicleLayout
;
Platform
arrivalPlatformLayout
;
IndividualTransport
individualTransport
;
};
class
JourneyPrivate
:
public
QSharedData
...
...
@@ -77,6 +78,7 @@ KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Vehicle, departureVehicleLayout,
KPUBLICTRANSPORT_MAKE_PROPERTY
(
JourneySection
,
Platform
,
departurePlatformLayout
,
setDeparturePlatformLayout
)
KPUBLICTRANSPORT_MAKE_PROPERTY
(
JourneySection
,
Vehicle
,
arrivalVehicleLayout
,
setArrivalVehicleLayout
)
KPUBLICTRANSPORT_MAKE_PROPERTY
(
JourneySection
,
Platform
,
arrivalPlatformLayout
,
setArrivalPlatformLayout
)
KPUBLICTRANSPORT_MAKE_PROPERTY
(
JourneySection
,
KPublicTransport
::
IndividualTransport
,
individualTransport
,
setIndividualTransport
)
bool
JourneySection
::
hasExpectedDepartureTime
()
const
{
...
...
@@ -350,6 +352,10 @@ bool JourneySection::isSame(const JourneySection &lhs, const JourneySection &rhs
return
false
;
}
if
(
lhs
.
d
->
mode
==
JourneySection
::
IndividualTransport
&&
lhs
.
d
->
individualTransport
!=
rhs
.
d
->
individualTransport
)
{
return
false
;
}
// we have N criteria to compare here, with 3 possible results:
// - equal
// - similar-ish, unknwon, or at least not conflicting
...
...
@@ -482,6 +488,10 @@ QJsonObject JourneySection::toJson(const JourneySection §ion)
obj
.
insert
(
QLatin1String
(
"arrivalPlatformLayout"
),
Platform
::
toJson
(
section
.
arrivalPlatformLayout
()));
}
if
(
section
.
mode
()
==
JourneySection
::
IndividualTransport
)
{
obj
.
insert
(
QLatin1String
(
"individualTransport"
),
IndividualTransport
::
toJson
(
section
.
individualTransport
()));
}
if
(
obj
.
size
()
<=
3
)
{
// only the disruption and mode enums and distance, ie. this is an empty object
return
{};
}
...
...
@@ -507,6 +517,7 @@ JourneySection JourneySection::fromJson(const QJsonObject &obj)
section
.
setDeparturePlatformLayout
(
Platform
::
fromJson
(
obj
.
value
(
QLatin1String
(
"departurePlatformLayout"
)).
toObject
()));
section
.
setArrivalVehicleLayout
(
Vehicle
::
fromJson
(
obj
.
value
(
QLatin1String
(
"arrivalVehicleLayout"
)).
toObject
()));
section
.
setArrivalPlatformLayout
(
Platform
::
fromJson
(
obj
.
value
(
QLatin1String
(
"arrivalPlatformLayout"
)).
toObject
()));
section
.
setIndividualTransport
(
IndividualTransport
::
fromJson
(
obj
.
value
(
QLatin1String
(
"individualTransport"
)).
toObject
()));
return
section
;
}
...
...
src/lib/datatypes/journey.h
View file @
4eb10601
...
...
@@ -9,6 +9,7 @@
#include
"datatypes.h"
#include
"disruption.h"
#include
"individualtransport.h"
#include
"line.h"
#include
"load.h"
#include
"location.h"
...
...
@@ -42,6 +43,7 @@ public:
Walking
=
4
,
Waiting
=
8
,
RentedVehicle
=
16
,
///< free floating or dock-based rental bike service, electric scooters, car sharing services, ie. any vehicle you drive yourself but that isn't your own
IndividualTransport
=
32
,
///< using your own vehicle (bike, car, etc).
};
Q_ENUM
(
Mode
)
Q_DECLARE_FLAGS
(
Modes
,
Mode
)
...
...
@@ -150,6 +152,9 @@ public:
/** Platform layout information at arrival. */
KPUBLICTRANSPORT_PROPERTY
(
KPublicTransport
::
Platform
,
arrivalPlatformLayout
,
setArrivalPlatformLayout
)
/** Individual transport details for sections using your own vehicle. */
KPUBLICTRANSPORT_PROPERTY
(
KPublicTransport
::
IndividualTransport
,
individualTransport
,
setIndividualTransport
)
public:
bool
hasExpectedDepartureTime
()
const
;
int
departureDelay
()
const
;
...
...
tests/journeyquery.qml
View file @
4eb10601
...
...
@@ -107,7 +107,8 @@ Kirigami.ApplicationWindow {
{
switch
(
loc
.
type
)
{
case
Location.Stop
:
return
"
🚏
"
+
loc
.
name
;
case
Location.RentedVehicleStation
:
return
"
🚲
"
+
loc
.
name
;
case
Location.RentedVehicleStation
:
return
"
🚏🚲
"
+
loc
.
name
;
case
Location.RentedVehicle
:
return
"
🚲
"
+
loc
.
name
;
case
Location.Place
:
return
loc
.
name
;
}
}
...
...
@@ -181,14 +182,22 @@ Kirigami.ApplicationWindow {
case
JourneySection
.
RentedVehicle
:
{
switch
(
modelData
.
rentalVehicle
.
type
)
{
case
RentalVehicle
.
Bicycle
:
return
"
🚲
"
;
case
RentalVehicle
.
Pedelec
:
return
"
🚲
"
;
case
RentalVehicle
.
ElectricKickScooter
:
return
"
🛴
"
;
case
RentalVehicle
.
ElectricMoped
:
return
"
🛵
"
;
case
RentalVehicle
.
Car
:
return
"
🚗
"
;
case
RentalVehicle
.
Bicycle
:
return
"
🔑
🚲
"
;
case
RentalVehicle
.
Pedelec
:
return
"
🔑🔌
🚲
"
;
case
RentalVehicle
.
ElectricKickScooter
:
return
"
🔑
🛴
"
;
case
RentalVehicle
.
ElectricMoped
:
return
"
🔑
🛵
"
;
case
RentalVehicle
.
Car
:
return
"
🔑
🚗
"
;
default
:
return
"
?
"
;
}
}
case
JourneySection
.
IndividualTransport
:
{
switch
(
modelData
.
individualTransport
.
mode
)
{
case
IndividualTransport
.
Walk
:
return
"
🚶
"
;
case
IndividualTransport
.
Bike
:
return
"
🚲
"
;
case
IndividualTransport
.
Car
:
return
"
🚗
"
;
}
}
default
:
return
"
?
"
;
}
}
...
...
@@ -243,6 +252,8 @@ Kirigami.ApplicationWindow {
return
"
Wait
"
+
displayDuration
(
modelData
.
duration
)
case
JourneySection
.
RentedVehicle
:
return
"
Drive (
"
+
modelData
.
rentalVehicle
.
network
.
name
+
"
)
"
+
displayDuration
(
modelData
.
duration
)
+
"
/
"
+
displayDistance
(
modelData
.
distance
);
case
JourneySection
.
IndividualTransport
:
return
"
Drive
"
+
displayDuration
(
modelData
.
duration
)
+
"
/
"
+
displayDistance
(
modelData
.
distance
)
return
"
???
"
;
}}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment