Skip to content
Permalink
Browse files

replace QgsRasterLayer::thumbnailAsPixmap() with previewAsPixmap() : …

…return QPixmap and add size and background color parameters ; remove QgsRasterLayer::thumbnailAsImage() as it's not used
  • Loading branch information
etiennesky committed Oct 4, 2012
1 parent 3d326cc commit 777ce59420fd0346d84e1fa6e2e4138c1ad3857b
@@ -475,10 +475,13 @@ class QgsRasterLayer : QgsMapLayer
/** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
void thumbnailAsPixmap( QPixmap * theQPixmap );

/** \brief Draws a preview of the rasterlayer into a pixmap */
QPixmap previewAsPixmap( QSize size, QColor bgColor = QColor( 255, 255, 255 ) );

/** \brief Draws a thumbnail of the rasterlayer into the supplied QImage pointer
* @note added in QGIS 1.6
* */
void thumbnailAsImage( QImage * thepImage );
/* void thumbnailAsImage( QImage * thepImage ); */

/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
void triggerRepaint();
@@ -388,9 +388,7 @@ QPixmap QgsLegendLayer::getOriginalPixmap()
if ( s.value( "/qgis/createRasterLegendIcons", true ).toBool() )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( theLayer );
QPixmap myPixmap( 32, 32 );
rlayer->thumbnailAsPixmap( &myPixmap );
return myPixmap;
return rlayer->previewAsPixmap( QSize( 32, 32 ) );
}
else
{
@@ -626,19 +626,19 @@ void QgsRasterLayerProperties::sync()
}

//get the thumbnail for the layer
QPixmap myQPixmap = QPixmap( pixmapThumbnail->width(), pixmapThumbnail->height() );
mRasterLayer->thumbnailAsPixmap( &myQPixmap );
pixmapThumbnail->setPixmap( myQPixmap );
pixmapThumbnail->setPixmap( mRasterLayer->previewAsPixmap( pixmapThumbnail->size() ) );

// TODO fix legend + palette pixmap

//update the legend pixmap on this dialog
//pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();
// pixmapLegend->setScaledContents( true );
// pixmapLegend->repaint();

//set the palette pixmap
//pixmapPalette->setPixmap( mRasterLayer->paletteAsPixmap( mRasterLayer->bandNumber( mRasterLayer->grayBandName() ) ) );
pixmapPalette->setScaledContents( true );
pixmapPalette->repaint();
// pixmapPalette->setPixmap( mRasterLayer->paletteAsPixmap( mRasterLayer->bandNumber( mRasterLayer->grayBandName() ) ) );
// pixmapPalette->setScaledContents( true );
// pixmapPalette->repaint();

QgsDebugMsg( "populate metadata tab" );
/*
@@ -761,9 +761,9 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setMaximumScale( 1.0 / cbMaximumScale->scale() );

//update the legend pixmap
pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();
// pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
// pixmapLegend->setScaledContents( true );
// pixmapLegend->repaint();

QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();

@@ -803,9 +803,7 @@ void QgsRasterLayerProperties::apply()


//get the thumbnail for the layer
QPixmap myQPixmap = QPixmap( pixmapThumbnail->width(), pixmapThumbnail->height() );
mRasterLayer->thumbnailAsPixmap( &myQPixmap );
pixmapThumbnail->setPixmap( myQPixmap );
pixmapThumbnail->setPixmap( mRasterLayer->previewAsPixmap( pixmapThumbnail->size() ) );

mRasterLayer->setTitle( mLayerTitleLineEdit->text() );
mRasterLayer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
@@ -914,9 +912,10 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
}
}
//update the legend pixmap
pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();
// pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
// pixmapLegend->setScaledContents( true );
// pixmapLegend->repaint();

//populate the metadata tab's text browser widget with gdal metadata info
QString myStyle = QgsApplication::reportStyleSheet();
txtbMetadata->setHtml( mRasterLayer->metadata() );
@@ -2321,7 +2321,7 @@ QStringList QgsRasterLayer::subLayers() const

void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
{
//TODO: This should be depreciated and a new function written that just returns a new QPixmap, it will be safer
//deprecated, use previewAsPixmap() instead
if ( !theQPixmap )
return;

@@ -2372,9 +2372,64 @@ void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
delete myQPainter;
}

QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor )
{
QPixmap myQPixmap( size );

myQPixmap.fill( bgColor ); //defaults to white, set to transparent for rendering on a map

QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();

double myMapUnitsPerPixel;
double myX = 0.0;
double myY = 0.0;
QgsRectangle myExtent = mDataProvider->extent();
if ( myExtent.width() / myExtent.height() >= myQPixmap.width() / myQPixmap.height() )
{
myMapUnitsPerPixel = myExtent.width() / myQPixmap.width();
myY = ( myQPixmap.height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
}
else
{
myMapUnitsPerPixel = myExtent.height() / myQPixmap.height();
myX = ( myQPixmap.width() - myExtent.width() / myMapUnitsPerPixel ) / 2;
}

double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
double myPixelHeight = myExtent.height() / myMapUnitsPerPixel;

//myRasterViewPort->topLeftPoint = QgsPoint( 0, 0 );
myRasterViewPort->topLeftPoint = QgsPoint( myX, myY );

//myRasterViewPort->bottomRightPoint = QgsPoint( myQPixmap.width(), myQPixmap.height() );

myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
myRasterViewPort->drawableAreaXDim = myQPixmap.width();
myRasterViewPort->drawableAreaYDim = myQPixmap.height();
//myRasterViewPort->drawableAreaXDim = myPixelWidth;
//myRasterViewPort->drawableAreaYDim = myPixelHeight;

myRasterViewPort->mDrawnExtent = myExtent;
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid

QgsMapToPixel *myMapToPixel = new QgsMapToPixel( myMapUnitsPerPixel );

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

return myQPixmap;
}

#if 0
void QgsRasterLayer::thumbnailAsImage( QImage * thepImage )
{
//TODO: This should be depreciated and a new function written that just returns a new QImage, it will be safer
// removed as it's not used anywhere, use previewAsPixmap() instead
if ( !thepImage )
return;

@@ -2398,6 +2453,7 @@ void QgsRasterLayer::thumbnailAsImage( QImage * thepImage )
}

}
#endif

void QgsRasterLayer::triggerRepaint()
{
@@ -501,7 +501,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
QList< QPair< QString, QColor > > legendSymbologyItems() const;

/** \brief Get a legend image for this layer */
QPixmap legendAsPixmap();
Q_DECL_DEPRECATED QPixmap legendAsPixmap();

/** \brief Overloaded version of above function that can print layer name onto legend */
//! @deprecated
@@ -639,12 +639,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
virtual QStringList subLayers() const;

/** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
void thumbnailAsPixmap( QPixmap * theQPixmap );
Q_DECL_DEPRECATED void thumbnailAsPixmap( QPixmap * theQPixmap );

/** \brief Draws a preview of the rasterlayer into a pixmap */
QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );

/** \brief Draws a thumbnail of the rasterlayer into the supplied QImage pointer
* @note added in QGIS 1.6
* */
void thumbnailAsImage( QImage * thepImage );
/* Q_DECL_DEPRECATED void thumbnailAsImage( QImage * thepImage ); */

/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
void triggerRepaint();

0 comments on commit 777ce59

Please sign in to comment.
You can’t perform that action at this time.