Skip to content
Permalink
Browse files

Completed single band gray widget

  • Loading branch information
mhugent committed Mar 11, 2012
1 parent 579ccb3 commit c7d284d2caabcb3b83b6e0a64953963150ce35d1
@@ -27,13 +27,20 @@ QgsSingleBandGrayRenderer::QgsSingleBandGrayRenderer( QgsRasterDataProvider* pro

QgsSingleBandGrayRenderer::~QgsSingleBandGrayRenderer()
{
delete mContrastEnhancement;
}

QgsRasterRenderer* QgsSingleBandGrayRenderer::create( const QDomElement& elem )
{
return 0;
}

void QgsSingleBandGrayRenderer::setContrastEnhancement( QgsContrastEnhancement* ce )
{
delete mContrastEnhancement;
mContrastEnhancement = ce;
}

void QgsSingleBandGrayRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
{
if ( !p || !mProvider || !viewPort || !theQgsMapToPixel )
@@ -33,8 +33,11 @@ class QgsSingleBandGrayRenderer: public QgsRasterRenderer

virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

int grayBand() const { return mGrayBand; }
void setGrayBand( int band ) { mGrayBand = band; }
const QgsContrastEnhancement* contrastEnhancement() const { return mContrastEnhancement; }
void setContrastEnhancement( QgsContrastEnhancement* ce ) { mContrastEnhancement = ce; }
/**Takes ownership*/
void setContrastEnhancement( QgsContrastEnhancement* ce );

private:
int mGrayBand;
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgssinglebandgrayrendererwidget.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgsrasterlayer.h"

QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer* layer ): QgsRasterRendererWidget( layer )
@@ -42,6 +43,20 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer
mContrastEnhancementComboBox->addItem( tr( "Stretch to MinMax" ), 1 );
mContrastEnhancementComboBox->addItem( tr( "Stretch and clip to MinMax" ), 2 );
mContrastEnhancementComboBox->addItem( tr( "Clip to MinMax" ), 3 );

QgsSingleBandGrayRenderer* r = dynamic_cast<QgsSingleBandGrayRenderer*>( layer->renderer() );
if ( r )
{
//band
mGrayBandComboBox->setCurrentIndex( mGrayBandComboBox->findData( r->grayBand() ) );
const QgsContrastEnhancement* ce = r->contrastEnhancement();
//minmax
mMinLineEdit->setText( QString::number( ce->minimumValue() ) );
mMaxLineEdit->setText( QString::number( ce->maximumValue() ) );
//contrast enhancement algorithm
mContrastEnhancementComboBox->setCurrentIndex(
mContrastEnhancementComboBox->findData(( int )( ce->contrastEnhancementAlgorithm() ) ) );
}
}
}

@@ -51,5 +66,26 @@ QgsSingleBandGrayRendererWidget::~QgsSingleBandGrayRendererWidget()

QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer()
{
return 0; //soon...
if ( !mRasterLayer )
{
return 0;
}
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
if ( !provider )
{
return 0;
}
int band = mGrayBandComboBox->itemData( mGrayBandComboBox->currentIndex() ).toInt();

QgsContrastEnhancement* e = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( band ) ) );
e->setMinimumValue( mMinLineEdit->text().toInt() );
e->setMaximumValue( mMaxLineEdit->text().toInt() );
e->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm )( mContrastEnhancementComboBox->itemData(
mContrastEnhancementComboBox->currentIndex() ).toInt() ) );


QgsSingleBandGrayRenderer* renderer = new QgsSingleBandGrayRenderer( provider, band );
renderer->setContrastEnhancement( e );
return renderer;
}

0 comments on commit c7d284d

Please sign in to comment.