QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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"
20 
22  : QgsRendererWidget( layer, style )
23 
24 {
25  if ( !layer )
26  return;
27 
28  // the renderer only applies to point vector layers
30  {
31  //setup blank dialog
32  QGridLayout *layout = new QGridLayout( this );
33  QLabel *label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
34  "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
35  .arg( layer->name() ), this );
36  layout->addWidget( label );
37  return;
38  }
39 
40  setupUi( this );
41  this->layout()->setContentsMargins( 0, 0, 0, 0 );
42 
43  mAngleWidget->setClearValue( 0 );
44  mWallColorButton->setColorDialogTitle( tr( "Select Wall Color" ) );
45  mWallColorButton->setAllowOpacity( true );
46  mWallColorButton->setContext( QStringLiteral( "symbology" ) );
47  mRoofColorButton->setColorDialogTitle( tr( "Select Roof Color" ) );
48  mRoofColorButton->setAllowOpacity( true );
49  mRoofColorButton->setContext( QStringLiteral( "symbology" ) );
50  mShadowColorButton->setColorDialogTitle( tr( "Select Shadow Color" ) );
51  mShadowColorButton->setAllowOpacity( true );
52  mShadowColorButton->setContext( QStringLiteral( "symbology" ) );
53 
54  if ( renderer )
55  {
56  mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
57  }
58 
59  mHeightWidget->setLayer( layer );
60 
62  QVariant height = scope->variable( QStringLiteral( "qgis_25d_height" ) );
63  QVariant angle = scope->variable( QStringLiteral( "qgis_25d_angle" ) );
64  delete scope;
65 
66  mHeightWidget->setField( height.isNull() ? QStringLiteral( "10" ) : height.toString() );
67  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
68  mWallColorButton->setColor( mRenderer->wallColor() );
69  mRoofColorButton->setColor( mRenderer->roofColor() );
70  mShadowColorButton->setColor( mRenderer->shadowColor() );
71  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
72  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
73  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
74 
75  connect( mAngleWidget, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
76  connect( mHeightWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) > ( &QgsFieldExpressionWidget::fieldChanged ), this, &Qgs25DRendererWidget::updateRenderer );
77  connect( mWallColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
78  connect( mRoofColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
79  connect( mShadowColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
80  connect( mShadowEnabledWidget, &QGroupBox::toggled, this, &Qgs25DRendererWidget::updateRenderer );
81  connect( mShadowSizeWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
82  connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
83 }
84 
86 {
87  return mRenderer;
88 }
89 
90 void Qgs25DRendererWidget::updateRenderer()
91 {
92  mRenderer->setRoofColor( mRoofColorButton->color() );
93  mRenderer->setWallColor( mWallColorButton->color() );
94  mRenderer->setShadowColor( mShadowColorButton->color() );
95  mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
96  mRenderer->setShadowSpread( mShadowSizeWidget->value() );
97  mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
98  emit widgetChanged();
99 }
100 
101 void Qgs25DRendererWidget::apply()
102 {
103  if ( mHeightWidget )
104  {
105  QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_height" ), mHeightWidget->currentText() );
106  QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_angle" ), mAngleWidget->value() );
107 
108  emit layerVariablesChanged();
109  }
110 }
111 
113 {
114  return new Qgs25DRendererWidget( layer, style, renderer );
115 }
QColor shadowColor() const
Gets the shadow&#39;s color.
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
Base class for renderer settings widgets.
QgsVectorLayer * mLayer
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
QColor wallColor() const
Gets the wall color.
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
void setShadowSpread(double shadowSpread)
Set the shadow&#39;s spread distance in map units.
static Qgs25DRenderer * convertFromRenderer(QgsFeatureRenderer *renderer)
Try to convert from an existing renderer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QVariant variable(const QString &name) const
Retrieves a variable&#39;s value from the scope.
void widgetChanged()
Emitted when the widget state changes.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
void fieldChanged(const QString &fieldName)
the signal is emitted when the currently selected field changes
void colorChanged(const QColor &color)
Is emitted whenever a new color is set for the button.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
QColor roofColor() const
Gets the roof color.
void setRoofColor(const QColor &roofColor)
Set the roof color.
bool wallShadingEnabled() const
Gets wall shading enabled.
void setShadowEnabled(bool value)
Enable or disable the shadow.
void setWallShadingEnabled(bool enabled)
Set wall shading enabled.
QString name
Definition: qgsmaplayer.h:67
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Represents a vector layer which manages a vector based data sets.
void setShadowColor(const QColor &shadowColor)
Set the shadow&#39;s color.
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed...
Qgs25DRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
void setWallColor(const QColor &wallColor)
Set the wall color.
double shadowSpread() const
Gets the shadow&#39;s spread distance in map units.
bool shadowEnabled() const
Is the shadow enabled.