KPublicTransport

journeyquerymodel.h
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_JOURNEYQUERYMODEL_H
8#define KPUBLICTRANSPORT_JOURNEYQUERYMODEL_H
9
10#include "kpublictransport_export.h"
11#include "abstractquerymodel.h"
12
13#include <KPublicTransport/JourneyRequest>
14
15namespace KPublicTransport {
16
17class Journey;
18class JourneyQueryModelPrivate;
19
20/**
21 * Model representing journey query results.
22 * This takes care of dynamically updating as results arrive from different
23 * backends, including merging them, as well as providing a way to search
24 * for earlier/later journeys for the initial request.
25 */
26class KPUBLICTRANSPORT_EXPORT JourneyQueryModel : public AbstractQueryModel
27{
28 Q_OBJECT
29
30 /** Specify the requested journey. */
31 Q_PROPERTY(KPublicTransport::JourneyRequest request READ request WRITE setRequest NOTIFY requestChanged)
32
33 /** Whether querying for later journeys is possible. */
34 Q_PROPERTY(bool canQueryNext READ canQueryNext NOTIFY canQueryPrevNextChanged)
35 /** Whether querying for earlier journey is possible. */
36 Q_PROPERTY(bool canQueryPrevious READ canQueryPrevious NOTIFY canQueryPrevNextChanged)
37
38public:
39 explicit JourneyQueryModel(QObject *parent = nullptr);
40 ~JourneyQueryModel() override;
41
42 JourneyRequest request() const;
43 /** Specify the actual journey query. */
44 void setRequest(const JourneyRequest &req);
45
46 bool canQueryNext() const;
47 /** Search for later journeys.
48 * Has no effect if canQueryNext() returns @c false.
49 */
50 Q_INVOKABLE void queryNext();
51
52 bool canQueryPrevious() const;
53 /** Search for earlier journeys.
54 * Has no effect if canQueryPrevious() returns @c false.
55 */
56 Q_INVOKABLE void queryPrevious();
57
58 enum Roles {
59 JourneyRole = Qt::UserRole,
60 ScheduledDepartureTime,
61 ScheduledArrivalTime,
62
63 /// Useful for creating sections
64 ScheduledDepartureDate
65 };
66 Q_ENUM(Roles)
67
68 int rowCount(const QModelIndex &parent) const override;
69 QVariant data(const QModelIndex &index, int role) const override;
70 QHash<int, QByteArray> roleNames() const override;
71
72 /** The current model content. */
73 const std::vector<Journey>& journeys() const;
74
75Q_SIGNALS:
76 void requestChanged();
77 void canQueryPrevNextChanged();
78
79private:
80 friend class JourneyQueryModelPrivate;
81 Q_DECLARE_PRIVATE(JourneyQueryModel)
82};
83
84}
85
86#endif // KPUBLICTRANSPORT_JOURNEYQUERYMODEL_H
Common base class for query models, do not use directly.
Model representing journey query results.
Describes a journey search.
Query operations and data types for accessing realtime public transport information from online servi...
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:10:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.