QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgsrastercontourrendererwidget.cpp"
18
20#include "qgsrasterlayer.h"
21#include "qgslinesymbol.h"
22
24 : QgsRasterRendererWidget( layer, extent )
25{
26 setupUi( this );
27
28 mContourSymbolButton->setSymbolType( Qgis::SymbolType::Line );
29 mIndexContourSymbolButton->setSymbolType( Qgis::SymbolType::Line );
30
31 mInputBandComboBox->setLayer( mRasterLayer );
32
33 if ( !mRasterLayer )
34 {
35 return;
36 }
38 if ( !provider )
39 {
40 return;
41 }
42
43 const QgsRasterContourRenderer *rcr = dynamic_cast<const QgsRasterContourRenderer *>( mRasterLayer->renderer() );
44 if ( rcr )
45 {
46 mInputBandComboBox->setBand( rcr->inputBand() );
47 mContourIntervalSpinBox->setValue( rcr->contourInterval() );
48 mIndexContourIntervalSpinBox->setValue( rcr->contourIndexInterval() );
49 mDownscaleSpinBox->setValue( rcr->downscale() );
50 if ( rcr->contourSymbol() )
51 mContourSymbolButton->setSymbol( rcr->contourSymbol()->clone() );
52 if ( rcr->contourIndexSymbol() )
53 mIndexContourSymbolButton->setSymbol( rcr->contourIndexSymbol()->clone() );
54 }
55
57 connect( mContourIntervalSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
58 connect( mIndexContourIntervalSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
59 connect( mDownscaleSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
60 connect( mContourSymbolButton, &QgsSymbolButton::changed, this, &QgsRasterRendererWidget::widgetChanged );
61 connect( mIndexContourSymbolButton, &QgsSymbolButton::changed, this, &QgsRasterRendererWidget::widgetChanged );
62}
63
65{
66 if ( !mRasterLayer )
67 {
68 return nullptr;
69 }
71 if ( !provider )
72 {
73 return nullptr;
74 }
75
77 renderer->setInputBand( mInputBandComboBox->currentBand() );
78 renderer->setContourInterval( mContourIntervalSpinBox->value() );
79 renderer->setContourIndexInterval( mIndexContourIntervalSpinBox->value() );
80 renderer->setDownscale( mDownscaleSpinBox->value() );
81 renderer->setContourSymbol( mContourSymbolButton->clonedSymbol<QgsLineSymbol>() );
82 renderer->setContourIndexSymbol( mIndexContourSymbolButton->clonedSymbol<QgsLineSymbol>() );
83 return renderer;
84}
@ 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.