KPublicTransport

stopoverquerymodel.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_STOPOVERQUERYMODEL_H
8 #define KPUBLICTRANSPORT_STOPOVERQUERYMODEL_H
9 
10 #include "kpublictransport_export.h"
11 #include "abstractquerymodel.h"
12 
13 #include <KPublicTransport/StopoverRequest>
14 
15 namespace KPublicTransport {
16 
17 class Stopover;
18 class StopoverQueryModelPrivate;
19 
20 /**
21  * Model representing arrival or departure 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 arrivals/departures for the initial request.
25  */
26 class KPUBLICTRANSPORT_EXPORT StopoverQueryModel : public AbstractQueryModel
27 {
28  Q_OBJECT
29 
30  /** Specify the actual departure query. */
31  Q_PROPERTY(KPublicTransport::StopoverRequest request READ request WRITE setRequest NOTIFY requestChanged)
32 
33  /** Whether querying for later departures 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 StopoverQueryModel(QObject *parent = nullptr);
41 
42  StopoverRequest request() const;
43  void setRequest(const StopoverRequest &req);
44 
45  bool canQueryNext() const;
46  /** Search for later journeys.
47  * Has no effect if canQueryNext() returns @c false.
48  */
49  Q_INVOKABLE void queryNext();
50 
51  bool canQueryPrevious() const;
52  /** Search for earlier journeys.
53  * Has no effect if canQueryPrevious() returns @c false.
54  */
55  Q_INVOKABLE void queryPrevious();
56 
57  enum Roles {
58  DepartureRole = Qt::UserRole
59  };
60  Q_ENUM(Roles)
61 
62  int rowCount(const QModelIndex &parent) const override;
63  QVariant data(const QModelIndex &index, int role) const override;
64  QHash<int, QByteArray> roleNames() const override;
65 
66  /** The current model content. */
67  const std::vector<Stopover>& departures() const;
68 
69 Q_SIGNALS:
70  void requestChanged();
71  void canQueryPrevNextChanged();
72 
73 private:
74  friend class StopoverQueryModelPrivate;
75  Q_DECLARE_PRIVATE(StopoverQueryModel)
76 };
77 
78 }
79 
80 #endif // KPUBLICTRANSPORT_STOPOVERQUERYMODEL_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Model representing arrival or departure query results.
Definition: location.h:16
UserRole
Describes an arrival or departure search.
Common base class for query models, do not use directly.
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.