KItinerary

jsapi/jsonld.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QDateTime>
10#include <QObject>
11
12class QJSEngine;
13class QJSValue;
14
15namespace KItinerary {
16namespace JsApi {
17
18/** Methods to create JSON-LD objects. */
19class JsonLd : public QObject
20{
22public:
23 ///@cond internal
24 explicit JsonLd(QJSEngine *engine);
25 ~JsonLd();
26 ///@endcond
27
28 /** Create a new JSON-LD object of type @p typeName. */
29 Q_INVOKABLE QJSValue newObject(const QString &typeName) const;
30
31 /** Convenience method that generates a full FlightReservation JS object.
32 * This can be used by extractor scripts to fill in the extracted information.
33 */
35 /** Convenience method that generates a full TrainReservation JS object.
36 * This can be used by extractor scripts to fill in the extracted information.
37 */
39 /** Convenience method that generates a full BusReservation JS object.
40 * This can be used by extractor scripts to fill in the extracted information.
41 */
43 /** Convenience method that generates a full LodgingReservation JS object.
44 * This can be used by extractor scripts to fill in the extracted information.
45 */
47 /** Convenience method that generates a full EventReservation JS object.
48 * This can be used by extractor scripts to fill in the extracted information.
49 */
51 /** Convenience method that generates a full FoodEstablishmentReservation JS object.
52 * This can be used by extractor scripts to fill in the extracted information.
53 */
55 /** Convenience method that generates a full RentalCarReservation JS object.
56 * This can be used by extractor scripts to fill in the extracted information.
57 */
59 /** Convenience method that generates a full BoatReservation JS object.
60 * This can be used by extractor scripts to fill in the extracted information.
61 */
63
64 /** Convert a train reservation to a bus reservation. */
66 /** Convert a bus reservation to a train reservation. */
68
69 /** Convert a date/time string to a date/time value.
70 * @param dtStr The input string containing a date/time value.
71 * @param format The format of the input string. Same format specification as
72 * used by QLocale and QDateTime. If the year is not part of the date
73 * it is attempted to be recovered from the context date set on the
74 * ExtractorEngine (that is, the returned date will be after the context
75 * date). Can be a string or an array of strings, which are then tried sequentially.
76 * @param localeName The locale in which the string is formatted. This is
77 * relevant when the input contains for example localized month names or
78 * month abbreviations. Can be a string or an array of strings.
79 */
80 Q_INVOKABLE QDateTime toDateTime(const QString &dtStr, const QJSValue &format, const QJSValue &localeName) const;
81 /** Convert object @p v to a JSON-LD object.
82 * This is useful when interacting with API returning regular data types,
83 * such as Uic9183Parser.
84 */
85 Q_INVOKABLE QJSValue toJson(const QVariant &v) const;
86 /** Clones the given JS object.
87 * That is, create a deep copy of @p v.
88 */
89 Q_INVOKABLE QJSValue clone(const QJSValue &v) const;
90 /** Parses geo coordinates from a given mapping service URLs.
91 * This consumes for example Google Maps links and returns a JSON-LD
92 * GeoCoordinates object.
93 */
95
96 /** Read a QDateTime property and return a JSON-LD serialization of it.
97 * This is a workaround for JS destroying timezone information when getting in touch with a QDateTime
98 * object. With this method it is safe to read a QDateTime property e.g. from a Qt gadget or QObject
99 * without the risk of losing information.
100 * @param obj The object to read from.
101 * @param propName The name of the property to read.
102 */
103 Q_INVOKABLE QJSValue readQDateTime(const QVariant &obj, const QString &propName) const;
104
105 /** @see JsonLdDocument::apply. */
106 Q_INVOKABLE QJSValue apply(const QJSValue &lhs, const QJSValue &rhs) const;
107
108 ///@cond internal
109 void setContextDate(const QDateTime &dt);
110 ///@endcond
111private:
112 QJSValue newPlace(const QString &type) const;
113 QDateTime toDateTime(const QString &dtStr, const QString &format, const QString &localeName) const;
114 QJSEngine *m_engine;
115 QDateTime m_contextDate;
116};
117
118}
119}
120
Methods to create JSON-LD objects.
Q_INVOKABLE QJSValue newEventReservation() const
Convenience method that generates a full EventReservation JS object.
Q_INVOKABLE QJSValue toGeoCoordinates(const QString &mapUrl)
Parses geo coordinates from a given mapping service URLs.
Q_INVOKABLE QJSValue newLodgingReservation() const
Convenience method that generates a full LodgingReservation JS object.
Q_INVOKABLE QJSValue newBusReservation() const
Convenience method that generates a full BusReservation JS object.
Q_INVOKABLE QJSValue busToTrainReservation(const QJSValue &busRes) const
Convert a bus reservation to a train reservation.
Q_INVOKABLE QJSValue newObject(const QString &typeName) const
Create a new JSON-LD object of type typeName.
Q_INVOKABLE QJSValue apply(const QJSValue &lhs, const QJSValue &rhs) const
Q_INVOKABLE QJSValue clone(const QJSValue &v) const
Clones the given JS object.
Q_INVOKABLE QJSValue toJson(const QVariant &v) const
Convert object v to a JSON-LD object.
Q_INVOKABLE QJSValue newRentalCarReservation() const
Convenience method that generates a full RentalCarReservation JS object.
Q_INVOKABLE QDateTime toDateTime(const QString &dtStr, const QJSValue &format, const QJSValue &localeName) const
Convert a date/time string to a date/time value.
Q_INVOKABLE QJSValue readQDateTime(const QVariant &obj, const QString &propName) const
Read a QDateTime property and return a JSON-LD serialization of it.
Q_INVOKABLE QJSValue newFoodEstablishmentReservation() const
Convenience method that generates a full FoodEstablishmentReservation JS object.
Q_INVOKABLE QJSValue newTrainReservation() const
Convenience method that generates a full TrainReservation JS object.
Q_INVOKABLE QJSValue newFlightReservation() const
Convenience method that generates a full FlightReservation JS object.
Q_INVOKABLE QJSValue newBoatReservation() const
Convenience method that generates a full BoatReservation JS object.
Q_INVOKABLE QJSValue trainToBusReservation(const QJSValue &trainRes) const
Convert a train reservation to a bus reservation.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.