예제 #1
0
void QgsRendererRasterPropertiesWidget::apply()
{
    mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
    mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );

    QgsRasterRendererWidget* rendererWidget = dynamic_cast<QgsRasterRendererWidget*>( stackedWidget->currentWidget() );
    if ( rendererWidget )
    {
        mRasterLayer->setRenderer( rendererWidget->renderer() );
    }

    // Hue and saturation controls
    QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
    if ( hueSaturationFilter )
    {
        hueSaturationFilter->setSaturation( sliderSaturation->value() );
        hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
        hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
        hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
        hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
    }

    QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();
    if ( resampleFilter )
    {
        QgsRasterResampler *zoomedInResampler = nullptr;
        QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
        if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
        {
            zoomedInResampler = new QgsBilinearRasterResampler();
        }
        else if ( zoomedInResamplingMethod == tr( "Cubic" ) )
        {
            zoomedInResampler = new QgsCubicRasterResampler();
        }

        resampleFilter->setZoomedInResampler( zoomedInResampler );

        //raster resampling
        QgsRasterResampler *zoomedOutResampler = nullptr;
        QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
        if ( zoomedOutResamplingMethod == tr( "Average" ) )
        {
            zoomedOutResampler = new QgsBilinearRasterResampler();
        }

        resampleFilter->setZoomedOutResampler( zoomedOutResampler );

        resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
    }

    mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
}
예제 #2
0
void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &rendererName )
{
    QgsDebugMsg( "rendererName = " + rendererName );
    QgsRasterRendererWidget* oldWidget = mRendererWidget;

    QgsRasterRendererRegistryEntry rendererEntry;
    if ( QgsRasterRendererRegistry::instance()->rendererData( rendererName, rendererEntry ) )
    {
        if ( rendererEntry.widgetCreateFunction ) //single band color data renderer e.g. has no widget
        {
            QgsDebugMsg( "renderer has widgetCreateFunction" );
            // Current canvas extent (used to calc min/max) in layer CRS
            QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
            mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
            mRendererWidget->setMapCanvas( mMapCanvas );
            connect( mRendererWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
            stackedWidget->addWidget( mRendererWidget );
            stackedWidget->setCurrentWidget( mRendererWidget );
            if ( oldWidget )
            {
                //compare used bands in new and old renderer and reset transparency dialog if different
                QgsRasterRenderer* oldRenderer = oldWidget->renderer();
                QgsRasterRenderer* newRenderer = mRendererWidget->renderer();
                QList<int> oldBands = oldRenderer->usesBands();
                QList<int> newBands = newRenderer->usesBands();
//        if ( oldBands != newBands )
//        {
//          populateTransparencyTable( newRenderer );
//        }
                delete oldRenderer;
                delete newRenderer;
            }
        }
    }

    if ( mRendererWidget != oldWidget )
        delete oldWidget;

    int widgetIndex = cboRenderers->findData( rendererName );
    if ( widgetIndex != -1 )
    {
        whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
    }

}
void QgsRendererRasterPropertiesWidget::apply()
{
  mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
  mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );

  QgsRasterRendererWidget* rendererWidget = dynamic_cast<QgsRasterRendererWidget*>( stackedWidget->currentWidget() );
  if ( rendererWidget )
  {
    mRasterLayer->setRenderer( rendererWidget->renderer() );
  }

  // Hue and saturation controls
  QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
  if ( hueSaturationFilter )
  {
    hueSaturationFilter->setSaturation( sliderSaturation->value() );
    hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
    hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
    hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
    hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
  }

  mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
}
void QgsRendererRasterPropertiesWidget::apply()
{
  mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
  mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );

  QgsRasterRendererWidget* rendererWidget = dynamic_cast<QgsRasterRendererWidget*>( stackedWidget->currentWidget() );
  if ( rendererWidget )
  {
    QgsRasterRenderer* newRenderer = rendererWidget->renderer();

    // there are transparency related data stored in renderer instances, but they
    // are not configured in the widget, so we need to copy them over from existing renderer
    QgsRasterRenderer* oldRenderer = mRasterLayer->renderer();
    if ( oldRenderer )
      newRenderer->copyCommonProperties( oldRenderer );

    mRasterLayer->setRenderer( newRenderer );
  }

  // Hue and saturation controls
  QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
  if ( hueSaturationFilter )
  {
    hueSaturationFilter->setSaturation( sliderSaturation->value() );
    hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
    hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
    hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
    hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
  }

  QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();
  if ( resampleFilter )
  {
    QgsRasterResampler *zoomedInResampler = nullptr;
    QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
    if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
    {
      zoomedInResampler = new QgsBilinearRasterResampler();
    }
    else if ( zoomedInResamplingMethod == tr( "Cubic" ) )
    {
      zoomedInResampler = new QgsCubicRasterResampler();
    }

    resampleFilter->setZoomedInResampler( zoomedInResampler );

    //raster resampling
    QgsRasterResampler *zoomedOutResampler = nullptr;
    QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
    if ( zoomedOutResamplingMethod == tr( "Average" ) )
    {
      zoomedOutResampler = new QgsBilinearRasterResampler();
    }

    resampleFilter->setZoomedOutResampler( zoomedOutResampler );

    resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
  }

  mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
}
void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &rendererName )
{
  QgsDebugMsg( "rendererName = " + rendererName );
  QgsRasterRendererWidget *oldWidget = mRendererWidget;
  QgsRasterRenderer *oldRenderer = mRasterLayer->renderer();

  int alphaBand = -1;
  double opacity = 1;
  if ( oldRenderer )
  {
    // Retain alpha band and opacity when switching renderer
    alphaBand = oldRenderer->alphaBand();
    opacity = oldRenderer->opacity();
  }

  QgsRasterRendererRegistryEntry rendererEntry;
  if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererName, rendererEntry ) )
  {
    if ( rendererEntry.widgetCreateFunction ) // Single band color data renderer e.g. has no widget
    {
      QgsDebugMsg( QStringLiteral( "renderer has widgetCreateFunction" ) );
      // Current canvas extent (used to calc min/max) in layer CRS
      QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
      if ( oldWidget )
      {
        if ( rendererName == QLatin1String( "singlebandgray" ) )
        {
          whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
          whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
        }
        else if ( rendererName == QLatin1String( "multibandcolor" ) )
        {
          whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
          whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
        }
      }
      mRasterLayer->renderer()->setAlphaBand( alphaBand );
      mRasterLayer->renderer()->setOpacity( opacity );
      mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
      mRendererWidget->setMapCanvas( mMapCanvas );
      connect( mRendererWidget, &QgsRasterRendererWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
      stackedWidget->addWidget( mRendererWidget );
      stackedWidget->setCurrentWidget( mRendererWidget );
      if ( oldWidget )
      {
        // Compare used bands in new and old renderer and reset transparency dialog if different
        QgsRasterRenderer *oldRenderer = oldWidget->renderer();
        QgsRasterRenderer *newRenderer = mRendererWidget->renderer();
#if 0
        QList<int> oldBands = oldRenderer->usesBands();
        QList<int> newBands = newRenderer->usesBands();

        if ( oldBands != newBands )
        {
          populateTransparencyTable( newRenderer );
        }
#endif

        delete oldRenderer;
        delete newRenderer;
      }
    }
  }

  if ( mRendererWidget != oldWidget )
    delete oldWidget;

  int widgetIndex = cboRenderers->findData( rendererName );
  if ( widgetIndex != -1 )
  {
    whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
  }

}