Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix transparency band in raster layer props, start implementing write…
…XML methods of renderers
  • Loading branch information
mhugent committed Mar 27, 2012
1 parent 1e2215a commit fbd944c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
32 changes: 27 additions & 5 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -121,9 +121,14 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
pbnAddValuesFromDisplay->setEnabled( false );
}

if ( !mRasterLayer )
{
return;
}
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();

// Only do pyramids if dealing directly with GDAL.
if ( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::BuildPyramids )
if ( provider->capabilities() & QgsRasterDataProvider::BuildPyramids )
{
QgsRasterLayer::RasterPyramidList myPyramidList = mRasterLayer->buildPyramidList();
QgsRasterLayer::RasterPyramidList::iterator myRasterPyramidIterator;
Expand Down Expand Up @@ -231,6 +236,22 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mMaximumOversamplingSpinBox->setValue( renderer->maxOversampling() );
}

//transparency band
if ( provider )
{
cboxTransparencyBand->addItem( tr( "None" ), -1 );
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
cboxTransparencyBand->addItem( provider->colorInterpretationName( i ), i );
}

if ( renderer )
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
}
}

//insert renderer widgets into registry
QgsRasterRendererRegistry::instance()->insertWidgetFunction( "paletted", QgsPalettedRendererWidget::create );
QgsRasterRendererRegistry::instance()->insertWidgetFunction( "multibandcolor", QgsMultiBandColorRendererWidget::create );
Expand Down Expand Up @@ -569,11 +590,12 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setRenderer( rendererWidget->renderer() );
}

//resampling
//transparency settings
QgsRasterRenderer* rasterRenderer = mRasterLayer->renderer();
QgsRasterTransparency* rasterTransparency = new QgsRasterTransparency();
rasterRenderer->setAlphaBand( cboxTransparencyBand->itemData( cboxTransparencyBand->currentIndex() ).toInt() );

//Walk through each row in table and test value. If not valid set to 0.0 and continue building transparency list
QgsRasterTransparency* rasterTransparency = new QgsRasterTransparency();
if ( mRasterLayer->bandCount() == 3 )
{
double myTransparentValue;
Expand Down Expand Up @@ -736,8 +758,7 @@ void QgsRasterLayerProperties::apply()
}
rasterRenderer->setRasterTransparency( rasterTransparency );

//set transparency
//rasterRenderer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );
//set global transparency
rasterRenderer->setOpacity(( 255 - sliderTransparency->value() ) / 255.0 );

QgsDebugMsg( "processing general tab" );
Expand Down Expand Up @@ -772,6 +793,7 @@ void QgsRasterLayerProperties::apply()
rasterRenderer->setZoomedInResampler( zoomedInResampler );
}

//raster resampling
QgsRasterResampler* zoomedOutResampler = 0;
QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
if ( zoomedOutResamplingMethod == tr( "Average" ) )
Expand Down
13 changes: 12 additions & 1 deletion src/core/raster/qgsmultibandcolorrenderer.cpp
Expand Up @@ -19,6 +19,8 @@
#include "qgscontrastenhancement.h"
#include "qgsrastertransparency.h"
#include "qgsrasterviewport.h"
#include <QDomDocument>
#include <QDomElement>
#include <QImage>
#include <QSet>

Expand Down Expand Up @@ -276,5 +278,14 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,

void QgsMultiBandColorRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
//soon...
if ( !parentElem.isNull() )
{
return;
}

QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
_writeXML( doc, parentElem );
rasterRendererElem.setAttribute( "redBand", mRedBand );
rasterRendererElem.setAttribute( "greenBand", mGreenBand );
rasterRendererElem.setAttribute( "blueBand", mBlueBand );
}
5 changes: 5 additions & 0 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -160,6 +160,11 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,

void QgsPalettedRasterRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
if ( parentElem.isNull() )
{
return;
}

QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
_writeXML( doc, rasterRendererElem );

Expand Down
5 changes: 3 additions & 2 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -28,7 +28,7 @@
<item row="0" column="0" colspan="4">
<widget class="QTabWidget" name="tabBar">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -256,7 +256,7 @@
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="cboxTransparencyBand">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand Down Expand Up @@ -829,6 +829,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:10pt;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;&quot;&gt;&lt;/p&gt;
Expand Down

0 comments on commit fbd944c

Please sign in to comment.