File indexing completed on 2024-05-12 04:42:51

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_ABSTRACTQUERYMODEL_H
0008 #define KPUBLICTRANSPORT_ABSTRACTQUERYMODEL_H
0009 
0010 #include "kpublictransport_export.h"
0011 
0012 #include <QAbstractListModel>
0013 
0014 #include <memory>
0015 #include <vector>
0016 
0017 namespace KPublicTransport {
0018 
0019 class AbstractQueryModelPrivate;
0020 class Attribution;
0021 class Manager;
0022 
0023 /** Common base class for query models, do not use directly. */
0024 class KPUBLICTRANSPORT_EXPORT AbstractQueryModel : public QAbstractListModel
0025 {
0026     Q_OBJECT
0027 
0028     /** Sets the KPublicTransport::Manager instance. Necessary for this to work at all. */
0029     Q_PROPERTY(KPublicTransport::Manager* manager READ manager WRITE setManager NOTIFY managerChanged)
0030 
0031     /** @c true if there is still an ongoing network operation. */
0032     Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
0033     /** Contains the error message if all backends failed to provide a result. */
0034     Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
0035 
0036     /** Attributions for the provided data. */
0037     Q_PROPERTY(QVariantList attributions READ attributionsVariant NOTIFY attributionsChanged)
0038 
0039 public:
0040     ~AbstractQueryModel() override;
0041 
0042     Manager* manager() const;
0043     void setManager(Manager *mgr);
0044 
0045     bool isLoading() const;
0046     QString errorMessage() const;
0047 
0048     /** The attribution information for the current model content. */
0049     const std::vector<Attribution>& attributions() const;
0050 
0051     /** Cancel ongoing query operations, but keep the results that are already there. */
0052     Q_INVOKABLE void cancel();
0053 
0054     /** Cancel any ongoing query operations, and clear the results. */
0055     Q_INVOKABLE void clear();
0056 
0057 Q_SIGNALS:
0058     void managerChanged();
0059     void loadingChanged();
0060     void errorMessageChanged();
0061     void attributionsChanged();
0062 
0063 protected:
0064     ///@cond internal
0065     Q_DECL_HIDDEN explicit AbstractQueryModel(AbstractQueryModelPrivate *dd, QObject *parent);
0066     std::unique_ptr<AbstractQueryModelPrivate> d_ptr;
0067     ///@endcond
0068 
0069 private:
0070     Q_DECL_HIDDEN QVariantList attributionsVariant() const;
0071 };
0072 
0073 }
0074 
0075 #endif // KPUBLICTRANSPORT_ABSTRACTQUERYMODEL_H