QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
24#include "qgsrasterlayer.h"
25
26#include "moc_qgshillshaderendererwidget.cpp"
27
29 : QgsRasterRendererWidget( layer, extent )
30{
31 setupUi( this );
32
33 mLightAngle->setMaximum( 90 );
34 mLightAzimuth->setMaximum( 360.00 );
35
36 mLightAngle->setValue( 45.00 );
37 mLightAngle->setClearValue( 45.0 );
38 mLightAzimuth->setValue( 315.00 );
39 mLightAzimuth->setClearValue( 315.00 );
40
41 // Update the dial correctly
42 mLightAzimuth_updated( 315.00 );
43 mZFactor->setValue( 1 );
44 mZFactor->setClearValue( 1 );
45
46 mMultiDirection->setChecked( false );
47 mBandsCombo->setLayer( mRasterLayer );
48
49 setFromRenderer( layer->renderer() );
50
51 connect( mLightAngle, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
52 connect( mLightAzimuth, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsHillshadeRendererWidget::mLightAzimuth_updated );
53 connect( mLightAzimuthDial, &QAbstractSlider::valueChanged, this, &QgsHillshadeRendererWidget::mLightAzimuthDial_updated );
54 connect( mZFactor, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterRendererWidget::widgetChanged );
55 connect( mMultiDirection, &QAbstractButton::toggled, this, &QgsRasterRendererWidget::widgetChanged );
57}
58
60{
61 if ( !mRasterLayer )
62 {
63 return nullptr;
64 }
65
66 QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
67 if ( !provider )
68 {
69 return nullptr;
70 }
71
72 const int band = mBandsCombo->currentBand();
73 QgsHillshadeRenderer *renderer = new QgsHillshadeRenderer( provider, band, mLightAzimuth->value(), mLightAngle->value() );
74 const double value = mZFactor->value();
75 renderer->setZFactor( value );
76 renderer->setMultiDirectional( mMultiDirection->checkState() );
77 return renderer;
78}
79
81{
82 const QgsHillshadeRenderer *r = dynamic_cast<const QgsHillshadeRenderer *>( renderer );
83 if ( r )
84 {
85 mBandsCombo->setBand( r->inputBand() );
86 mLightAngle->setValue( r->altitude() );
87 mLightAzimuth->setValue( r->azimuth() );
88 mZFactor->setValue( r->zFactor() );
89 mMultiDirection->setChecked( r->multiDirectional() );
90 }
91}
92
94{
95 mLightAngle->setValue( altitude );
96}
97
99{
100 mLightAzimuth->setValue( azimuth );
101}
102
104{
105 mZFactor->setValue( zfactor );
106}
107
109{
110 mMultiDirection->setChecked( isMultiDirectional );
111}
112
113void QgsHillshadeRendererWidget::mLightAzimuth_updated( double value )
114{
115 int newvalue = static_cast<int>( value ) - 180;
116 if ( newvalue < 0 )
117 newvalue += 360;
118 whileBlocking( mLightAzimuthDial )->setValue( newvalue );
119 emit widgetChanged();
120}
121
122void QgsHillshadeRendererWidget::mLightAzimuthDial_updated( int value )
123{
124 int newvalue = static_cast<int>( value ) + 180;
125 if ( newvalue > 360 )
126 newvalue -= 360;
127 whileBlocking( mLightAzimuth )->setValue( newvalue );
128 emit widgetChanged();
129}
130
132{
133 return mLightAzimuth->value();
134}
135
137{
138 return mLightAngle->value();
139}
140
142{
143 return mZFactor->value();
144}
145
147{
148 return mMultiDirection->isChecked();
149}
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.
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.
QgsRasterRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent)
Constructor for QgsRasterRendererWidget.
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:6511