QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrastercontourrendererwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrastercontourrendererwidget.cpp
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
19 #include "qgsrasterlayer.h"
20 
21 
23  : QgsRasterRendererWidget( layer, extent )
24 {
25  setupUi( this );
26 
27  mContourSymbolButton->setSymbolType( QgsSymbol::Line );
28  mIndexContourSymbolButton->setSymbolType( QgsSymbol::Line );
29 
30  mInputBandComboBox->setLayer( mRasterLayer );
31 
32  if ( !mRasterLayer )
33  {
34  return;
35  }
37  if ( !provider )
38  {
39  return;
40  }
41 
42  const QgsRasterContourRenderer *rcr = dynamic_cast<const QgsRasterContourRenderer *>( mRasterLayer->renderer() );
43  if ( rcr )
44  {
45  mInputBandComboBox->setBand( rcr->inputBand() );
46  mContourIntervalSpinBox->setValue( rcr->contourInterval() );
47  mIndexContourIntervalSpinBox->setValue( rcr->contourIndexInterval() );
48  mDownscaleSpinBox->setValue( rcr->downscale() );
49  if ( rcr->contourSymbol() )
50  mContourSymbolButton->setSymbol( rcr->contourSymbol()->clone() );
51  if ( rcr->contourIndexSymbol() )
52  mIndexContourSymbolButton->setSymbol( rcr->contourIndexSymbol()->clone() );
53  }
54 
55  connect( mInputBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsRasterRendererWidget::widgetChanged );
56  connect( mContourIntervalSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
57  connect( mIndexContourIntervalSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
58  connect( mDownscaleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
59  connect( mContourSymbolButton, &QgsSymbolButton::changed, this, &QgsRasterRendererWidget::widgetChanged );
60  connect( mIndexContourSymbolButton, &QgsSymbolButton::changed, this, &QgsRasterRendererWidget::widgetChanged );
61 }
62 
64 {
65  if ( !mRasterLayer )
66  {
67  return nullptr;
68  }
69  QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
70  if ( !provider )
71  {
72  return nullptr;
73  }
74 
75  QgsRasterContourRenderer *renderer = new QgsRasterContourRenderer( provider );
76  renderer->setInputBand( mInputBandComboBox->currentBand() );
77  renderer->setContourInterval( mContourIntervalSpinBox->value() );
78  renderer->setContourIndexInterval( mIndexContourIntervalSpinBox->value() );
79  renderer->setDownscale( mDownscaleSpinBox->value() );
80  renderer->setContourSymbol( mContourSymbolButton->clonedSymbol<QgsLineSymbol>() );
81  renderer->setContourIndexSymbol( mIndexContourSymbolButton->clonedSymbol<QgsLineSymbol>() );
82  return renderer;
83 }
QgsRasterBandComboBox::bandChanged
void bandChanged(int band)
Emitted when the currently selected band changes.
QgsRasterContourRenderer::setInputBand
void setInputBand(int band)
Sets the number of the input raster band.
Definition: qgsrastercontourrenderer.h:58
QgsRasterContourRenderer::setDownscale
void setDownscale(double scale)
Sets by how much the renderer will scale down the request to the data provider.
Definition: qgsrastercontourrenderer.h:92
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
qgsrasterlayer.h
QgsRasterRendererWidget::mRasterLayer
QgsRasterLayer * mRasterLayer
Definition: qgsrasterrendererwidget.h:92
QgsLineSymbol::clone
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgssymbol.cpp:2193
QgsRasterContourRenderer::contourSymbol
QgsLineSymbol * contourSymbol() const
Returns the symbol used for contour lines.
Definition: qgsrastercontourrenderer.h:66
QgsRasterContourRenderer::setContourSymbol
void setContourSymbol(QgsLineSymbol *symbol)
Sets the symbol used for contour lines. Takes ownership of the passed symbol.
Definition: qgsrastercontourrenderer.cpp:218
QgsRasterContourRenderer::contourInterval
double contourInterval() const
Returns the interval of contour lines generation.
Definition: qgsrastercontourrenderer.h:61
QgsRasterContourRenderer::setContourIndexInterval
void setContourIndexInterval(double interval)
Sets the interval of index contour lines (index contour lines are typical further apart and with a wi...
Definition: qgsrastercontourrenderer.h:73
QgsRasterContourRenderer::inputBand
int inputBand() const
Returns the number of the input raster band.
Definition: qgsrastercontourrenderer.h:56
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRasterContourRenderer::contourIndexSymbol
QgsLineSymbol * contourIndexSymbol() const
Returns the symbol of index contour lines.
Definition: qgsrastercontourrenderer.h:76
QgsRasterContourRenderer::setContourInterval
void setContourInterval(double interval)
Sets the interval of contour lines generation.
Definition: qgsrastercontourrenderer.h:63
QgsRasterContourRendererWidget::renderer
QgsRasterRenderer * renderer() override
Definition: qgsrastercontourrendererwidget.cpp:63
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:39
QgsRasterContourRenderer
Raster renderer that generates contours on the fly for a source raster band.
Definition: qgsrastercontourrenderer.h:31
QgsRasterContourRenderer::setContourIndexSymbol
void setContourIndexSymbol(QgsLineSymbol *symbol)
Sets the symbol of index contour lines.
Definition: qgsrastercontourrenderer.cpp:223
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:234
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
qgsrastercontourrendererwidget.h
QgsRasterContourRenderer::downscale
double downscale() const
Returns by how much the renderer will scale down the request to the data provider.
Definition: qgsrastercontourrenderer.h:86
qgsrastercontourrenderer.h
QgsSymbol::Line
@ Line
Line symbol.
Definition: qgssymbol.h:88
QgsRasterLayer::renderer
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
Definition: qgsrasterlayer.h:246
QgsRasterRendererWidget
Definition: qgsrasterrendererwidget.h:37
QgsRasterRendererWidget::widgetChanged
void widgetChanged()
Emitted when something on the widget has changed.
QgsRasterContourRenderer::contourIndexInterval
double contourIndexInterval() const
Returns the interval of index contour lines (index contour lines are typical further apart and with a...
Definition: qgsrastercontourrenderer.h:71
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
QgsRasterContourRendererWidget::QgsRasterContourRendererWidget
QgsRasterContourRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
Constructs the widget.
Definition: qgsrastercontourrendererwidget.cpp:22