QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 ***************************************************************************/
17#include "moc_qgs25drendererwidget.cpp"
18#include "qgs25drenderer.h"
19#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 polygon 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() ),
38 this );
39 layout->addWidget( label );
40 return;
41 }
42
43 setupUi( this );
44 this->layout()->setContentsMargins( 0, 0, 0, 0 );
45
46 mAngleWidget->setClearValue( 0 );
47 mWallColorButton->setColorDialogTitle( tr( "Select Wall Color" ) );
48 mWallColorButton->setAllowOpacity( true );
49 mWallColorButton->setContext( QStringLiteral( "symbology" ) );
50 mRoofColorButton->setColorDialogTitle( tr( "Select Roof Color" ) );
51 mRoofColorButton->setAllowOpacity( true );
52 mRoofColorButton->setContext( QStringLiteral( "symbology" ) );
53 mShadowColorButton->setColorDialogTitle( tr( "Select Shadow Color" ) );
54 mShadowColorButton->setAllowOpacity( true );
55 mShadowColorButton->setContext( QStringLiteral( "symbology" ) );
56
57 if ( renderer )
58 {
60 }
61
62 mHeightWidget->setLayer( layer );
63
65 const QVariant height = scope->variable( QStringLiteral( "qgis_25d_height" ) );
66 const QVariant angle = scope->variable( QStringLiteral( "qgis_25d_angle" ) );
67 delete scope;
68
69 mHeightWidget->setField( QgsVariantUtils::isNull( height ) ? QStringLiteral( "10" ) : height.toString() );
70 mAngleWidget->setValue( QgsVariantUtils::isNull( angle ) ? 70 : angle.toDouble() );
71 mAngleWidget->setClearValue( 70 );
72 mWallColorButton->setColor( mRenderer->wallColor() );
73 mRoofColorButton->setColor( mRenderer->roofColor() );
74 mShadowColorButton->setColor( mRenderer->shadowColor() );
75 mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
76 mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
77 mShadowSizeWidget->setClearValue( 4 );
78 mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
79
80 connect( mAngleWidget, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
81 connect( mHeightWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString & )>( &QgsFieldExpressionWidget::fieldChanged ), this, &Qgs25DRendererWidget::updateRenderer );
82 connect( mWallColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
83 connect( mRoofColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
84 connect( mShadowColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
85 connect( mShadowEnabledWidget, &QGroupBox::toggled, this, &Qgs25DRendererWidget::updateRenderer );
86 connect( mShadowSizeWidget, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
87 connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
88}
89
91
93{
94 return mRenderer.get();
95}
96
97void Qgs25DRendererWidget::updateRenderer()
98{
99 mRenderer->setRoofColor( mRoofColorButton->color() );
100 mRenderer->setWallColor( mWallColorButton->color() );
101 mRenderer->setShadowColor( mShadowColorButton->color() );
102 mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
103 mRenderer->setShadowSpread( mShadowSizeWidget->value() );
104 mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
105 emit widgetChanged();
106}
107
108void Qgs25DRendererWidget::apply()
109{
110 if ( mHeightWidget )
111 {
112 QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_height" ), mHeightWidget->currentText() );
113 QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_angle" ), mAngleWidget->value() );
114
116 }
117}
118
120{
121 return new Qgs25DRendererWidget( layer, style, renderer );
122}
@ Polygon
Polygons.
~Qgs25DRendererWidget() override
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
Qgs25DRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
static Qgs25DRenderer * convertFromRenderer(QgsFeatureRenderer *renderer)
Try to convert from an existing renderer.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Abstract base class for all 2D vector feature renderers.
The QgsFieldExpressionWidget class creates a widget to choose fields and edit expressions It contains...
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
QString name
Definition qgsmaplayer.h:80
void widgetChanged()
Emitted when the widget state changes.
Base class for renderer settings widgets.
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed.
QgsVectorLayer * mLayer
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.