QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgshillshaderendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgshillshaderendererwidget.cpp
3 ---------------------------------
4 begin : May 2016
5 copyright : (C) 2016 by Nathan Woodrow
6 email : woodrow dot nathan at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
20#include "moc_qgshillshaderendererwidget.cpp"
21#include "qgsrasterlayer.h"
25
27 : QgsRasterRendererWidget( layer, extent )
28{
29 setupUi( this );
30
31 mLightAngle->setMaximum( 90 );
32 mLightAzimuth->setMaximum( 360.00 );
33
34 mLightAngle->setValue( 45.00 );
35 mLightAngle->setClearValue( 45.0 );
36 mLightAzimuth->setValue( 315.00 );
37 mLightAzimuth->setClearValue( 315.00 );
38
39 // Update the dial correctly
40 mLightAzimuth_updated( 315.00 );
41 mZFactor->setValue( 1 );
42 mZFactor->setClearValue( 1 );
43
44 mMultiDirection->setChecked( false );
45 mBandsCombo->setLayer( mRasterLayer );
46
47 setFromRenderer( layer->renderer() );
48
49 connect( mLightAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
50 connect( mLightAzimuth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHillshadeRendererWidget::mLightAzimuth_updated );
51 connect( mLightAzimuthDial, &QAbstractSlider::valueChanged, this, &QgsHillshadeRendererWidget::mLightAzimuthDial_updated );
52 connect( mZFactor, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
53 connect( mMultiDirection, &QAbstractButton::toggled, this, &QgsRasterRendererWidget::widgetChanged );
55}
56
58{
59 if ( !mRasterLayer )
60 {
61 return nullptr;
62 }
63
65 if ( !provider )
66 {
67 return nullptr;
68 }
69
70 const int band = mBandsCombo->currentBand();
71 QgsHillshadeRenderer *renderer = new QgsHillshadeRenderer( provider, band, mLightAzimuth->value(), mLightAngle->value() );
72 const double value = mZFactor->value();
73 renderer->setZFactor( value );
74 renderer->setMultiDirectional( mMultiDirection->checkState() );
75 return renderer;
76}
77
79{
80 const QgsHillshadeRenderer *r = dynamic_cast<const QgsHillshadeRenderer *>( renderer );
81 if ( r )
82 {
83 mBandsCombo->setBand( r->inputBand() );
84 mLightAngle->setValue( r->altitude() );
85 mLightAzimuth->setValue( r->azimuth() );
86 mZFactor->setValue( r->zFactor() );
87 mMultiDirection->setChecked( r->multiDirectional() );
88 }
89}
90
92{
93 mLightAngle->setValue( altitude );
94}
95
97{
98 mLightAzimuth->setValue( azimuth );
99}
100
102{
103 mZFactor->setValue( zfactor );
104}
105
107{
108 mMultiDirection->setChecked( isMultiDirectional );
109}
110
111void QgsHillshadeRendererWidget::mLightAzimuth_updated( double value )
112{
113 int newvalue = static_cast<int>( value ) - 180;
114 if ( newvalue < 0 )
115 newvalue += 360;
116 whileBlocking( mLightAzimuthDial )->setValue( newvalue );
117 emit widgetChanged();
118}
119
120void QgsHillshadeRendererWidget::mLightAzimuthDial_updated( int value )
121{
122 int newvalue = static_cast<int>( value ) + 180;
123 if ( newvalue > 360 )
124 newvalue -= 360;
125 whileBlocking( mLightAzimuth )->setValue( newvalue );
126 emit widgetChanged();
127}
128
130{
131 return mLightAzimuth->value();
132}
133
135{
136 return mLightAngle->value();
137}
138
140{
141 return mZFactor->value();
142}
143
145{
146 return mMultiDirection->isChecked();
147}
QgsRasterRenderer * renderer() override
Creates a new renderer, using the properties defined in the widget.
double zFactor() const
Returns the Z scaling factor.
void setAzimuth(double azimuth)
Set the azimuth of the light source.
QgsHillshadeRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
Renderer widget for the hill shade renderer.
bool multiDirectional() const
Returns true if the renderer should use the multi-directional hillshade algorithm.
void setAltitude(double altitude)
Set the altitude of the light source.
double azimuth() const
Returns the direction of the light over the raster between 0-360.
void setFromRenderer(const QgsRasterRenderer *renderer)
Set the widget state from the given renderer.
void setZFactor(double zfactor)
Set the Z scaling factor of the result image.
double altitude() const
Returns the angle of the light source over the raster.
void setMultiDirectional(bool isMultiDirectional)
Sets whether to render using a multi-directional hillshade algorithm.
A renderer for generating live hillshade models.
bool multiDirectional() const
Returns true if the renderer is using multi-directional hillshading.
double azimuth() const
Returns the direction of the light over the raster between 0-360.
Q_DECL_DEPRECATED void setBand(int bandNo)
Sets the band used by the renderer.
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
double altitude() const
Returns the angle of the light source over the raster.
double zFactor() const
Returns the Z scaling factor.
void bandChanged(int band)
Emitted when the currently selected band changes.
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.
A rectangle specified with double values.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5821