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_LOCATIONQUERYMODEL_H 0008 #define KPUBLICTRANSPORT_LOCATIONQUERYMODEL_H 0009 0010 #include "kpublictransport_export.h" 0011 #include "abstractquerymodel.h" 0012 0013 #include <KPublicTransport/LocationRequest> 0014 0015 namespace KPublicTransport { 0016 0017 class Location; 0018 class LocationQueryModelPrivate; 0019 0020 /** 0021 * Model representing location query results. 0022 * Intented as a basis for as-you-type completers for location searches. 0023 */ 0024 class KPUBLICTRANSPORT_EXPORT LocationQueryModel : public AbstractQueryModel 0025 { 0026 Q_OBJECT 0027 /** Specify the actual location query. */ 0028 Q_PROPERTY(KPublicTransport::LocationRequest request READ request WRITE setRequest NOTIFY requestChanged) 0029 0030 /** Delay in milliseconds until the query is actually performed. 0031 * Useful when expecting high frequency changes to the request, eg. for completion during typing. 0032 * @default no delay 0033 */ 0034 Q_PROPERTY(int queryDelay READ queryDelay WRITE setQueryDelay NOTIFY queryDelayChanged) 0035 0036 public: 0037 explicit LocationQueryModel(QObject *parent = nullptr); 0038 ~LocationQueryModel() override; 0039 0040 LocationRequest request() const; 0041 void setRequest(const LocationRequest &req); 0042 0043 int queryDelay() const; 0044 void setQueryDelay(int ms); 0045 0046 enum Roles { 0047 LocationRole = Qt::UserRole 0048 }; 0049 Q_ENUM(Roles) 0050 0051 int rowCount(const QModelIndex &parent) const override; 0052 QVariant data(const QModelIndex &index, int role) const override; 0053 QHash<int, QByteArray> roleNames() const override; 0054 0055 /** The current model content. */ 0056 const std::vector<Location>& locations() const; 0057 0058 Q_SIGNALS: 0059 void requestChanged(); 0060 void queryDelayChanged(); 0061 0062 private: 0063 friend class LocationQueryModelPrivate; 0064 Q_DECLARE_PRIVATE(LocationQueryModel) 0065 }; 0066 0067 } 0068 0069 #endif // KPUBLICTRANSPORT_LOCATIONQUERYMODEL_H