KPublicTransport

journeyquerymodel.h
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
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 
15 namespace KPublicTransport {
16 
17 class Journey;
18 class 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  */
26 class 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 
38 public:
39  explicit JourneyQueryModel(QObject *parent = nullptr);
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  Q_ENUM(Roles)
64 
65  int rowCount(const QModelIndex &parent) const override;
66  QVariant data(const QModelIndex &index, int role) const override;
67  QHash<int, QByteArray> roleNames() const override;
68 
69  /** The current model content. */
70  const std::vector<Journey>& journeys() const;
71 
72 Q_SIGNALS:
73  void requestChanged();
74  void canQueryPrevNextChanged();
75 
76 private:
77  friend class JourneyQueryModelPrivate;
78  Q_DECLARE_PRIVATE(JourneyQueryModel)
79 };
80 
81 }
82 
83 #endif // KPUBLICTRANSPORT_JOURNEYQUERYMODEL_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Definition: location.h:16
UserRole
Model representing journey query results.
Common base class for query models, do not use directly.
Describes a journey search.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.