KPublicTransport

feature.h
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KPUBLICTRANSPORT_FEATURE_H
7#define KPUBLICTRANSPORT_FEATURE_H
8
9#include "kpublictransport_export.h"
10#include "datatypes.h"
11#include "disruption.h"
12
13namespace KPublicTransport {
14
15class FeaturePrivate;
16
17/** An amenity, facility or other relevant property of a vehicle (train, bus, etc),
18 * vehicle part (e.g. train coach) or location.
19 */
20class KPUBLICTRANSPORT_EXPORT Feature {
21 KPUBLICTRANSPORT_GADGET(Feature)
22
23 /** A short human-readable label of this feature. */
24 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
25
26 /** A short humand-readable label for this feature.
27 * Unlike name this returns a default label depending on the type
28 * of the feature, even if the data source for this didn't provide
29 * a name.
30 */
31 Q_PROPERTY(QString displayName READ displayName STORED false)
32
33 /** An optional longer human-readable description.
34 * Strongly recommended e.g. for features with limited/condicational
35 * availability or with type @c Other.
36 */
37 KPUBLICTRANSPORT_PROPERTY(QString, description, setDescription)
38
39 /** Type of the feature. */
40 enum Type {
41 NoFeature, ///< uninitialized/null
42 AirConditioning, ///< area is air conditioned
43 Restaurant, ///< a place to obtain food/drinks
44 ToddlerArea, ///< infrastructure for toddler maintenance
45 FamilyArea, ///< area dedicated for travelers with kids
46 WheelchairAccessible, ///< wheelchair access possible
47 SilentArea, ///< wishful thinking usually
48 BusinessArea,
49 BikeStorage, ///< vehicle contains space for bikes
50 Toilet,
51 WheelchairAccessibleToilet, ///< wheelchair accessible toilet
52 InformationPoint, ///< a place to obtain information from a human
53 WiFi, ///< Freely usable Wi-Fi network
54 PowerSockets, ///< Power sockets for passenger use
55 Other, ///< none of the above
56 };
57 Q_ENUM(Type)
58 KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
59
60 /** Availability of the feature. */
61 enum Availability {
62 Unknown,
63 Available,
64 Unavailable, ///< It is known the specified feature does not exist (!= features is (temporarily) disrupted)
65 Limited, ///< e.g. limited quantity
66 Conditional, ///< e.g. feature is available only on explicit reservation or with a specific ticket/tariff
67 };
68 Q_ENUM(Availability)
69 KPUBLICTRANSPORT_PROPERTY(Availability, availability, setAvailability)
70
71 /** Distruption effects on the feature. */
72 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect)
73
74 /** Amount of instances of this feature.
75 * Eg. number of seats/spaces, 0 if unknown.
76 */
77 KPUBLICTRANSPORT_PROPERTY(int, quantity, setQuantity)
78
79 /** Icon representing the given feature type @p type.
80 * Can be an qrc: URL or a icon name compatbile with QIcon::fromTheme.
81 */
82 Q_PROPERTY(QString typeIconName READ typeIconName STORED false)
83
84public:
85 /** Convenience constructor for a Feature of type @p type and availability @p availability. */
86 explicit Feature(Type type, Availability availability = Available);
87
88 [[nodiscard]] QString displayName() const;
89 [[nodiscard]] QString typeIconName() const;
90
91 /** Generic display name for feature of @p type. */
92 [[nodiscard]] static QString typeDisplayName(KPublicTransport::Feature::Type type);
93 /** Icon representing the given feature type @p type.
94 * Can be an qrc: URL or a icon name compatbile with QIcon::fromTheme.
95 */
96 [[nodiscard]] static QString typeIconName(KPublicTransport::Feature::Type type);
97
98 /** Serializes one object to JSON. */
99 [[nodiscard]] static QJsonObject toJson(const Feature &feature);
100 /** Serializes a vector of features to JSON. */
101 [[nodiscard]] static QJsonArray toJson(const std::vector<Feature> &features);
102 /** Deserialize an object from JSON. */
103 [[nodiscard]] static Feature fromJson(const QJsonObject &obj);
104 /** Deserialize a vector of features from JSON. */
105 [[nodiscard]] static std::vector<Feature> fromJson(const QJsonArray &array);
106
107 /** Returns @c true if both features refer to the same thing.
108 * This doesn't mean they are identical, nor does this consider the context
109 * a feature belongs to.
110 */
111 [[nodiscard]] static bool isSame(const Feature &lhs, const Feature &rhs);
112 /** Merge two features referring to the same thing. */
113 [[nodiscard]] static Feature merge(const Feature &lhs, const Feature &rhs);
114};
115
116}
117
118#endif
An amenity, facility or other relevant property of a vehicle (train, bus, etc), vehicle part (e....
Definition feature.h:20
Query operations and data types for accessing realtime public transport information from online servi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.