QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgs25drendererwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs25drendererwidget.cpp - Qgs25DRendererWidget
3 
4  ---------------------
5  begin : 14.1.2016
6  copyright : (C) 2016 by mku
7  email : [your-email-here]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #include "qgs25drendererwidget.h"
17 #include "qgs25drenderer.h"
18 #include "qgsvectorlayer.h"
21 
23  : QgsRendererWidget( layer, style )
24 
25 {
26  if ( !layer )
27  return;
28 
29  // the renderer only applies to point vector layers
31  {
32  //setup blank dialog
33  QGridLayout *layout = new QGridLayout( this );
34  QLabel *label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
35  "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
36  .arg( layer->name() ), this );
37  layout->addWidget( label );
38  return;
39  }
40 
41  setupUi( this );
42  this->layout()->setContentsMargins( 0, 0, 0, 0 );
43 
44  mAngleWidget->setClearValue( 0 );
45  mWallColorButton->setColorDialogTitle( tr( "Select Wall Color" ) );
46  mWallColorButton->setAllowOpacity( true );
47  mWallColorButton->setContext( QStringLiteral( "symbology" ) );
48  mRoofColorButton->setColorDialogTitle( tr( "Select Roof Color" ) );
49  mRoofColorButton->setAllowOpacity( true );
50  mRoofColorButton->setContext( QStringLiteral( "symbology" ) );
51  mShadowColorButton->setColorDialogTitle( tr( "Select Shadow Color" ) );
52  mShadowColorButton->setAllowOpacity( true );
53  mShadowColorButton->setContext( QStringLiteral( "symbology" ) );
54 
55  if ( renderer )
56  {
58  }
59 
60  mHeightWidget->setLayer( layer );
61 
63  QVariant height = scope->variable( QStringLiteral( "qgis_25d_height" ) );
64  QVariant angle = scope->variable( QStringLiteral( "qgis_25d_angle" ) );
65  delete scope;
66 
67  mHeightWidget->setField( height.isNull() ? QStringLiteral( "10" ) : height.toString() );
68  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
69  mAngleWidget->setClearValue( 70 );
70  mWallColorButton->setColor( mRenderer->wallColor() );
71  mRoofColorButton->setColor( mRenderer->roofColor() );
72  mShadowColorButton->setColor( mRenderer->shadowColor() );
73  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
74  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
75  mShadowSizeWidget->setClearValue( 4 );
76  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
77 
78  connect( mAngleWidget, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
79  connect( mHeightWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) > ( &QgsFieldExpressionWidget::fieldChanged ), this, &Qgs25DRendererWidget::updateRenderer );
80  connect( mWallColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
81  connect( mRoofColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
82  connect( mShadowColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
83  connect( mShadowEnabledWidget, &QGroupBox::toggled, this, &Qgs25DRendererWidget::updateRenderer );
84  connect( mShadowSizeWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
85  connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
86 }
87 
89 {
90  return mRenderer;
91 }
92 
93 void Qgs25DRendererWidget::updateRenderer()
94 {
95  mRenderer->setRoofColor( mRoofColorButton->color() );
96  mRenderer->setWallColor( mWallColorButton->color() );
97  mRenderer->setShadowColor( mShadowColorButton->color() );
98  mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
99  mRenderer->setShadowSpread( mShadowSizeWidget->value() );
100  mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
101  emit widgetChanged();
102 }
103 
104 void Qgs25DRendererWidget::apply()
105 {
106  if ( mHeightWidget )
107  {
108  QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_height" ), mHeightWidget->currentText() );
109  QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_angle" ), mAngleWidget->value() );
110 
111  emit layerVariablesChanged();
112  }
113 }
114 
116 {
117  return new Qgs25DRendererWidget( layer, style, renderer );
118 }
Qgs25DRenderer::setShadowEnabled
void setShadowEnabled(bool value)
Enable or disable the shadow.
Definition: qgs25drenderer.cpp:214
Qgs25DRenderer::setShadowSpread
void setShadowSpread(double shadowSpread)
Set the shadow's spread distance in map units.
Definition: qgs25drenderer.cpp:234
qgsexpressioncontextutils.h
qgsmaplayerstylemanager.h
Qgs25DRenderer::setRoofColor
void setRoofColor(const QColor &roofColor)
Set the roof color.
Definition: qgs25drenderer.cpp:265
QgsRendererWidget::mLayer
QgsVectorLayer * mLayer
Definition: qgsrendererwidget.h:99
QgsExpressionContextUtils::layerScope
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Definition: qgsexpressioncontextutils.cpp:265
qgs25drendererwidget.h
Qgs25DRenderer::roofColor
QColor roofColor() const
Gets the roof color.
Definition: qgs25drenderer.cpp:260
Qgs25DRenderer::shadowSpread
double shadowSpread() const
Gets the shadow's spread distance in map units.
Definition: qgs25drenderer.cpp:229
QgsExpressionContextUtils::setLayerVariable
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
Definition: qgsexpressioncontextutils.cpp:322
Qgs25DRenderer::setWallColor
void setWallColor(const QColor &wallColor)
Set the wall color.
Definition: qgs25drenderer.cpp:244
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsColorButton::colorChanged
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
Qgs25DRendererWidget::Qgs25DRendererWidget
Qgs25DRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
Definition: qgs25drendererwidget.cpp:22
Qgs25DRenderer::shadowEnabled
bool shadowEnabled() const
Is the shadow enabled.
Definition: qgs25drenderer.cpp:209
QgsFieldExpressionWidget::fieldChanged
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
Qgs25DRenderer::wallShadingEnabled
bool wallShadingEnabled() const
Gets wall shading enabled.
Definition: qgs25drenderer.cpp:255
QgsPanelWidget::widgetChanged
void widgetChanged()
Emitted when the widget state changes.
Qgs25DRenderer::setShadowColor
void setShadowColor(const QColor &shadowColor)
Set the shadow's color.
Definition: qgs25drenderer.cpp:224
qgs25drenderer.h
Qgs25DRendererWidget::renderer
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
Definition: qgs25drendererwidget.cpp:88
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext.
Definition: qgsexpressioncontext.h:112
QgsRendererWidget
Base class for renderer settings widgets.
Definition: qgsrendererwidget.h:45
qgsvectorlayer.h
Qgs25DRenderer::wallColor
QColor wallColor() const
Gets the wall color.
Definition: qgs25drenderer.cpp:239
Qgs25DRenderer::convertFromRenderer
static Qgs25DRenderer * convertFromRenderer(QgsFeatureRenderer *renderer)
Try to convert from an existing renderer.
Definition: qgs25drenderer.cpp:271
QgsFeatureRenderer
Definition: qgsrenderer.h:103
QgsStyle
Definition: qgsstyle.h:160
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsExpressionContextScope::variable
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
Definition: qgsexpressioncontext.cpp:108
QgsRendererWidget::layerVariablesChanged
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed.
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:86
Qgs25DRenderer::setWallShadingEnabled
void setWallShadingEnabled(bool enabled)
Set wall shading enabled.
Definition: qgs25drenderer.cpp:250
Qgs25DRenderer::shadowColor
QColor shadowColor() const
Gets the shadow's color.
Definition: qgs25drenderer.cpp:219
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
QgsFieldExpressionWidget
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
Definition: qgsfieldexpressionwidget.h:47
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
Qgs25DRendererWidget::create
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
Definition: qgs25drendererwidget.cpp:115