QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgslinesymbol.h"
21 
23  : QgsRasterRendererWidget( layer, extent )
24 {
25  setupUi( this );
26 
27  mContourSymbolButton->setSymbolType( Qgis::SymbolType::Line );
28  mIndexContourSymbolButton->setSymbolType( Qgis::SymbolType::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:59
QgsRasterContourRenderer::setDownscale
void setDownscale(double scale)
Sets by how much the renderer will scale down the request to the data provider.
Definition: qgsrastercontourrenderer.h:93
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
qgsrasterlayer.h
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsRasterRendererWidget::mRasterLayer
QgsRasterLayer * mRasterLayer
Definition: qgsrasterrendererwidget.h:123
QgsLineSymbol::clone
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgslinesymbol.cpp:303
QgsRasterContourRenderer::contourSymbol
QgsLineSymbol * contourSymbol() const
Returns the symbol used for contour lines.
Definition: qgsrastercontourrenderer.h:67
QgsRasterContourRenderer::setContourSymbol
void setContourSymbol(QgsLineSymbol *symbol)
Sets the symbol used for contour lines. Takes ownership of the passed symbol.
Definition: qgsrastercontourrenderer.cpp:236
QgsRasterContourRenderer::contourInterval
double contourInterval() const
Returns the interval of contour lines generation.
Definition: qgsrastercontourrenderer.h:62
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:74
QgsRasterContourRenderer::inputBand
int inputBand() const
Returns the number of the input raster band.
Definition: qgsrastercontourrenderer.h:57
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRasterContourRenderer::contourIndexSymbol
QgsLineSymbol * contourIndexSymbol() const
Returns the symbol of index contour lines.
Definition: qgsrastercontourrenderer.h:77
QgsRasterLayer::renderer
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
Definition: qgsrasterlayer.cpp:1758
QgsRasterContourRenderer::setContourInterval
void setContourInterval(double interval)
Sets the interval of contour lines generation.
Definition: qgsrastercontourrenderer.h:64
QgsRasterContourRendererWidget::renderer
QgsRasterRenderer * renderer() override
Creates a new renderer, using the properties defined in the widget.
Definition: qgsrastercontourrendererwidget.cpp:63
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:40
QgsRasterContourRenderer
Raster renderer that generates contours on the fly for a source raster band.
Definition: qgsrastercontourrenderer.h:30
QgsRasterContourRenderer::setContourIndexSymbol
void setContourIndexSymbol(QgsLineSymbol *symbol)
Sets the symbol of index contour lines.
Definition: qgsrastercontourrenderer.cpp:241
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
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:87
qgsrastercontourrenderer.h
QgsRasterRendererWidget
Abstract base class for widgets which configure a QgsRasterRenderer.
Definition: qgsrasterrendererwidget.h:39
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:72
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:88
QgsRasterContourRendererWidget::QgsRasterContourRendererWidget
QgsRasterContourRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
Constructs the widget.
Definition: qgsrastercontourrendererwidget.cpp:22
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:257
qgslinesymbol.h