Skip to content

Commit 6b52f7e

Browse files
committed
Add resample options to raster style dock
1 parent a6294cf commit 6b52f7e

6 files changed

+182
-74
lines changed

python/gui/raster/qgsrendererrasterpropertieswidget.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
class QgsRendererRasterPropertiesWidget : QWidget
1+
class QgsRendererRasterPropertiesWidget : QgsMapStylePanel
22
{
33
%TypeHeaderCode
44
#include <qgsrendererrasterpropertieswidget.h>
55
%End
66

77
public:
8-
QgsRendererRasterPropertiesWidget( QgsMapCanvas* canvas, QWidget* parent );
8+
QgsRendererRasterPropertiesWidget( QgsMapLayer* layer, QgsMapCanvas* canvas, QWidget* parent );
99
~QgsRendererRasterPropertiesWidget();
1010

1111
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current

src/app/qgsmapstylingwidget.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,6 @@ void QgsMapStylingWidget::apply()
176176
undoName = QString( "Style Change - %1" ).arg( m->visibleName() );
177177
styleWasChanged = true;
178178
}
179-
else if ( QgsRendererRasterPropertiesWidget* widget = qobject_cast<QgsRendererRasterPropertiesWidget*>( current ) )
180-
{
181-
widget->apply();
182-
styleWasChanged = true;
183-
}
184179
else if ( QgsRasterTransparencyWidget* widget = qobject_cast<QgsRasterTransparencyWidget*>( current ) )
185180
{
186181
widget->apply();
@@ -297,8 +292,7 @@ void QgsMapStylingWidget::updateCurrentWidgetLayer()
297292
switch ( row )
298293
{
299294
case 0: // Style
300-
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( mMapCanvas, mWidgetArea );
301-
mRasterStyleWidget->syncToLayer( rlayer );
295+
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetArea );
302296
connect( mRasterStyleWidget, SIGNAL( widgetChanged() ), this, SLOT( autoApply() ) );
303297

304298
mWidgetArea->setWidget( mRasterStyleWidget );
@@ -317,7 +311,7 @@ void QgsMapStylingWidget::updateCurrentWidgetLayer()
317311
mRasterStyleWidget->deleteLater();
318312
delete mRasterStyleWidget;
319313
}
320-
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( mMapCanvas, mWidgetArea );
314+
mRasterStyleWidget = new QgsRendererRasterPropertiesWidget( rlayer, mMapCanvas, mWidgetArea );
321315
mRasterStyleWidget->syncToLayer( rlayer );
322316
connect( mRasterStyleWidget, SIGNAL( widgetChanged() ), this, SLOT( autoApply() ) );
323317

src/gui/raster/qgsrendererrasterpropertieswidget.cpp

+87-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "qgsmultibandcolorrendererwidget.h"
2525
#include "qgspalettedrendererwidget.h"
2626
#include "qgshillshaderendererwidget.h"
27+
#include "qgsrasterresamplefilter.h"
28+
#include "qgsbilinearrasterresampler.h"
29+
#include "qgscubicrasterresampler.h"
2730

2831

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

4447

4548

46-
QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapCanvas* canvas, QWidget *parent )
47-
: QWidget( parent )
48-
, mRasterLayer( nullptr )
49-
, mMapCanvas( canvas )
49+
QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLayer *layer, QgsMapCanvas* canvas, QWidget *parent )
50+
: QgsMapStylePanel( layer, canvas, parent )
5051
, mRendererWidget( nullptr )
5152
{
53+
mRasterLayer = qobject_cast<QgsRasterLayer*>( layer );
54+
if ( !mRasterLayer )
55+
return;
56+
5257
setupUi( this );
5358

5459
_initRendererWidgetFunctions();
5560

61+
mZoomedInResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
62+
mZoomedInResamplingComboBox->insertItem( 1, tr( "Bilinear" ) );
63+
mZoomedInResamplingComboBox->insertItem( 2, tr( "Cubic" ) );
64+
mZoomedOutResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
65+
mZoomedOutResamplingComboBox->insertItem( 1, tr( "Average" ) );
66+
67+
syncToLayer( mRasterLayer );
68+
5669
connect( cboRenderers, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rendererChanged() ) );
5770

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

