Kgapi

staticmaptilefetchjob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "staticmaptilefetchjob.h"
10#include "debug.h"
11#include "staticmapurl.h"
12
13#include <QNetworkAccessManager>
14#include <QNetworkReply>
15#include <QNetworkRequest>
16
17using namespace KGAPI2;
18
19class Q_DECL_HIDDEN StaticMapTileFetchJob::Private
20{
21public:
22 QUrl url;
23 QPixmap tilePixmap;
24};
25
26StaticMapTileFetchJob::StaticMapTileFetchJob(const StaticMapUrl &url, QObject *parent)
27 : Job(parent)
28 , d(new Private)
29{
30 d->url = url.url();
31}
32
33StaticMapTileFetchJob::StaticMapTileFetchJob(const QUrl &url, QObject *parent)
34 : Job(parent)
35 , d(new Private)
36{
37 d->url = url;
38}
39
40StaticMapTileFetchJob::~StaticMapTileFetchJob()
41{
42 delete d;
43}
44
45QPixmap StaticMapTileFetchJob::tilePixmap() const
46{
47 if (isRunning()) {
48 qCWarning(KGAPIDebug) << "Called tilePixmap on a running job!";
49 return QPixmap();
50 }
51
52 return d->tilePixmap;
53}
54
55void StaticMapTileFetchJob::start()
56{
58}
59
60void StaticMapTileFetchJob::dispatchRequest(QNetworkAccessManager *accessManager,
61 const QNetworkRequest &request,
62 const QByteArray &data,
63 const QString &contentType)
64{
65 Q_UNUSED(data)
66 Q_UNUSED(contentType)
67
68 accessManager->get(request);
69}
70
71void StaticMapTileFetchJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
72{
73 Q_UNUSED(reply)
74
75 d->tilePixmap.loadFromData(rawData);
77}
78
79#include "moc_staticmaptilefetchjob.cpp"
Abstract base class for all jobs in LibKGAPI.
Definition job.h:41
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
bool isRunning
Whether the job is running.
Definition job.h:67
A class to build a URL from StaticMapMarkers and StaticMapPaths to fetch a map tile.
QUrl url() const
Returns constructed url from all defined parameters.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
QNetworkReply * get(const QNetworkRequest &request)
bool loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.