QgsRasterRenderer* QgsSingleBandGrayRenderer::create( const QDomElement& elem, QgsRasterInterface* input ) { if ( elem.isNull() ) { return 0; } int grayBand = elem.attribute( "grayBand", "-1" ).toInt(); QgsSingleBandGrayRenderer* r = new QgsSingleBandGrayRenderer( input, grayBand ); r->readXML( elem ); if ( elem.attribute( "gradient" ) == "WhiteToBlack" ) { r->setGradient( WhiteToBlack ); // BlackToWhite is default } QDomElement contrastEnhancementElem = elem.firstChildElement( "contrastEnhancement" ); if ( !contrastEnhancementElem.isNull() ) { QgsContrastEnhancement* ce = new QgsContrastEnhancement(( QGis::DataType )( input->dataType( grayBand ) ) ); ce->readXML( contrastEnhancementElem ); r->setContrastEnhancement( ce ); } return r; }
QgsRasterRenderer *QgsSingleBandGrayRendererWidget::renderer() { if ( !mRasterLayer ) { return nullptr; } QgsRasterDataProvider *provider = mRasterLayer->dataProvider(); if ( !provider ) { return nullptr; } int band = mGrayBandComboBox->currentBand(); QgsContrastEnhancement *e = new QgsContrastEnhancement( ( Qgis::DataType )( provider->dataType( band ) ) ); e->setMinimumValue( mMinLineEdit->text().toDouble() ); e->setMaximumValue( mMaxLineEdit->text().toDouble() ); e->setContrastEnhancementAlgorithm( ( QgsContrastEnhancement::ContrastEnhancementAlgorithm )( mContrastEnhancementComboBox->currentData().toInt() ) ); QgsSingleBandGrayRenderer *renderer = new QgsSingleBandGrayRenderer( provider, band ); renderer->setContrastEnhancement( e ); renderer->setGradient( ( QgsSingleBandGrayRenderer::Gradient ) mGradientComboBox->currentData().toInt() ); renderer->setMinMaxOrigin( mMinMaxWidget->minMaxOrigin() ); return renderer; }
QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer() { 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().toDouble() ); e->setMaximumValue( mMaxLineEdit->text().toDouble() ); e->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm )( mContrastEnhancementComboBox->itemData( mContrastEnhancementComboBox->currentIndex() ).toInt() ) ); QgsSingleBandGrayRenderer* renderer = new QgsSingleBandGrayRenderer( provider, band ); renderer->setContrastEnhancement( e ); return renderer; }
QgsRasterRenderer* QgsMultiBandColorRenderer::create( const QDomElement& elem, QgsRasterInterface* input ) { if ( elem.isNull() ) { return 0; } //red band, green band, blue band int redBand = elem.attribute( "redBand", "-1" ).toInt(); int greenBand = elem.attribute( "greenBand", "-1" ).toInt(); int blueBand = elem.attribute( "blueBand", "-1" ).toInt(); //contrast enhancements QgsContrastEnhancement* redContrastEnhancement = 0; QDomElement redContrastElem = elem.firstChildElement( "redContrastEnhancement" ); if ( !redContrastElem.isNull() ) { redContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( input->dataType( redBand ) ) ); redContrastEnhancement->readXML( redContrastElem ); } QgsContrastEnhancement* greenContrastEnhancement = 0; QDomElement greenContrastElem = elem.firstChildElement( "greenContrastEnhancement" ); if ( !greenContrastElem.isNull() ) { greenContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( input->dataType( greenBand ) ) ); greenContrastEnhancement->readXML( greenContrastElem ); } QgsContrastEnhancement* blueContrastEnhancement = 0; QDomElement blueContrastElem = elem.firstChildElement( "blueContrastEnhancement" ); if ( !blueContrastElem.isNull() ) { blueContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( input->dataType( blueBand ) ) ); blueContrastEnhancement->readXML( blueContrastElem ); } QgsRasterRenderer* r = new QgsMultiBandColorRenderer( input, redBand, greenBand, blueBand, redContrastEnhancement, greenContrastEnhancement, blueContrastEnhancement ); r->readXML( elem ); return r; }
void QgsMultiBandColorRendererWidget::setCustomMinMaxValues( QgsMultiBandColorRenderer* r, const QgsRasterDataProvider* provider, int redBand, int greenBand, int blueBand ) { if ( !r || !provider ) { return; } if ( mContrastEnhancementAlgorithmComboBox->itemData( mContrastEnhancementAlgorithmComboBox->currentIndex() ).toInt() == QgsContrastEnhancement::NoEnhancement ) { r->setRedContrastEnhancement( 0 ); r->setGreenContrastEnhancement( 0 ); r->setBlueContrastEnhancement( 0 ); return; } QgsContrastEnhancement* redEnhancement = 0; QgsContrastEnhancement* greenEnhancement = 0; QgsContrastEnhancement* blueEnhancement = 0; bool redMinOk, redMaxOk; double redMin = mRedMinLineEdit->text().toDouble( &redMinOk ); double redMax = mRedMaxLineEdit->text().toDouble( &redMaxOk ); if ( redMinOk && redMaxOk ) { redEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( provider->dataType( redBand ) ) ); redEnhancement->setMinimumValue( redMin ); redEnhancement->setMaximumValue( redMax ); } bool greenMinOk, greenMaxOk; double greenMin = mGreenMinLineEdit->text().toDouble( &greenMinOk ); double greenMax = mGreenMaxLineEdit->text().toDouble( &greenMaxOk ); if ( greenMinOk && greenMaxOk ) { greenEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( provider->dataType( greenBand ) ) ); greenEnhancement->setMinimumValue( greenMin ); greenEnhancement->setMaximumValue( greenMax ); } bool blueMinOk, blueMaxOk; double blueMin = mBlueMinLineEdit->text().toDouble( &blueMinOk ); double blueMax = mBlueMaxLineEdit->text().toDouble( &blueMaxOk ); if ( blueMinOk && blueMaxOk ) { blueEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )( provider->dataType( blueBand ) ) ); blueEnhancement->setMinimumValue( blueMin ); blueEnhancement->setMaximumValue( blueMax ); } if ( redEnhancement ) { redEnhancement->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm ) ( mContrastEnhancementAlgorithmComboBox->itemData( mContrastEnhancementAlgorithmComboBox->currentIndex() ).toInt() ) ); } if ( greenEnhancement ) { greenEnhancement->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm ) ( mContrastEnhancementAlgorithmComboBox->itemData( mContrastEnhancementAlgorithmComboBox->currentIndex() ).toInt() ) ); } if ( blueEnhancement ) { blueEnhancement->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm ) ( mContrastEnhancementAlgorithmComboBox->itemData( mContrastEnhancementAlgorithmComboBox->currentIndex() ).toInt() ) ); } r->setRedContrastEnhancement( redEnhancement ); r->setGreenContrastEnhancement( greenEnhancement ); r->setBlueContrastEnhancement( blueEnhancement ); }