Skip to content

Commit 3c3b77b

Browse files
committed
Restore properties in singleband pseudo color dialog
1 parent 7c7d36a commit 3c3b77b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/core/raster/qgssinglebandpseudocolorrenderer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
3636

3737
/**Takes ownership of the shader*/
3838
void setShader( QgsRasterShader* shader );
39-
const QgsRasterShader* shader;
39+
QgsRasterShader* shader() { return mShader; }
4040

4141
private:
4242
QgsRasterShader* mShader;

src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,36 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
5252
QgsSingleBandPseudoColorRenderer* r = dynamic_cast<QgsSingleBandPseudoColorRenderer*>( layer->renderer() );
5353
if ( r )
5454
{
55-
//todo...
55+
QgsRasterShader* rasterShader = r->shader();
56+
if ( rasterShader )
57+
{
58+
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
59+
if ( colorRampShader )
60+
{
61+
if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
62+
{
63+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
64+
}
65+
else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
66+
{
67+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
68+
}
69+
else
70+
{
71+
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
72+
}
73+
74+
const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
75+
QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
76+
for ( ; it != colorRampItemList.end(); ++it )
77+
{
78+
QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
79+
newItem->setText( 0, QString::number( it->value, 'f' ) );
80+
newItem->setBackground( 1, QBrush( it->color ) );
81+
newItem->setText( 2, it->label );
82+
}
83+
}
84+
}
5685
}
5786
}
5887

@@ -107,7 +136,7 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
107136
void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
108137
{
109138
int bandComboIndex = mBandComboBox->currentIndex();
110-
if ( bandComboIndex == -1 )
139+
if ( bandComboIndex == -1 || !mRasterLayer )
111140
{
112141
return;
113142
}

0 commit comments

Comments
 (0)