Skip to content
Permalink
Browse files

Add resample options to raster style dock

  • Loading branch information
NathanW2 committed Jun 3, 2016
1 parent a6294cf commit 6b52f7ea0e35c1291a18264280473cef22f8345f
@@ -1,11 +1,11 @@
class QgsRendererRasterPropertiesWidget : QWidget
class QgsRendererRasterPropertiesWidget : QgsMapStylePanel
{
%TypeHeaderCode
#include <qgsrendererrasterpropertieswidget.h>
%End

public:
QgsRendererRasterPropertiesWidget( QgsMapCanvas* canvas, QWidget* parent );
QgsRendererRasterPropertiesWidget( QgsMapLayer* layer, QgsMapCanvas* canvas, QWidget* parent );
~QgsRendererRasterPropertiesWidget();

/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
@@ -176,11 +176,6 @@ void QgsMapStylingWidget::apply()
undoName = QString( "Style Change - %1" ).arg( m->visibleName() );
styleWasChanged = true;
}
else if ( QgsRendererRasterPropertiesWidget* widget = qobject_cast<QgsRendererRasterPropertiesWidget*>( current ) )
{
widget->apply();
styleWasChanged = true;
}
else if ( QgsRasterTransparencyWidget* widget = qobject_cast<QgsRasterTransparencyWidget*>( current ) )
{
widget->apply();
@@ -297,8 +292,7 @@ void QgsMapStylingWidget::updateCurrentWidgetLayer()
switch ( row )
{
case 0: // Style
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( mMapCanvas, mWidgetArea );
mRasterStyleWidget->syncToLayer( rlayer );
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetArea );
connect( mRasterStyleWidget, SIGNAL( widgetChanged() ), this, SLOT( autoApply() ) );

mWidgetArea->setWidget( mRasterStyleWidget );
@@ -317,7 +311,7 @@ void QgsMapStylingWidget::updateCurrentWidgetLayer()
mRasterStyleWidget->deleteLater();
delete mRasterStyleWidget;
}
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( mMapCanvas, mWidgetArea );
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetArea );
mRasterStyleWidget->syncToLayer( rlayer );
connect( mRasterStyleWidget, SIGNAL( widgetChanged() ), this, SLOT( autoApply() ) );

@@ -24,6 +24,9 @@
#include "qgsmultibandcolorrendererwidget.h"
#include "qgspalettedrendererwidget.h"
#include "qgshillshaderendererwidget.h"
#include "qgsrasterresamplefilter.h"
#include "qgsbilinearrasterresampler.h"
#include "qgscubicrasterresampler.h"


static void _initRendererWidgetFunctions()
@@ -43,16 +46,26 @@ static void _initRendererWidgetFunctions()



QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapCanvas* canvas, QWidget *parent )
: QWidget( parent )
, mRasterLayer( nullptr )
, mMapCanvas( canvas )
QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLayer *layer, QgsMapCanvas* canvas, QWidget *parent )
: QgsMapStylePanel( layer, canvas, parent )
, mRendererWidget( nullptr )
{
mRasterLayer = qobject_cast<QgsRasterLayer*>( layer );
if ( !mRasterLayer )
return;

setupUi( this );

_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" ) );

syncToLayer( mRasterLayer );

connect( cboRenderers, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rendererChanged() ) );

connect( mSliderBrightness, SIGNAL( valueChanged( int ) ), mBrightnessSpinBox, SLOT( setValue( int ) ) );
@@ -88,6 +101,11 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapCanv

// enable or disable colorize colorbutton with colorize checkbox
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), this, SLOT( toggleColorizeControls( bool ) ) );

connect( mZoomedInResamplingComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mZoomedOutResamplingComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mMaximumOversamplingSpinBox, SIGNAL( valueChanged( double ) ), this, SIGNAL( widgetChanged() ) );

}

QgsRendererRasterPropertiesWidget::~QgsRendererRasterPropertiesWidget()
@@ -129,6 +147,35 @@ void QgsRendererRasterPropertiesWidget::apply()
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() );
}

@@ -189,6 +236,42 @@ void QgsRendererRasterPropertiesWidget::syncToLayer( QgsRasterLayer* layer )

//blend mode
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );

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

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

void QgsRendererRasterPropertiesWidget::on_mResetColorRenderingBtn_clicked()
@@ -20,11 +20,14 @@

#include "ui_qgsrendererrasterpropswidgetbase.h"

#include "qgsmapstylepanel.h"


class QgsRasterLayer;
class QgsMapCanvas;
class QgsRasterRendererWidget;

class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui::QgsRendererRasterPropsWidgetBase
class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QgsMapStylePanel, private Ui::QgsRendererRasterPropsWidgetBase
{
Q_OBJECT

@@ -34,7 +37,7 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui:
* @param canvas The canvas object used to calculate the max and min values from the extent.
* @param parent Parent object
*/
QgsRendererRasterPropertiesWidget( QgsMapCanvas *canvas, QWidget *parent = 0 );
QgsRendererRasterPropertiesWidget( QgsMapLayer* layer, QgsMapCanvas *canvas, QWidget *parent = 0 );
~QgsRendererRasterPropertiesWidget();

/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
@@ -49,14 +52,6 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui:
*/
QgsRasterRendererWidget* currentRenderWidget() { return mRendererWidget; }

signals:

/**
* Emitted when something on the widget has changed.
* All widgets will fire this event to notify of an internal change.
*/
void widgetChanged();

public slots:
//! called when user changes renderer type
void rendererChanged();
@@ -83,7 +78,6 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui:
void setRendererWidget( const QString& rendererName );

QgsRasterLayer* mRasterLayer;
QgsMapCanvas* mMapCanvas;
QgsRasterRendererWidget* mRendererWidget;
};

@@ -209,7 +209,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="mOptsPage_General">
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -238,8 +238,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>541</height>
<width>615</width>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -463,8 +463,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>544</height>
<width>615</width>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
@@ -1094,8 +1094,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>541</height>
<width>435</width>
<height>461</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -1510,8 +1510,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>659</width>
<height>527</height>
<width>559</width>
<height>217</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -1574,7 +1574,7 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
@@ -1680,8 +1680,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>541</height>
<width>86</width>
<height>36</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
@@ -1739,8 +1739,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>697</height>
<width>334</width>
<height>659</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
@@ -2194,6 +2194,17 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
@@ -2217,17 +2228,6 @@ p, li { white-space: pre-wrap; }
<header>qgslayertreeembeddedconfigwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mOptionsListWidget</tabstop>

0 comments on commit 6b52f7e

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