QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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
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 }
70 if ( !provider )
71 {
72 return nullptr;
73 }
74
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}
@ Line
Line symbol.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
void bandChanged(int band)
Emitted when the currently selected band changes.
QgsRasterRenderer * renderer() override
Creates a new renderer, using the properties defined in the widget.
QgsRasterContourRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
Constructs the widget.
Raster renderer that generates contours on the fly for a source raster band.
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
QgsLineSymbol * contourIndexSymbol() const
Returns the symbol of index contour lines.
double downscale() const
Returns by how much the renderer will scale down the request to the data provider.
QgsLineSymbol * contourSymbol() const
Returns the symbol used for contour lines.
double contourInterval() const
Returns the interval of contour lines generation.
double contourIndexInterval() const
Returns the interval of index contour lines (index contour lines are typical further apart and with a...
Base class for raster data providers.
Represents a raster layer.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Abstract base class for widgets which configure a QgsRasterRenderer.
void widgetChanged()
Emitted when something on the widget has changed.
Raster renderer pipe that applies colors to a raster.
virtual bool setInputBand(int band)
Attempts to set the input band for the renderer.
A rectangle specified with double values.
void changed()
Emitted when the symbol's settings are changed.