Skip to content
Permalink
Browse files

Add method to query used bands to renderer, use it in raster properti…

…es dialog
  • Loading branch information
mhugent committed Jun 30, 2012
1 parent bddb759 commit 8ffc1342929f4f9ab06e9b952866b35d2339bf21
@@ -325,8 +325,43 @@ void QgsRasterLayerProperties::populateTransparencyTable()
return;
}

tableTransparency->clear();

QList<int> bandList = renderer->usesBands();
tableTransparency->setColumnCount( bandList.size() + 1 );
for ( int i = 0; i < bandList.size(); ++i )
{
tableTransparency->setHorizontalHeaderItem( i, new QTableWidgetItem( QString::number( bandList.at( i ) ) ) );
}

const QgsRasterTransparency* rasterTransparency = renderer->rasterTransparency();
if ( !rasterTransparency )
{
return;
}

if ( bandList.count() == 1 )
{
tableTransparency->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Percent Transparent" ) ) );
QList<QgsRasterTransparency::TransparentSingleValuePixel> pixelList = rasterTransparency->transparentSingleValuePixelList();
for ( int i = 0; i < pixelList.size(); ++i )
{
tableTransparency->insertRow( i );
QTableWidgetItem* grayItem = new QTableWidgetItem( QString::number( pixelList[i].pixelValue ) );
QTableWidgetItem* percentItem = new QTableWidgetItem( QString::number( pixelList[i].percentTransparent ) );
tableTransparency->setItem( i, 0, grayItem );
tableTransparency->setItem( i, 1, percentItem );
}
}
else if ( bandList.count() == 3 )
{

}




#if 0
//Clear existing color transparency list
//NOTE: May want to just tableTransparency->clearContents() and fill back in after checking to be sure list and table are the same size
QString myNumberFormatter;
@@ -405,6 +440,7 @@ void QgsRasterLayerProperties::populateTransparencyTable()

tableTransparency->resizeColumnsToContents();
tableTransparency->resizeRowsToContents();
#endif //0
}

void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
@@ -351,3 +351,21 @@ void QgsMultiBandColorRenderer::writeXML( QDomDocument& doc, QDomElement& parent
}
parentElem.appendChild( rasterRendererElem );
}

QList<int> QgsMultiBandColorRenderer::usesBands() const
{
QList<int> bandList;
if ( mRedBand != -1 )
{
bandList << mRedBand;
}
if ( mGreenBand != -1 )
{
bandList << mGreenBand;
}
if ( mBlueBand != -1 )
{
bandList << mBlueBand;
}
return bandList;
}
@@ -57,6 +57,8 @@ class CORE_EXPORT QgsMultiBandColorRenderer: public QgsRasterRenderer

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

QList<int> usesBands() const;

private:
int mRedBand;
int mGreenBand;
@@ -217,3 +217,13 @@ void QgsPalettedRasterRenderer::legendSymbologyItems( QList< QPair< QString, QCo
symbolItems.push_back( qMakePair( QString::number( i ), mColors[i] ) );
}
}

QList<int> QgsPalettedRasterRenderer::usesBands() const
{
QList<int> bandList;
if ( mBandNumber != -1 )
{
bandList << mBandNumber;
}
return bandList;
}
@@ -42,6 +42,8 @@ class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
int mBandNumber;
/**Color array*/
@@ -85,6 +85,9 @@ class CORE_EXPORT QgsRasterRenderer
/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& rendererElem );

/**Returns a list of band numbers used by the renderer*/
virtual QList<int> usesBands() const { return QList<int>(); }

protected:
inline double readValue( void *data, QgsRasterDataProvider::DataType type, int index );

@@ -114,3 +114,13 @@ void QgsSingleBandColorDataRenderer::writeXML( QDomDocument& doc, QDomElement& p
rasterRendererElem.setAttribute( "band", mBand );
parentElem.appendChild( rasterRendererElem );
}

QList<int> QgsSingleBandColorDataRenderer::usesBands() const
{
QList<int> bandList;
if ( mBand != -1 )
{
bandList << mBand;
}
return bandList;
}
@@ -34,6 +34,8 @@ class CORE_EXPORT QgsSingleBandColorDataRenderer: public QgsRasterRenderer

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

QList<int> usesBands() const;

private:
int mBand;
};
@@ -199,3 +199,13 @@ void QgsSingleBandGrayRenderer::legendSymbologyItems( QList< QPair< QString, QCo
symbolItems.push_back( qMakePair( QString::number( mContrastEnhancement->maximumValue() ), QColor( 255, 255, 255 ) ) );
}
}

QList<int> QgsSingleBandGrayRenderer::usesBands() const
{
QList<int> bandList;
if ( mGrayBand != -1 )
{
bandList << mGrayBand;
}
return bandList;
}
@@ -43,6 +43,8 @@ class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
int mGrayBand;
QgsContrastEnhancement* mContrastEnhancement;
@@ -191,3 +191,13 @@ void QgsSingleBandPseudoColorRenderer::legendSymbologyItems( QList< QPair< QStri
}
}
}

QList<int> QgsSingleBandPseudoColorRenderer::usesBands() const
{
QList<int> bandList;
if ( mBand != -1 )
{
bandList << mBand;
}
return bandList;
}
@@ -43,6 +43,8 @@ class CORE_EXPORT QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

QList<int> usesBands() const;

private:
QgsRasterShader* mShader;
int mBand;

0 comments on commit 8ffc134

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