KReport

KReportMapRenderer.cpp
1/*
2 * Copyright (C) 2015 Radosław Wicik <radoslaw@wicik.pl>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "KReportMapRenderer.h"
20#include "KReportItemMaps.h"
21#include <KReportRenderObjects.h>
22
23#include <marble/MarbleWidget.h>
24#include <marble/MarbleGlobal.h>
25#include <marble/MarbleModel.h>
26#include <marble/HttpDownloadManager.h>
27#include <marble/AbstractFloatItem.h>
28#include <marble/GeoPainter.h>
29
30#include "kreportplugin_debug.h"
31
32KReportMapRenderer::KReportMapRenderer(QObject* parent)
33 : QObject(parent)
34 , m_currentJob(nullptr)
35{
36 m_marble.setMapThemeId(QLatin1String("earth/openstreetmap/openstreetmap.dgml"));
37 m_marble.setShowOverviewMap(false);
38 m_marble.setMapQualityForViewContext(Marble::PrintQuality, Marble::Still);
39 m_marble.setShowCrosshairs(true);
40
41 foreach(Marble::AbstractFloatItem* floatItem, m_marble.floatItems()){
42 if(floatItem->nameId() == QString(QLatin1String("navigation"))){
43 floatItem->setVisible(false);
44 }
45 }
46
47 connect(m_marble.model()->downloadManager(), &Marble::HttpDownloadManager::progressChanged, this, &KReportMapRenderer::downloadProgres);
48 connect(&m_marble, &Marble::MarbleMap::renderStatusChanged, this, &KReportMapRenderer::onRenderStatusChange);
49 connect(&m_retryTimer, &QTimer::timeout, this, &KReportMapRenderer::retryRender);
50}
51
52KReportMapRenderer::~KReportMapRenderer()
53{
54
55}
56
57void KReportMapRenderer::renderJob(KReportItemMaps* reportItemMaps)
58{
59 m_currentJob = reportItemMaps;
60 int zoom = m_currentJob->zoom();
61 //kreportpluginDebug() << "Map Renderer rendering" << m_currentJob->longtitude() << m_currentJob->latitude();
62
63 m_marble.setMapThemeId(m_currentJob->themeId());
64 //some themes enable overview map, and this must be disabled after theme switch.
65 m_marble.setShowOverviewMap(false);
66 m_marble.setSize(KReportItemBase::sceneSize(m_currentJob->size()).toSize());
67 m_marble.centerOn(m_currentJob->longtitude(), m_currentJob->latitude());
68 m_marble.setRadius(pow(M_E, (zoom / 200.0)));
69
70 // Create a painter that will do the painting.
71 Marble::GeoPainter geoPainter( m_currentJob->oroImage()->picture(), m_marble.viewport(), m_marble.mapQuality() );
72 m_marble.paint( geoPainter, QRect() );
73
74 if (m_marble.renderStatus() == Marble::Complete) {
75 m_currentJob->renderFinished();
76 } else {
77 m_retryTimer.start(1000);
78 }
79
80}
81
82void KReportMapRenderer::onRenderStatusChange(Marble::RenderStatus renderStatus)
83{
84 //kreportpluginDebug() << m_marble.renderStatus() << "|" << renderStatus;
85
86 if(m_currentJob){
87 /*kreportpluginDebug()
88 << this
89 << m_currentJob
90 << m_currentJob->longtitude()
91 << m_currentJob->latitude()
92 << m_currentJob->zoom()
93 << " | status: " << renderStatus;*/
94
95 if(renderStatus == Marble::Complete){
96 m_currentJob->renderFinished();
97 }
98 }
99}
100
101void KReportMapRenderer::downloadProgres(int active, int queued)
102{
103 Q_UNUSED(active)
104 Q_UNUSED(queued)
105 //if(m_currentJob){
106 // kreportpluginDebug() << "job:" << m_currentJob
107 // << "(" << m_currentJob->latitude() << "," << m_currentJob->longtitude() << ")"
108 // << "active/queued:" << active << "/" << queued;
109 //}
110}
111
112void KReportMapRenderer::retryRender()
113{
114 //kreportpluginDebug() << "Retrying map render";
115
116 // Create a painter that will do the painting.
117 Marble::GeoPainter geoPainter( m_currentJob->oroImage()->picture(), m_marble.viewport(), m_marble.mapQuality() );
118 m_marble.paint( geoPainter, QRect() );
119
120 if (m_marble.renderStatus() == Marble::Complete) {
121 m_retryTimer.stop();
122 m_currentJob->renderFinished();
123 }
124}
125
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
QSizeF size() const
Return the size in points.
void progressChanged(int active, int queued)
void paint(GeoPainter &painter, const QRect &dirtyRect)
void centerOn(const qreal lon, const qreal lat)
MapQuality mapQuality() const
void setRadius(int radius)
void setMapThemeId(const QString &maptheme)
void setShowOverviewMap(bool visible)
void renderStatusChanged(RenderStatus status)
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
QSize toSize() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void start()
void stop()
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.