Skip to content
Permalink
Browse files

WMS transparency fix, issue #6276

  • Loading branch information
blazek committed Sep 3, 2012
1 parent d9c9052 commit e5389212c4ebeb2074f6d27d419987f4108bdb61
@@ -282,7 +282,11 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
if ( QgsRasterRendererRegistry::instance()->rendererData( name, entry ) )
{
mRenderTypeComboBox->addItem( entry.visibleName, entry.name );
if (( mRasterLayer->rasterType() != QgsRasterLayer::ColorLayer && entry.name != "singlebandcolordata" ) ||
( mRasterLayer->rasterType() == QgsRasterLayer::ColorLayer && entry.name == "singlebandcolordata" ) )
{
mRenderTypeComboBox->addItem( entry.visibleName, entry.name );
}
}
}

@@ -296,6 +300,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
}

//prevent change between singleband color renderer and the other renderers
// No more necessary, combo entries according to layer type
#if 0
if ( rendererType == "singlebandcolordata" )
{
mRenderTypeComboBox->setEnabled( false );
@@ -304,6 +310,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
mRenderTypeComboBox->removeItem( mRenderTypeComboBox->findData( "singlebandcolordata" ) );
}
#endif
}
on_mRenderTypeComboBox_currentIndexChanged( mRenderTypeComboBox->currentIndex() );

@@ -425,13 +432,15 @@ void QgsRasterLayerProperties::populateTransparencyTable( QgsRasterRenderer* ren

void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
{
QgsDebugMsg( "rendererName = " + rendererName );
QgsRasterRendererWidget* oldWidget = mRendererWidget;

QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsRasterRendererRegistry::instance()->rendererData( rendererName, rendererEntry ) )
{
if ( rendererEntry.widgetCreateFunction ) //single band color data renderer e.g. has no widget
{
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = ( *rendererEntry.widgetCreateFunction )( mRasterLayer, myExtent );
@@ -1699,7 +1699,8 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
mValidNoDataValue = mDataProvider->isNoDataValueValid();

// set up the raster drawing style
setDrawingStyle( MultiBandColor ); //sensible default
// Do not set any 'sensible' style here, the style is set later
// setDrawingStyle( MultiBandColor ); //sensible default

// Setup source CRS
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
@@ -74,13 +74,13 @@ bool QgsRasterRenderer::setInput( QgsRasterInterface* input )

for ( int i = 1; i <= input->bandCount(); i++ )
{
if ( typeIsNumeric( input->dataType( i ) ) )
if ( !typeIsNumeric( input->dataType( i ) ) )
{
mInput = input;
return true;
return false;
}
}
return false;
mInput = input;
return true;
}

bool QgsRasterRenderer::usesTransparency( ) const
@@ -76,18 +76,15 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons
}
else
{
QRgb pixelColor;
double alpha = 255.0;
for ( int j = 0; j < width; ++j )
{
QRgb pixelColor;
double alpha = 255.0;
for ( int j = 0; j < width; ++j )
{
QRgb c((( uint* )( rasterData ) )[currentRasterPos] );
alpha = qAlpha( c );
pixelColor = qRgba( qRed( c ), qGreen( c ), qBlue( c ), mOpacity * alpha );
memcpy( &( scanLine[j*4] ), &pixelColor, 4 );
++currentRasterPos;
}
QRgb c((( uint* )( rasterData ) )[currentRasterPos] );
alpha = qAlpha( c );
pixelColor = qRgba( mOpacity * qRed( c ), mOpacity * qGreen( c ), mOpacity * qBlue( c ), mOpacity * alpha );
memcpy( &( scanLine[j*4] ), &pixelColor, 4 );
++currentRasterPos;
}
}
}
@@ -119,3 +116,24 @@ QList<int> QgsSingleBandColorDataRenderer::usesBands() const
}
return bandList;
}

bool QgsSingleBandColorDataRenderer::setInput( QgsRasterInterface* input )
{
// Renderer can only work with numerical values in at least 1 band
if ( !input ) return false;

if ( !mOn )
{
// In off mode we can connect to anything
mInput = input;
return true;
}

if ( input->dataType( 1 ) == QgsRasterInterface::ARGB32 ||
input->dataType( 1 ) == QgsRasterInterface::ARGB32_Premultiplied )
{
mInput = input;
return true;
}
return false;
}
@@ -31,6 +31,8 @@ class CORE_EXPORT QgsSingleBandColorDataRenderer: public QgsRasterRenderer

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterInterface* input );

bool setInput( QgsRasterInterface* input );

void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

0 comments on commit e538921

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