• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • thumbnailer
thumbnailer.cpp
Go to the documentation of this file.
1 // Copyright 2014 Friedrich W. H. Kossebau <kossebau@kde.org>
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this program. If not, see <http://www.gnu.org/licenses/>.
15 
16 #include "thumbnailer.h"
17 
18 // Marble
19 #include <MarbleModel.h>
20 #include <GeoDataDocument.h>
21 #include <GeoPainter.h>
22 #include <GeoDataLatLonAltBox.h>
23 #include <ViewportParams.h>
24 #include <RenderPlugin.h>
25 #include <GeoDataTreeModel.h>
26 #include <GeoDataTypes.h>
27 // Qt
28 #include <QTimer>
29 #include <QPainter>
30 
31 static const int timeoutTime = 5000; // in msec
32 
33 #include <KDebug>
34 
35 namespace Marble {
36 
37 GeoDataThumbnailer::GeoDataThumbnailer()
38  : ThumbCreator()
39  , m_marbleMap()
40 {
41  m_marbleMap.setMapThemeId(QLatin1String("earth/openstreetmap/openstreetmap.dgml"));
42  m_marbleMap.setProjection(Equirectangular);
43  m_marbleMap.setMapQualityForViewContext( PrintQuality, Still );
44  m_marbleMap.setViewContext( Still );
45  foreach( RenderPlugin* plugin, m_marbleMap.renderPlugins() ) {
46  plugin->setEnabled( false );
47  }
48 
49  m_outtimer.setInterval(timeoutTime);
50  m_outtimer.setSingleShot(true);
51  connect(&m_outtimer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
52 }
53 
54 
55 GeoDataThumbnailer::~GeoDataThumbnailer()
56 {
57 }
58 
59 bool GeoDataThumbnailer::create(const QString &path, int width, int height, QImage &image)
60 {
61  m_marbleMap.setSize(width, height);
62 
63  MarbleModel *const model = m_marbleMap.model();
64 
65  // load the document content
66  m_loadingCompleted = false;
67 
68  m_currentFilename = path;
69  connect(model->treeModel(), SIGNAL(added(GeoDataObject*)), this, SLOT(onGeoDataObjectAdded(GeoDataObject*)));
70  model->addGeoDataFile(path);
71 
72  if (! m_loadingCompleted) {
73  // loading is done async, so wait here for a while
74  // Using a QEventLoop here seems fine, thumbnailers are only used inside the
75  // thumbnail protocol slave, it seems
76  m_outtimer.start();
77  m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
78  }
79 
80  if (m_loadingCompleted) {
81  // TODO: limit to shown map, if full earth is used
82  image = QImage(width, height, QImage::Format_ARGB32);
83  image.fill(qRgba(0, 0, 0, 0));
84 
85  // Create a painter that will do the painting.
86  GeoPainter geoPainter( &image, m_marbleMap.viewport(),
87  m_marbleMap.mapQuality() );
88 
89  m_marbleMap.paint( geoPainter, QRect() ); // TODO: dirtyRect seems currently unused, make sure it is
90  }
91 
92  disconnect(model->treeModel(), SIGNAL(added(GeoDataObject*)), this, SLOT(onGeoDataObjectAdded(GeoDataObject*)));
93  model->removeGeoData(path);
94  m_currentFilename.clear();
95 
96  return m_loadingCompleted;
97 }
98 
99 static qreal radius(qreal zoom)
100 {
101  return pow(M_E, (zoom / 200.0));
102 }
103 
104 void GeoDataThumbnailer::onGeoDataObjectAdded( GeoDataObject* object )
105 {
106  if ( object->nodeType() != GeoDataTypes::GeoDataDocumentType ) {
107  return;
108  }
109 
110  const GeoDataDocument *document = static_cast<GeoDataDocument*>(object);
111  if (document->fileName() != m_currentFilename) {
112  return;
113  }
114 
115  const GeoDataLatLonAltBox latLonAltBox = document->latLonAltBox();
116  const GeoDataCoordinates center = latLonAltBox.center();
117 
118  int newRadius = m_marbleMap.radius();
119  //prevent divide by zero
120  if( latLonAltBox.height() && latLonAltBox.width() ) {
121  const ViewportParams* viewparams = m_marbleMap.viewport();
122  //work out the needed zoom level
123  const int horizontalRadius = ( 0.25 * M_PI ) * ( viewparams->height() / latLonAltBox.height() );
124  const int verticalRadius = ( 0.25 * M_PI ) * ( viewparams->width() / latLonAltBox.width() );
125  newRadius = qMin<int>( horizontalRadius, verticalRadius );
126  newRadius = qMax<int>(radius(m_marbleMap.minimumZoom()), qMin<int>(newRadius, radius(m_marbleMap.maximumZoom())));
127  }
128 
129  m_marbleMap.centerOn( center.longitude(GeoDataCoordinates::Degree), center.latitude(GeoDataCoordinates::Degree) );
130 
131  m_marbleMap.setRadius( newRadius );
132 
133  m_loadingCompleted = true;
134  m_outtimer.stop();
135  m_eventLoop.quit();
136 }
137 
138 ThumbCreator::Flags GeoDataThumbnailer::flags() const
139 {
140  return DrawFrame;
141 }
142 
143 }
GeoDataDocument.h
QTimer::setInterval
void setInterval(int msec)
thumbnailer.h
QEventLoop::quit
void quit()
Marble::MarbleModel::removeGeoData
void removeGeoData(const QString &key)
Remove the file or raw data from the treeModel.
Definition: MarbleModel.cpp:736
Marble::MarbleModel::treeModel
GeoDataTreeModel * treeModel()
Return the list of Placemarks as a QAbstractItemModel *.
Definition: MarbleModel.cpp:477
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::MarbleMap::radius
int radius() const
Return the radius of the globe in pixels.
Definition: MarbleMap.cpp:364
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::GeoDataTypes::GeoDataDocumentType
const char * GeoDataDocumentType
Definition: GeoDataTypes.cpp:38
Marble::PrintQuality
Print quality.
Definition: MarbleGlobal.h:87
Marble::MarbleMap::setMapQualityForViewContext
void setMapQualityForViewContext(MapQuality qualityForViewContext, ViewContext viewContext)
Definition: MarbleMap.cpp:299
timeoutTime
static const int timeoutTime
Definition: thumbnailer.cpp:31
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Marble::GeoDataThumbnailer::flags
virtual Flags flags() const
Definition: thumbnailer.cpp:138
Marble::MarbleMap::setViewContext
void setViewContext(ViewContext viewContext)
Definition: MarbleMap.cpp:317
Marble::MarbleMap::viewport
ViewportParams * viewport()
Definition: MarbleMap.cpp:288
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::MarbleMap::model
MarbleModel * model() const
Return the model that this view shows.
Definition: MarbleMap.cpp:283
Marble::MarbleMap::setMapThemeId
void setMapThemeId(const QString &maptheme)
Set a new map theme.
Definition: MarbleMap.cpp:782
QString::clear
void clear()
Marble::Equirectangular
Flat projection ("plate carree")
Definition: MarbleGlobal.h:46
Marble::GeoDataThumbnailer::create
virtual bool create(const QString &path, int width, int height, QImage &image)
Definition: thumbnailer.cpp:59
QRect
ThumbCreator
Marble::MarbleModel::addGeoDataFile
void addGeoDataFile(const QString &filename)
Handle file loading into the treeModel.
Definition: MarbleModel.cpp:725
Marble::MarbleMap::setSize
void setSize(int width, int height)
Definition: MarbleMap.cpp:337
Marble::MarbleMap::maximumZoom
int maximumZoom() const
return the minimum zoom value for the current map theme.
Definition: MarbleMap.cpp:430
QImage::fill
void fill(uint pixelValue)
QEventLoop::exec
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
Marble::radius
static qreal radius(qreal zoom)
Definition: thumbnailer.cpp:99
Marble::MarbleMap::setRadius
void setRadius(int radius)
Set the radius of the globe in pixels.
Definition: MarbleMap.cpp:369
Marble::Still
still image
Definition: MarbleGlobal.h:75
QString
Marble::MarbleMap::paint
void paint(GeoPainter &painter, const QRect &dirtyRect)
Paint the map using a give painter.
Definition: MarbleMap.cpp:739
GeoPainter.h
Marble::MarbleMap::minimumZoom
int minimumZoom() const
return the minimum zoom value for the current map theme.
Definition: MarbleMap.cpp:422
GeoDataTreeModel.h
Marble::MarbleMap::renderPlugins
QList< RenderPlugin * > renderPlugins() const
Returns a list of all RenderPlugins in the model, this includes float items.
Definition: MarbleMap.cpp:1206
Marble::MarbleMap::setProjection
void setProjection(Projection projection)
Set the Projection used for the map.
Definition: MarbleMap.cpp:665
ViewportParams.h
This file contains the headers for ViewportParams.
QTimer::stop
void stop()
QImage
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:139
Marble::GeoDataThumbnailer::~GeoDataThumbnailer
virtual ~GeoDataThumbnailer()
Definition: thumbnailer.cpp:55
QLatin1String
GeoDataLatLonAltBox.h
RenderPlugin.h
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
QTimer::start
void start(int msec)
Marble::MarbleMap::centerOn
void centerOn(const qreal lon, const qreal lat)
Center the view on a geographical point.
Definition: MarbleMap.cpp:643
GeoDataTypes.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::GeoDataThumbnailer::GeoDataThumbnailer
GeoDataThumbnailer()
Definition: thumbnailer.cpp:37
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
QTimer::setSingleShot
void setSingleShot(bool singleShot)
Marble::MarbleMap::mapQuality
MapQuality mapQuality(ViewContext viewContext) const
Definition: MarbleMap.cpp:307
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal