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