KOSMIndoorMap

wikidataquery.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef WIKIDATAQUERY_H
8#define WIKIDATAQUERY_H
9
10#include "entities.h"
11
12#include <QObject>
13
14#include <vector>
15
16class QNetworkReply;
17class QNetworkRequest;
18class QUrlQuery;
19
20namespace Wikidata {
21class QueryManager;
22
23/** Base class for Wikidata queries. */
24class Query : public QObject
25{
27public:
28 explicit Query(QObject *parent = nullptr);
29 ~Query() override;
30
31 enum Error {
32 NoError,
33 NetworkError
34 };
35 [[nodiscard]] Error error() const;
36
38 void finished();
39
40protected:
41 [[nodiscard]] static QUrlQuery commonUrlQuery();
42
43 friend class QueryManager;
44 [[nodiscard]] virtual QNetworkRequest nextRequest() = 0;
45 /** Returns @true if this query is complete, @false if another request is needed. */
46 [[nodiscard]] virtual bool processReply(QNetworkReply *reply) = 0;
47
48 Error m_error = NoError;
49};
50
51/** Wikidata multi-entity retrieval query. */
52class EntitiesQuery : public Query
53{
55public:
56 explicit EntitiesQuery(QObject *parent = nullptr);
57 ~EntitiesQuery() override;
58
59 void setItems(std::vector<Wikidata::Q> &&items);
60 [[nodiscard]] std::vector<Wikidata::Item>&& takeResult();
61
63 void partialResult(EntitiesQuery *query);
64
65private:
66 [[nodiscard]] QNetworkRequest nextRequest() override;
67 [[nodiscard]] bool processReply(QNetworkReply *reply) override;
68
69 std::vector<Wikidata::Q> m_items;
70 std::size_t m_nextBatch = 0;
71 std::vector<Wikidata::Item> m_result;
72};
73
74/** Wikidata image metadata query. */
76{
78public:
79 explicit ImageMetadataQuery(QObject *parent = nullptr);
80 ~ImageMetadataQuery() override;
81
82 void setImages(std::vector<QString> &&images);
83 [[nodiscard]] std::vector<Wikidata::Image>&& takeResult();
84
86 void partialResult(ImageMetadataQuery *query);
87
88private:
89 [[nodiscard]] QNetworkRequest nextRequest() override;
90 [[nodiscard]] bool processReply(QNetworkReply *reply) override;
91
92 std::vector<QString> m_images;
93 std::size_t m_nextBatch = 0;
94 std::vector<Wikidata::Image> m_result;
95};
96
97}
98
99#endif // WIKIDATAQUERY_H
Wikidata multi-entity retrieval query.
Wikidata image metadata query.
Executes wikidata queries.
Base class for Wikidata queries.
virtual bool processReply(QNetworkReply *reply)=0
Returns @true if this query is complete, @false if another request is needed.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.