Skip to content
Permalink
Browse files

Raster layer properties dock panel: add 'Early resampling' checkbox, …

…and move common code with raster properties dialog into a QgsResamplingUtils class
  • Loading branch information
rouault authored and nyalldawson committed Jun 19, 2020
1 parent d2497c8 commit 904a3378041aafd272df602f91e2e580ca938599
@@ -14,6 +14,7 @@ SET(QGIS_GUI_SRCS
raster/qgsrendererrasterpropertieswidget.cpp
raster/qgsrastertransparencywidget.cpp
raster/qgshillshaderendererwidget.cpp
raster/qgsresamplingutils.cpp

vector/qgsattributeactiondialog.cpp
vector/qgsattributeactionpropertiesdialog.cpp
@@ -1065,6 +1066,7 @@ SET(QGIS_GUI_HDRS
raster/qgssinglebandpseudocolorrendererwidget.h
raster/qgsrasterlayerproperties.h
raster/qgsrasterlayertemporalpropertieswidget.h
raster/qgsresamplingutils.h

vector/qgsattributeactiondialog.h
vector/qgsattributeactionpropertiesdialog.h
@@ -20,11 +20,9 @@

#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsbilinearrasterresampler.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgscontrastenhancement.h"
#include "qgscoordinatetransform.h"
#include "qgscubicrasterresampler.h"
#include "qgsprojectionselectiondialog.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@@ -48,7 +46,6 @@
#include "qgsrasterrange.h"
#include "qgsrasterrenderer.h"
#include "qgsrasterrendererregistry.h"
#include "qgsrasterresamplefilter.h"
#include "qgsrastertransparency.h"
#include "qgssinglebandgrayrendererwidget.h"
#include "qgssinglebandpseudocolorrendererwidget.h"
@@ -360,81 +357,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv

//resampling
mResamplingGroupBox->setSaveCheckedState( true );
const QgsRasterRenderer *renderer = mRasterLayer->renderer();
mZoomedInResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedInResamplingComboBox->insertItem( 1, tr( "Bilinear" ) );
mZoomedInResamplingComboBox->insertItem( 2, tr( "Cubic" ) );
mZoomedOutResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedOutResamplingComboBox->insertItem( 1, tr( "Average" ) );

mCbEarlyResampling->setVisible(
provider && ( provider->providerCapabilities() & QgsRasterDataProvider::ProviderHintCanPerformProviderResampling ) );
mCbEarlyResampling->setChecked( mRasterLayer->resamplingStage() == QgsRasterPipe::ResamplingStage::Provider );
mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
mResamplingUtils.refreshWidgetsFromLayer();

if ( provider && mRasterLayer->resamplingStage() == QgsRasterPipe::ResamplingStage::Provider )
{
if ( provider->zoomedInResamplingMethod() == QgsRasterDataProvider::ResamplingMethod::Bilinear )
{
mZoomedInResamplingComboBox->setCurrentIndex( 1 );
}
else if ( provider->zoomedInResamplingMethod() == QgsRasterDataProvider::ResamplingMethod::Cubic )
{
mZoomedInResamplingComboBox->setCurrentIndex( 2 );
}
else
{
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
}

if ( provider->zoomedOutResamplingMethod() == QgsRasterDataProvider::ResamplingMethod::Bilinear )
{
mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
}
else
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}

mMaximumOversamplingSpinBox->setValue( provider->maxOversampling() );
}
else
{
const QgsRasterResampleFilter *resampleFilter = mRasterLayer->resampleFilter();
//set combo boxes to current resampling types
if ( resampleFilter )
{
const QgsRasterResampler *zoomedInResampler = resampleFilter->zoomedInResampler();
if ( zoomedInResampler )
{
if ( zoomedInResampler->type() == QLatin1String( "bilinear" ) )
{
mZoomedInResamplingComboBox->setCurrentIndex( 1 );
}
else if ( zoomedInResampler->type() == QLatin1String( "cubic" ) )
{
mZoomedInResamplingComboBox->setCurrentIndex( 2 );
}
}
else
{
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
}

const QgsRasterResampler *zoomedOutResampler = resampleFilter->zoomedOutResampler();
if ( zoomedOutResampler )
{
if ( zoomedOutResampler->type() == QLatin1String( "bilinear" ) ) //bilinear resampler does averaging when zooming out
{
mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
}
}
else
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
}
}
const QgsRasterRenderer *renderer = mRasterLayer->renderer();

btnColorizeColor->setColorDialogTitle( tr( "Select Color" ) );
btnColorizeColor->setContext( QStringLiteral( "symbology" ) );
@@ -1099,64 +1025,7 @@ void QgsRasterLayerProperties::apply()
// pixmapLegend->setScaledContents( true );
// pixmapLegend->repaint();

const QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
const QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();

mRasterLayer->setResamplingStage( mCbEarlyResampling->isChecked() ? QgsRasterPipe::ResamplingStage::Provider : QgsRasterPipe::ResamplingStage::ResampleFilter );
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
if ( provider )
{
if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
{
provider->setZoomedInResamplingMethod( QgsRasterDataProvider::ResamplingMethod::Bilinear );
}
else if ( zoomedInResamplingMethod == tr( "Cubic" ) )
{
provider->setZoomedInResamplingMethod( QgsRasterDataProvider::ResamplingMethod::Cubic );
}
else
{
provider->setZoomedInResamplingMethod( QgsRasterDataProvider::ResamplingMethod::Nearest );
}

if ( zoomedOutResamplingMethod == tr( "Average" ) )
{
provider->setZoomedOutResamplingMethod( QgsRasterDataProvider::ResamplingMethod::Bilinear );
}
else
{
provider->setZoomedOutResamplingMethod( QgsRasterDataProvider::ResamplingMethod::Nearest );
}

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

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

resampleFilter->setZoomedInResampler( zoomedInResampler );

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

resampleFilter->setZoomedOutResampler( zoomedOutResampler );

resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
}
mResamplingUtils.refreshLayerFromWidgets();

// Hue and saturation controls
QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
@@ -28,6 +28,7 @@
#include "qgsmaplayerstylemanager.h"
#include "qgsmaptoolemitpoint.h"
#include "qgis_gui.h"
#include "qgsresamplingutils.h"

class QgsPointXY;
class QgsMapLayer;
@@ -281,6 +282,8 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
//! Synchronize state with associated raster layer
void sync();

QgsResamplingUtils mResamplingUtils;

friend class QgsAppScreenShots;
};
#endif
@@ -27,9 +27,6 @@
#include "qgsmultibandcolorrendererwidget.h"
#include "qgspalettedrendererwidget.h"
#include "qgshillshaderendererwidget.h"
#include "qgsrasterresamplefilter.h"
#include "qgsbilinearrasterresampler.h"
#include "qgscubicrasterresampler.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgsapplication.h"
@@ -57,10 +54,8 @@ static void _initRendererWidgetFunctions()

QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )

, mRasterLayer( qobject_cast<QgsRasterLayer *>( layer ) )
{
mRasterLayer = qobject_cast<QgsRasterLayer *>( layer );

if ( !mRasterLayer )
return;

@@ -69,11 +64,7 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLaye

_initRendererWidgetFunctions();

mZoomedInResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedInResamplingComboBox->insertItem( 1, tr( "Bilinear" ) );
mZoomedInResamplingComboBox->insertItem( 2, tr( "Cubic" ) );
mZoomedOutResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedOutResamplingComboBox->insertItem( 1, tr( "Average" ) );
mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );

connect( cboRenderers, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRendererRasterPropertiesWidget::rendererChanged );

@@ -108,6 +99,7 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLaye
connect( mZoomedInResamplingComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mZoomedOutResamplingComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mMaximumOversamplingSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mCbEarlyResampling, &QAbstractButton::toggled, this, &QgsPanelWidget::widgetChanged );

// finally sync to the layer - even though some actions may emit widgetChanged signal,
// this is not a problem - nobody is listening to our signals yet
@@ -160,33 +152,7 @@ void QgsRendererRasterPropertiesWidget::apply()
hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
}

if ( QgsRasterResampleFilter *resampleFilter = mRasterLayer->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() );
}
mResamplingUtils.refreshLayerFromWidgets();

mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
}
@@ -248,39 +214,7 @@ void QgsRendererRasterPropertiesWidget::syncToLayer( QgsRasterLayer *layer )
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );

//set combo boxes to current resampling types
if ( const QgsRasterResampleFilter *resampleFilter = mRasterLayer->resampleFilter() )
{
const QgsRasterResampler *zoomedInResampler = resampleFilter->zoomedInResampler();
if ( zoomedInResampler )
{
if ( zoomedInResampler->type() == QLatin1String( "bilinear" ) )
{
mZoomedInResamplingComboBox->setCurrentIndex( 1 );
}
else if ( zoomedInResampler->type() == QLatin1String( "cubic" ) )
{
mZoomedInResamplingComboBox->setCurrentIndex( 2 );
}
}
else
{
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
}

const QgsRasterResampler *zoomedOutResampler = resampleFilter->zoomedOutResampler();
if ( zoomedOutResampler )
{
if ( zoomedOutResampler->type() == QLatin1String( "bilinear" ) ) //bilinear resampler does averaging when zooming out
{
mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
}
}
else
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
}
mResamplingUtils.refreshWidgetsFromLayer();
}

void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
@@ -21,6 +21,7 @@
#include "ui_qgsrendererrasterpropswidgetbase.h"

#include "qgsmaplayerconfigwidget.h"
#include "qgsresamplingutils.h"
#include "qgis_gui.h"


@@ -89,6 +90,8 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QgsMapLayerConfigWid

QgsRasterLayer *mRasterLayer = nullptr;
QgsRasterRendererWidget *mRendererWidget = nullptr;

QgsResamplingUtils mResamplingUtils;
};

#endif // QGSRENDERERRASTERPROPERTIESDIALOG_H

0 comments on commit 904a337

Please sign in to comment.
You can’t perform that action at this time.