89102
// enable or disable colorize colorbutton with colorize checkbox
90103
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), this, SLOT( toggleColorizeControls( bool ) ) );
104+
105+
connect( mZoomedInResamplingComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
106+
connect( mZoomedOutResamplingComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
107+
connect( mMaximumOversamplingSpinBox, SIGNAL( valueChanged( double ) ), this, SIGNAL( widgetChanged() ) );
108+
91109
}
92110

93111
QgsRendererRasterPropertiesWidget::~QgsRendererRasterPropertiesWidget()
@@ -129,6 +147,35 @@ void QgsRendererRasterPropertiesWidget::apply()
129147
hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
130148
}
131149

150+
QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();
151+
if ( resampleFilter )
152+
{
153+
QgsRasterResampler *zoomedInResampler = nullptr;
154+
QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
155+
if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
156+
{
157+
zoomedInResampler = new QgsBilinearRasterResampler();
158+
}
159+
else if ( zoomedInResamplingMethod == tr( "Cubic" ) )
160+
{
161+
zoomedInResampler = new QgsCubicRasterResampler();
162+
}
163+
164+
resampleFilter->setZoomedInResampler( zoomedInResampler );
165+
166+
//raster resampling
167+
QgsRasterResampler *zoomedOutResampler = nullptr;
168+
QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
169+
if ( zoomedOutResamplingMethod == tr( "Average" ) )
170+
{
171+
zoomedOutResampler = new QgsBilinearRasterResampler();
172+
}
173+
174+
resampleFilter->setZoomedOutResampler( zoomedOutResampler );
175+
176+
resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
177+
}
178+
132179
mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
133180
}
134181

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

190237
//blend mode
191238
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
239+
240+
const QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();
241+
//set combo boxes to current resampling types
242+
if ( resampleFilter )
243+
{
244+
const QgsRasterResampler* zoomedInResampler = resampleFilter->zoomedInResampler();
245+
if ( zoomedInResampler )
246+
{
247+
if ( zoomedInResampler->type() == "bilinear" )
248+
{
249+
mZoomedInResamplingComboBox->setCurrentIndex( 1 );
250+
}
251+
else if ( zoomedInResampler->type() == "cubic" )
252+
{
253+
mZoomedInResamplingComboBox->setCurrentIndex( 2 );
254+
}
255+
}
256+
else
257+
{
258+
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
259+
}
260+
261+
const QgsRasterResampler* zoomedOutResampler = resampleFilter->zoomedOutResampler();
262+
if ( zoomedOutResampler )
263+
{
264+
if ( zoomedOutResampler->type() == "bilinear" ) //bilinear resampler does averaging when zooming out
265+
{
266+
mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
267+
}
268+
}
269+
else
270+
{
271+
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
272+
}
273+
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
274+
}
192275
}
193276

194277
void QgsRendererRasterPropertiesWidget::on_mResetColorRenderingBtn_clicked()

src/gui/raster/qgsrendererrasterpropertieswidget.h

+5-11
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
#include "ui_qgsrendererrasterpropswidgetbase.h"
2222

23+
#include "qgsmapstylepanel.h"
24+
25+
2326
class QgsRasterLayer;
2427
class QgsMapCanvas;
2528
class QgsRasterRendererWidget;
2629

27-
class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui::QgsRendererRasterPropsWidgetBase
30+
class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QgsMapStylePanel, private Ui::QgsRendererRasterPropsWidgetBase
2831
{
2932
Q_OBJECT
3033

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

4043
/** 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:
4952
*/
5053
QgsRasterRendererWidget* currentRenderWidget() { return mRendererWidget; }
5154

52-
signals:
53-
54-
/**
55-
* Emitted when something on the widget has changed.
56-
* All widgets will fire this event to notify of an internal change.
57-
*/
58-
void widgetChanged();
59-
6055
public slots:
6156
//! called when user changes renderer type
6257
void rendererChanged();
@@ -83,7 +78,6 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QWidget, private Ui:
8378
void setRendererWidget( const QString& rendererName );
8479

8580
QgsRasterLayer* mRasterLayer;
86-
QgsMapCanvas* mMapCanvas;
8781
QgsRasterRendererWidget* mRendererWidget;
8882
};
8983

