File indexing completed on 2024-05-12 04:42:52
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KPUBLICTRANSPORT_STOPOVERQUERYMODEL_H 0008 #define KPUBLICTRANSPORT_STOPOVERQUERYMODEL_H 0009 0010 #include "kpublictransport_export.h" 0011 #include "abstractquerymodel.h" 0012 0013 #include <KPublicTransport/StopoverRequest> 0014 0015 namespace KPublicTransport { 0016 0017 class Stopover; 0018 class StopoverQueryModelPrivate; 0019 0020 /** 0021 * Model representing arrival or departure query results. 0022 * This takes care of dynamically updating as results arrive from different 0023 * backends, including merging them, as well as providing a way to search 0024 * for earlier/later arrivals/departures for the initial request. 0025 */ 0026 class KPUBLICTRANSPORT_EXPORT StopoverQueryModel : public AbstractQueryModel 0027 { 0028 Q_OBJECT 0029 0030 /** Specify the actual departure query. */ 0031 Q_PROPERTY(KPublicTransport::StopoverRequest request READ request WRITE setRequest NOTIFY requestChanged) 0032 0033 /** Whether querying for later departures is possible. */ 0034 Q_PROPERTY(bool canQueryNext READ canQueryNext NOTIFY canQueryPrevNextChanged) 0035 /** Whether querying for earlier journey is possible. */ 0036 Q_PROPERTY(bool canQueryPrevious READ canQueryPrevious NOTIFY canQueryPrevNextChanged) 0037 0038 public: 0039 explicit StopoverQueryModel(QObject *parent = nullptr); 0040 ~StopoverQueryModel() override; 0041 0042 StopoverRequest request() const; 0043 void setRequest(const StopoverRequest &req); 0044 0045 bool canQueryNext() const; 0046 /** Search for later journeys. 0047 * Has no effect if canQueryNext() returns @c false. 0048 */ 0049 Q_INVOKABLE void queryNext(); 0050 0051 bool canQueryPrevious() const; 0052 /** Search for earlier journeys. 0053 * Has no effect if canQueryPrevious() returns @c false. 0054 */ 0055 Q_INVOKABLE void queryPrevious(); 0056 0057 enum Roles { 0058 DepartureRole = Qt::UserRole 0059 }; 0060 Q_ENUM(Roles) 0061 0062 int rowCount(const QModelIndex &parent) const override; 0063 QVariant data(const QModelIndex &index, int role) const override; 0064 QHash<int, QByteArray> roleNames() const override; 0065 0066 /** The current model content. */ 0067 const std::vector<Stopover>& departures() const; 0068 0069 Q_SIGNALS: 0070 void requestChanged(); 0071 void canQueryPrevNextChanged(); 0072 0073 private: 0074 friend class StopoverQueryModelPrivate; 0075 Q_DECLARE_PRIVATE(StopoverQueryModel) 0076 }; 0077 0078 } 0079 0080 #endif // KPUBLICTRANSPORT_STOPOVERQUERYMODEL_H