Skip to content

Commit

Permalink
Restore properties in singleband pseudo color dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 22, 2012
1 parent 7c7d36a commit 3c3b77b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandpseudocolorrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer

/**Takes ownership of the shader*/
void setShader( QgsRasterShader* shader );
const QgsRasterShader* shader;
QgsRasterShader* shader() { return mShader; }

private:
QgsRasterShader* mShader;
Expand Down
33 changes: 31 additions & 2 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,36 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
QgsSingleBandPseudoColorRenderer* r = dynamic_cast<QgsSingleBandPseudoColorRenderer*>( layer->renderer() );
if ( r )
{
//todo...
QgsRasterShader* rasterShader = r->shader();
if ( rasterShader )
{
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
if ( colorRampShader )
{
if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
}
else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
}
else
{
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
}

const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
for ( ; it != colorRampItemList.end(); ++it )
{
QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
newItem->setText( 0, QString::number( it->value, 'f' ) );
newItem->setBackground( 1, QBrush( it->color ) );
newItem->setText( 2, it->label );
}
}
}
}
}

Expand Down Expand Up @@ -107,7 +136,7 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
{
int bandComboIndex = mBandComboBox->currentIndex();
if ( bandComboIndex == -1 )
if ( bandComboIndex == -1 || !mRasterLayer )
{
return;
}
Expand Down

0 comments on commit 3c3b77b

Please sign in to comment.