KPublicTransport

reply.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_REPLY_H
8#define KPUBLICTRANSPORT_REPLY_H
9
10#include "kpublictransport_export.h"
11
12#include <QObject>
13
14#include <memory>
15
16namespace KPublicTransport {
17
18class AbstractBackend;
19class Attribution;
20class Manager;
21class ReplyPrivate;
22
23/** Query response base class. */
24class KPUBLICTRANSPORT_EXPORT Reply : public QObject
25{
28 Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
29public:
30 ~Reply() override;
31
32 /** Error types. */
33 enum Error {
34 NoError, ///< Nothing went wrong.
35 NetworkError, ///< Error during network operations.
36 NotFoundError, ///< The requested journey/departure/place could not be found.
37 InvalidRequest, ///< Incomplete or otherwise invalid request.
38 NoBackend, ///< No backend was found to satisfy this request, e.g. due to no backend covering the requested area.
39 UnknownError ///< Anything else.
40 };
41 Q_ENUM(Error)
42
43 /** Error code. */
44 [[nodiscard]] Error error() const;
45 /** Textual error message. */
46 [[nodiscard]] QString errorString() const;
47
48 /** Returns the attributions for the provided data. */
49 [[nodiscard]] const std::vector<Attribution>& attributions() const;
50 /** Returns the attributions for the provided data for moving them elsewhere. */
51 std::vector<Attribution>&& takeAttributions();
52
53Q_SIGNALS:
54 /** Emitted whenever the corresponding search has been completed. */
55 void finished();
56 /** Emitted whenever new results are available, even before the search has been completed.
57 * @note At this point no guarantees about the result apply, sorting/merging/etc might not have been applied yet
58 * and not all properties of the reply might be valid. Avoid the usage of this in general, unless you write
59 * dynamically updating models that need very quick results at the expensive of incompleteness.
60 */
61 void updated();
62
63protected:
64 ///@cond internal
65 Q_DECL_HIDDEN explicit Reply(ReplyPrivate *dd, QObject *parent);
66 std::unique_ptr<ReplyPrivate> d_ptr;
67
68 friend class AbstractBackend;
69 /** Used for a backend to report it finished it's job with an error.
70 * Prefer to use the variants of this provided by the type-specific sub-classes
71 * which also add the corresponding negative cache entries if appropriate.
72 */
73 Q_DECL_HIDDEN void addError(Error error, const QString &errorMsg);
74 Q_DECL_HIDDEN void addAttributions(std::vector<Attribution> &&attributions);
75 Q_DECL_HIDDEN void addAttributions(const std::vector<Attribution> &attributions);
76
77 friend class Manager;
78 friend class ManagerPrivate;
79 Q_DECL_HIDDEN void setPendingOps(int ops);
80 Q_DECL_HIDDEN void addAttribution(const Attribution &attr);
81 ///@endcond
82};
83
84}
85
86#endif // KPUBLICTRANSPORT_JOURNEYREPLY_H
Copyright and license information about the provided data.
Definition attribution.h:29
Entry point for starting public transport queries.
Definition manager.h:42
Query response base class.
Definition reply.h:25
void finished()
Emitted whenever the corresponding search has been completed.
void updated()
Emitted whenever new results are available, even before the search has been completed.
const std::vector< Attribution > & attributions() const
Returns the attributions for the provided data.
Definition reply.cpp:84
Error
Error types.
Definition reply.h:33
@ InvalidRequest
Incomplete or otherwise invalid request.
Definition reply.h:37
@ NoBackend
No backend was found to satisfy this request, e.g. due to no backend covering the requested area.
Definition reply.h:38
@ NetworkError
Error during network operations.
Definition reply.h:35
@ UnknownError
Anything else.
Definition reply.h:39
@ NoError
Nothing went wrong.
Definition reply.h:34
@ NotFoundError
The requested journey/departure/place could not be found.
Definition reply.h:36
Query operations and data types for accessing realtime public transport information from online servi...
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:50:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.