示例#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 QgsLayerStylingWidget::updateCurrentWidgetLayer()
{
  if ( !mCurrentLayer )
    return;  // non-spatial are ignored in setLayer()

  mBlockAutoApply = true;

  whileBlocking( mLayerCombo )->setLayer( mCurrentLayer );

  int row = mOptionsListWidget->currentIndex().row();

  mStackedWidget->setCurrentIndex( mLayerPage );

  QgsPanelWidget *current = mWidgetStack->takeMainPanel();
  if ( current )
  {
    if ( QgsLabelingWidget *widget = qobject_cast<QgsLabelingWidget *>( current ) )
    {
      mLabelingWidget = widget;
    }
    else if ( QgsUndoWidget *widget = qobject_cast<QgsUndoWidget *>( current ) )
    {
      mUndoWidget = widget;
    }
    else if ( QgsRendererRasterPropertiesWidget *widget = qobject_cast<QgsRendererRasterPropertiesWidget *>( current ) )
    {
      mRasterStyleWidget = widget;
    }
#ifdef HAVE_3D
    else if ( QgsVectorLayer3DRendererWidget *widget = qobject_cast<QgsVectorLayer3DRendererWidget *>( current ) )
    {
      mVector3DWidget = widget;
    }
#endif

  }

  mWidgetStack->clear();
  // Create the user page widget if we are on one of those pages
  // TODO Make all widgets use this method.
  if ( mUserPages.contains( row ) )
  {
    QgsMapLayerConfigWidget *panel = mUserPages[row]->createWidget( mCurrentLayer, mMapCanvas, true, mWidgetStack );
    if ( panel )
    {
      connect( panel, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
      mWidgetStack->setMainPanel( panel );
    }
  }

  // The last widget is always the undo stack.
  if ( row == mOptionsListWidget->count() - 1 )
  {
    mWidgetStack->setMainPanel( mUndoWidget );
  }
  else if ( mCurrentLayer->type() == QgsMapLayer::VectorLayer )
  {
    QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );

    switch ( row )
    {
      case 0: // Style
      {
        QgsRendererPropertiesDialog *styleWidget = new QgsRendererPropertiesDialog( vlayer, QgsStyle::defaultStyle(), true, mStackedWidget );
        styleWidget->setMapCanvas( mMapCanvas );
        styleWidget->setDockMode( true );
        connect( styleWidget, &QgsRendererPropertiesDialog::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
        QgsPanelWidgetWrapper *wrapper = new QgsPanelWidgetWrapper( styleWidget, mStackedWidget );
        wrapper->setDockMode( true );
        connect( styleWidget, &QgsRendererPropertiesDialog::showPanel, wrapper, &QgsPanelWidget::openPanel );
        mWidgetStack->setMainPanel( wrapper );
        break;
      }
      case 1: // Labels
      {
        if ( !mLabelingWidget )
        {
          mLabelingWidget = new QgsLabelingWidget( nullptr, mMapCanvas, mWidgetStack );
          mLabelingWidget->setDockMode( true );
          connect( mLabelingWidget, &QgsLabelingWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
        }
        mLabelingWidget->setLayer( vlayer );
        mWidgetStack->setMainPanel( mLabelingWidget );
        break;
      }
#ifdef HAVE_3D
      case 2:  // 3D View
      {
        if ( !mVector3DWidget )
        {
          mVector3DWidget = new QgsVectorLayer3DRendererWidget( nullptr, mMapCanvas, mWidgetStack );
          mVector3DWidget->setDockMode( true );
          connect( mVector3DWidget, &QgsVectorLayer3DRendererWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
        }
        mVector3DWidget->setLayer( vlayer );
        mWidgetStack->setMainPanel( mVector3DWidget );
        break;
      }
#endif
      default:
        break;
    }
  }
  else if ( mCurrentLayer->type() == QgsMapLayer::RasterLayer )
  {
    QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( mCurrentLayer );
    bool hasMinMaxCollapsedState = false;
    bool minMaxCollapsed = false;

    switch ( row )
    {
      case 0: // Style
      {
        // Backup collapsed state of min/max group so as to restore it
        // on the new widget.
        if ( mRasterStyleWidget )
        {
          QgsRasterRendererWidget *currentRenderWidget = mRasterStyleWidget->currentRenderWidget();
          if ( currentRenderWidget )
          {
            QgsRasterMinMaxWidget *mmWidget = currentRenderWidget->minMaxWidget();
            if ( mmWidget )
            {
              hasMinMaxCollapsedState = true;
              minMaxCollapsed = mmWidget->isCollapsed();
            }
          }
        }
        mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetStack );
        if ( hasMinMaxCollapsedState )
        {
          QgsRasterRendererWidget *currentRenderWidget = mRasterStyleWidget->currentRenderWidget();
          if ( currentRenderWidget )
          {
            QgsRasterMinMaxWidget *mmWidget = currentRenderWidget->minMaxWidget();
            if ( mmWidget )
            {
              mmWidget->setCollapsed( minMaxCollapsed );
            }
          }
        }
        mRasterStyleWidget->setDockMode( true );
        connect( mRasterStyleWidget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
        mWidgetStack->setMainPanel( mRasterStyleWidget );
        break;
      }

      case 1: // Transparency
      {
        QgsRasterTransparencyWidget *transwidget = new QgsRasterTransparencyWidget( rlayer, mMapCanvas, mWidgetStack );
        transwidget->setDockMode( true );
        connect( transwidget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
        mWidgetStack->setMainPanel( transwidget );
        break;
      }
      case 2: // Histogram
      {
        if ( rlayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
        {
          if ( !mRasterStyleWidget )
          {
            mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetStack );
            mRasterStyleWidget->syncToLayer( rlayer );
          }
          connect( mRasterStyleWidget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );

          QgsRasterHistogramWidget *widget = new QgsRasterHistogramWidget( rlayer, mWidgetStack );
          connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
          QString name = mRasterStyleWidget->currentRenderWidget()->renderer()->type();
          widget->setRendererWidget( name, mRasterStyleWidget->currentRenderWidget() );
          widget->setDockMode( true );

          mWidgetStack->setMainPanel( widget );
        }
        break;
      }
      default:
        break;
    }
  }
  else
  {
    mStackedWidget->setCurrentIndex( mNotSupportedPage );
  }

  mBlockAutoApply = false;
}
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 );
  }

}