24
24
#include " qgsmultibandcolorrendererwidget.h"
25
25
#include " qgspalettedrendererwidget.h"
26
26
#include " qgshillshaderendererwidget.h"
27
+ #include " qgsrasterresamplefilter.h"
28
+ #include " qgsbilinearrasterresampler.h"
29
+ #include " qgscubicrasterresampler.h"
27
30
28
31
29
32
static void _initRendererWidgetFunctions ()
@@ -43,16 +46,26 @@ static void _initRendererWidgetFunctions()
43
46
44
47
45
48
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 )
50
51
, mRendererWidget( nullptr )
51
52
{
53
+ mRasterLayer = qobject_cast<QgsRasterLayer*>( layer );
54
+ if ( !mRasterLayer )
55
+ return ;
56
+
52
57
setupUi ( this );
53
58
54
59
_initRendererWidgetFunctions ();
55
60
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
+
56
69
connect ( cboRenderers, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( rendererChanged () ) );
57
70
58
71
connect ( mSliderBrightness , SIGNAL ( valueChanged ( int ) ), mBrightnessSpinBox , SLOT ( setValue ( int ) ) );
@@ -88,6 +101,11 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapCanv
88
101
89
102
// enable or disable colorize colorbutton with colorize checkbox
90
103
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
+
91
109
}
92
110
93
111
QgsRendererRasterPropertiesWidget::~QgsRendererRasterPropertiesWidget ()
@@ -129,6 +147,35 @@ void QgsRendererRasterPropertiesWidget::apply()
129
147
hueSaturationFilter->setColorizeStrength ( sliderColorizeStrength->value () );
130
148
}
131
149
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
+
132
179
mRasterLayer ->setBlendMode ( mBlendModeComboBox ->blendMode () );
133
180
}
134
181
@@ -189,6 +236,42 @@ void QgsRendererRasterPropertiesWidget::syncToLayer( QgsRasterLayer* layer )
189
236
190
237
// blend mode
191
238
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
+ }
192
275
}
193
276
194
277
void QgsRendererRasterPropertiesWidget::on_mResetColorRenderingBtn_clicked ()
0 commit comments