Skip to content

Commit

Permalink
Avoid qt warning when opening the raster properties dialog
Browse files Browse the repository at this point in the history
(while visiting the function, remove use of  my* variable
names)
  • Loading branch information
nirvn committed Sep 14, 2019
1 parent cdd3a55 commit 738ced6
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,54 +1568,61 @@ QStringList QgsRasterLayer::subLayers() const
// note: previewAsImage and previewAsPixmap should use a common low-level fct QgsRasterLayer::previewOnPaintDevice( QSize size, QColor bgColor, QPaintDevice &device )
QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage::Format format )
{
QImage myQImage( size, format );
QImage image( size, format );

if ( ! isValid( ) )
return QImage();

myQImage.setColor( 0, bgColor.rgba() );
myQImage.fill( 0 ); //defaults to white, set to transparent for rendering on a map

if ( image.format() == QImage::Format_Indexed8 )
{
image.setColor( 0, bgColor.rgba() );
image.fill( 0 ); //defaults to white, set to transparent for rendering on a map
}
else
{
image.fill( bgColor );
}

QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
QgsRasterViewPort *rasterViewPort = new QgsRasterViewPort();

double myMapUnitsPerPixel;
double myX = 0.0;
double myY = 0.0;
QgsRectangle myExtent = mDataProvider->extent();
if ( myExtent.width() / myExtent.height() >= static_cast< double >( myQImage.width() ) / myQImage.height() )
double mapUnitsPerPixel;
double x = 0.0;
double y = 0.0;
QgsRectangle extent = mDataProvider->extent();
if ( extent.width() / extent.height() >= static_cast< double >( image.width() ) / image.height() )
{
myMapUnitsPerPixel = myExtent.width() / myQImage.width();
myY = ( myQImage.height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
mapUnitsPerPixel = extent.width() / image.width();
y = ( image.height() - extent.height() / mapUnitsPerPixel ) / 2;
}
else
{
myMapUnitsPerPixel = myExtent.height() / myQImage.height();
myX = ( myQImage.width() - myExtent.width() / myMapUnitsPerPixel ) / 2;
mapUnitsPerPixel = extent.height() / image.height();
x = ( image.width() - extent.width() / mapUnitsPerPixel ) / 2;
}

double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
double myPixelHeight = myExtent.height() / myMapUnitsPerPixel;
const double pixelWidth = extent.width() / mapUnitsPerPixel;
const double pixelHeight = extent.height() / mapUnitsPerPixel;

rasterViewPort->mTopLeftPoint = QgsPointXY( x, y );
rasterViewPort->mBottomRightPoint = QgsPointXY( pixelWidth, pixelHeight );
rasterViewPort->mWidth = image.width();
rasterViewPort->mHeight = image.height();

myRasterViewPort->mTopLeftPoint = QgsPointXY( myX, myY );
myRasterViewPort->mBottomRightPoint = QgsPointXY( myPixelWidth, myPixelHeight );
myRasterViewPort->mWidth = myQImage.width();
myRasterViewPort->mHeight = myQImage.height();
rasterViewPort->mDrawnExtent = extent;
rasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
rasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid

myRasterViewPort->mDrawnExtent = myExtent;
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
QgsMapToPixel *mapToPixel = new QgsMapToPixel( mapUnitsPerPixel );

QgsMapToPixel *myMapToPixel = new QgsMapToPixel( myMapUnitsPerPixel );
QPainter *painter = new QPainter( &image );
draw( painter, rasterViewPort, mapToPixel );
delete rasterViewPort;
delete mapToPixel;

QPainter *myQPainter = new QPainter( &myQImage );
draw( myQPainter, myRasterViewPort, myMapToPixel );
delete myRasterViewPort;
delete myMapToPixel;
myQPainter->end();
delete myQPainter;
painter->end();
delete painter;

return myQImage;
return image;
}

//////////////////////////////////////////////////////////
Expand Down

0 comments on commit 738ced6

Please sign in to comment.