src/ui/qgsrasterlayerpropertiesbase.ui

+25-25
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
</sizepolicy>
210210
</property>
211211
<property name="currentIndex">
212-
<number>0</number>
212+
<number>1</number>
213213
</property>
214214
<widget class="QWidget" name="mOptsPage_General">
215215
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -238,8 +238,8 @@
238238
<rect>
239239
<x>0</x>
240240
<y>0</y>
241-
<width>617</width>
242-
<height>541</height>
241+
<width>615</width>
242+
<height>542</height>
243243
</rect>
244244
</property>
245245
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -463,8 +463,8 @@
463463
<rect>
464464
<x>0</x>
465465
<y>0</y>
466-
<width>603</width>
467-
<height>544</height>
466+
<width>615</width>
467+
<height>542</height>
468468
</rect>
469469
</property>
470470
<layout class="QVBoxLayout" name="verticalLayout_10">
@@ -1094,8 +1094,8 @@
10941094
<rect>
10951095
<x>0</x>
10961096
<y>0</y>
1097-
<width>617</width>
1098-
<height>541</height>
1097+
<width>435</width>
1098+
<height>461</height>
10991099
</rect>
11001100
</property>
11011101
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -1510,8 +1510,8 @@
15101510
<rect>
15111511
<x>0</x>
15121512
<y>0</y>
1513-
<width>659</width>
1514-
<height>527</height>
1513+
<width>559</width>
1514+
<height>217</height>
15151515
</rect>
15161516
</property>
15171517
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -1574,7 +1574,7 @@
15741574
<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;
15751575
&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;
15761576
p, li { white-space: pre-wrap; }
1577-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
1577+
&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;
15781578
&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>
15791579
</property>
15801580
</widget>
@@ -1680,8 +1680,8 @@ p, li { white-space: pre-wrap; }
16801680
<rect>
16811681
<x>0</x>
16821682
<y>0</y>
1683-
<width>617</width>
1684-
<height>541</height>
1683+
<width>86</width>
1684+
<height>36</height>
16851685
</rect>
16861686
</property>
16871687
<layout class="QVBoxLayout" name="verticalLayout_16">
@@ -1739,8 +1739,8 @@ p, li { white-space: pre-wrap; }
17391739
<rect>
17401740
<x>0</x>
17411741
<y>0</y>
1742-
<width>603</width>
1743-
<height>697</height>
1742+
<width>334</width>
1743+
<height>659</height>
17441744
</rect>
17451745
</property>
17461746
<layout class="QGridLayout" name="gridLayout_12">
@@ -2194,6 +2194,17 @@ p, li { white-space: pre-wrap; }
21942194
</layout>
21952195
</widget>
21962196
<customwidgets>
2197+
<customwidget>
2198+
<class>QgsColorButtonV2</class>
2199+
<extends>QToolButton</extends>
2200+
<header>qgscolorbuttonv2.h</header>
2201+
<container>1</container>
2202+
</customwidget>
2203+
<customwidget>
2204+
<class>QgsBlendModeComboBox</class>
2205+
<extends>QComboBox</extends>
2206+
<header>qgsblendmodecombobox.h</header>
2207+
</customwidget>
21972208
<customwidget>
21982209
<class>QgsCollapsibleGroupBox</class>
21992210
<extends>QGroupBox</extends>
@@ -2217,17 +2228,6 @@ p, li { white-space: pre-wrap; }
22172228
<header>qgslayertreeembeddedconfigwidget.h</header>
22182229
<container>1</container>
22192230
</customwidget>
2220-
<customwidget>
2221-
<class>QgsColorButtonV2</class>
2222-
<extends>QToolButton</extends>
2223-
<header>qgscolorbuttonv2.h</header>
2224-
<container>1</container>
2225-
</customwidget>
2226-
<customwidget>
2227-
<class>QgsBlendModeComboBox</class>
2228-
<extends>QComboBox</extends>
2229-
<header>qgsblendmodecombobox.h</header>
2230-
</customwidget>
22312231
</customwidgets>
22322232
<tabstops>
22332233
<tabstop>mOptionsListWidget</tabstop>

0 commit comments

Comments
 (0)