Skip to content
Permalink
Browse files
Auto load raster color table from band when band is changed in
paletted raster renderer

(Only if raster has an embedded color table)
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 17a3d1f commit 12aa48a712e77f960d17c7fbc925075a018acfdf
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/gui/raster/qgspalettedrendererwidget.cpp
@@ -89,7 +89,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
}

setFromRenderer( mRasterLayer->renderer() );
connect( mBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mBandComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterRendererWidget::widgetChanged );
}

connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
@@ -111,6 +111,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
}

connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( QgsMapLayer * ) >( &QgsProject::layerWillBeRemoved ), this, &QgsPalettedRendererWidget::layerWillBeRemoved );
connect( mBandComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPalettedRendererWidget::loadFromLayer );
}

QgsPalettedRendererWidget::~QgsPalettedRendererWidget()
@@ -425,9 +426,13 @@ void QgsPalettedRendererWidget::loadFromLayer()
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
if ( provider )
{
QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::colorTableToClassData( provider->colorTable( mBandComboBox->currentData().toInt() ) );
mModel->setClassData( classes );
emit widgetChanged();
QList<QgsColorRampShader::ColorRampItem> table = provider->colorTable( mBandComboBox->currentData().toInt() );
if ( !table.isEmpty() )
{
QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::colorTableToClassData( provider->colorTable( mBandComboBox->currentData().toInt() ) );
mModel->setClassData( classes );
emit widgetChanged();
}
}
}

0 comments on commit 12aa48a

Please sign in to comment.