Commit aa598a3a authored by Bernhard Beschow's avatar Bernhard Beschow

ViewParams: use QSharedPointer to hold the canvas and coast images

* fixes a crash when the appearance of the download progress bar causes a resize of the map during painting

BUG: 265599
RevBy: Dennis Nienhüser
parent 11d7be9d
......@@ -64,7 +64,7 @@ void EquirectScanlineTextureMapper::setRepaintNeeded()
void EquirectScanlineTextureMapper::mapTexture( ViewParams *viewParams, TextureColorizer *texColorizer )
{
QImage *canvasImage = viewParams->canvasImage();
QSharedPointer<QImage> canvasImage = viewParams->canvasImagePtr();
const int imageHeight = canvasImage->height();
const int imageWidth = canvasImage->width();
const qint64 radius = viewParams->radius();
......
......@@ -66,7 +66,7 @@ void MercatorScanlineTextureMapper::setRepaintNeeded()
void MercatorScanlineTextureMapper::mapTexture( ViewParams *viewParams, TextureColorizer *texColorizer )
{
QImage *canvasImage = viewParams->canvasImage();
QSharedPointer<QImage> canvasImage = viewParams->canvasImagePtr();
const int imageHeight = canvasImage->height();
const int imageWidth = canvasImage->width();
const qint64 radius = viewParams->radius();
......
......@@ -188,7 +188,7 @@ void PlacemarkLayout::paintPlaceFolder( QPainter *painter,
return;
// const int imgwidth = viewParams->canvasImage()->width();
const int imgheight = viewParams->canvasImage()->height();
const int imgheight = viewParams->canvasImagePtr()->height();
if ( m_styleResetRequested ) {
m_styleResetRequested = false;
......
......@@ -68,7 +68,7 @@ void SphericalScanlineTextureMapper::setRepaintNeeded()
void SphericalScanlineTextureMapper::mapTexture( ViewParams *viewParams, TextureColorizer *texColorizer )
{
QImage *canvasImage = viewParams->canvasImage();
QSharedPointer<QImage> canvasImage = viewParams->canvasImagePtr();
const int imageHeight = canvasImage->height();
const int imageWidth = canvasImage->width();
const qint64 radius = viewParams->radius();
......
......@@ -15,6 +15,7 @@
#include <cmath>
#include <QtCore/QFile>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
#include <QtCore/QTime>
#include <QtGui/QColor>
......@@ -170,8 +171,8 @@ void TextureColorizer::colorize(ViewParams *viewParams)
// update coastimg
m_veccomposer.drawTextureMap( viewParams );
QImage *origimg = viewParams->canvasImage();
const QImage *coastimg = viewParams->coastImage();
QSharedPointer<QImage> origimg = viewParams->canvasImagePtr();
QSharedPointer<const QImage> coastimg = viewParams->coastImagePtr();
const qint64 radius = viewParams->radius();
const int imgheight = origimg->height();
......
......@@ -73,7 +73,7 @@ void TileScalingTextureMapper::mapTexture( GeoPainter *geoPainter, ViewParams *v
if ( viewParams->radius() <= 0 )
return;
QImage *canvasImage = viewParams->canvasImage();
QSharedPointer<QImage> canvasImage = viewParams->canvasImagePtr();
const int imageHeight = canvasImage->height();
const int imageWidth = canvasImage->width();
const qint64 radius = viewParams->radius();
......@@ -109,7 +109,7 @@ void TileScalingTextureMapper::mapTexture( GeoPainter *geoPainter, ViewParams *v
if ( texColorizer || m_oldRadius != radius ) {
m_cache->clear();
QPainter painter( canvasImage );
QPainter painter( canvasImage.data() );
painter.setRenderHint( QPainter::SmoothPixmapTransform, highQuality );
for ( int tileY = minTileY; tileY <= maxTileY; ++tileY ) {
......
......@@ -150,7 +150,7 @@ void VectorComposer::drawTextureMap(ViewParams *viewParams)
{
loadCoastlines();
QImage *origimg = viewParams->coastImage();
QSharedPointer<QImage> origimg = viewParams->coastImagePtr();
Quaternion rotAxis = viewParams->planetAxis();
origimg->fill( Qt::transparent );
......@@ -173,7 +173,7 @@ void VectorComposer::drawTextureMap(ViewParams *viewParams)
m_vectorMap->createFromPntMap( s_coastLines, viewParams->viewport() );
m_vectorMap->setPen( m_textureLandPen );
m_vectorMap->setBrush( m_textureLandBrush );
m_vectorMap->drawMap( origimg, antialiased, viewParams->viewport(),
m_vectorMap->drawMap( origimg.data(), antialiased, viewParams->viewport(),
viewParams->mapQuality() );
// Islands
......@@ -183,7 +183,7 @@ void VectorComposer::drawTextureMap(ViewParams *viewParams)
m_vectorMap->createFromPntMap( s_islands, viewParams->viewport() );
m_vectorMap->setPen( m_textureLandPen );
m_vectorMap->setBrush( m_textureLandBrush );
m_vectorMap->drawMap( origimg, antialiased, viewParams->viewport(),
m_vectorMap->drawMap( origimg.data(), antialiased, viewParams->viewport(),
viewParams->mapQuality() );
bool showWaterbodies, showLakes;
......@@ -198,13 +198,13 @@ void VectorComposer::drawTextureMap(ViewParams *viewParams)
m_vectorMap->createFromPntMap( s_lakes, viewParams->viewport() );
m_vectorMap->setPen( Qt::NoPen );
m_vectorMap->setBrush( m_textureLakeBrush );
m_vectorMap->drawMap( origimg, antialiased, viewParams->viewport(),
m_vectorMap->drawMap( origimg.data(), antialiased, viewParams->viewport(),
viewParams->mapQuality() );
m_vectorMap->createFromPntMap( s_lakeislands, viewParams->viewport() );
m_vectorMap->setPen( Qt::NoPen );
m_vectorMap->setBrush( m_textureLandBrush );
m_vectorMap->drawMap( origimg, antialiased, viewParams->viewport(),
m_vectorMap->drawMap( origimg.data(), antialiased, viewParams->viewport(),
viewParams->mapQuality() );
}
......@@ -219,7 +219,7 @@ void VectorComposer::drawTextureMap(ViewParams *viewParams)
m_vectorMap->setPen( Qt::NoPen );
m_vectorMap->setBrush( m_textureGlacierBrush );
m_vectorMap->drawMap( origimg, antialiased, viewParams->viewport(),
m_vectorMap->drawMap( origimg.data(), antialiased, viewParams->viewport(),
viewParams->mapQuality() );
}
......
......@@ -60,8 +60,8 @@ public:
GeoSceneSettings m_globalSettings;
// Cached data that will make painting faster.
QImage *m_canvasImage; // Base image with space and atmosphere
QImage *m_coastImage; // A slightly higher level image.
QSharedPointer<QImage> m_canvasImage; // Base image with space and atmosphere
QSharedPointer<QImage> m_coastImage; // A slightly higher level image.
void initGlobalSettings();
void propagateGlobalToLocalSettings();
......@@ -85,8 +85,6 @@ ViewParamsPrivate::ViewParamsPrivate()
ViewParamsPrivate::~ViewParamsPrivate()
{
delete m_canvasImage;
delete m_coastImage;
}
void ViewParamsPrivate::initGlobalSettings()
......@@ -156,7 +154,7 @@ void ViewParams::setProjection(Projection newProjection)
// Repaint the background if necessary
if ( !currentProjection()->mapCoversViewport( viewport() ) ) {
canvasImage()->fill(0); // Using Qt::transparent is wrong here (equals "18")!
d->m_canvasImage->fill(0); // Using Qt::transparent is wrong here (equals "18")!
}
}
......@@ -238,7 +236,7 @@ void ViewParams::setRadius(int newRadius)
// Repaint the background if necessary
if ( !currentProjection()->mapCoversViewport( viewport() ) ) {
canvasImage()->fill(0); // Using Qt::transparent is wrong here (equals "18")!
d->m_canvasImage->fill(0); // Using Qt::transparent is wrong here (equals "18")!
}
}
......@@ -285,8 +283,7 @@ void ViewParams::setSize( int width, int height )
: QImage::Format_ARGB32_Premultiplied;
// Recreate the canvas image with the new size.
delete d->m_canvasImage;
d->m_canvasImage = new QImage( width, height, imageFormat );
d->m_canvasImage = QSharedPointer<QImage>( new QImage( width, height, imageFormat ) );
// Repaint the background if necessary
if ( !currentProjection()->mapCoversViewport( viewport() ) ) {
......@@ -294,20 +291,29 @@ void ViewParams::setSize( int width, int height )
}
// Recreate the coastline detection offscreen image
delete d->m_coastImage;
d->m_coastImage = new QImage( width, height, QImage::Format_RGB32 );
d->m_coastImage = QSharedPointer<QImage>( new QImage( width, height, QImage::Format_RGB32 ) );
}
QImage * ViewParams::canvasImage() const
QSharedPointer<QImage> ViewParams::canvasImagePtr() const
{
return d->m_canvasImage;
}
QImage * ViewParams::coastImage() const
QImage * ViewParams::canvasImage() const
{
return d->m_canvasImage.data();
}
QSharedPointer<QImage> ViewParams::coastImagePtr() const
{
return d->m_coastImage;
}
QImage * ViewParams::coastImage() const
{
return d->m_coastImage.data();
}
bool ViewParams::showGps() const
{
return d->m_showGps;
......
......@@ -19,6 +19,7 @@
* @author Inge Wallin <inge@lysator.liu.se>
*/
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
#include "marble_export.h"
......@@ -114,8 +115,10 @@ class MARBLE_EXPORT ViewParams
*/
void setSize( int width, int height );
QSharedPointer<QImage> canvasImagePtr() const;
QImage * canvasImage() const;
QSharedPointer<QImage> coastImagePtr() const;
QImage * coastImage() const;
bool showGps() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment