QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
18#include "qgs25drenderer.h"
20#include "qgssymbol.h"
21#include "qgsvectorlayer.h"
22
23#include "moc_qgs25drendererwidget.cpp"
24
26 : QgsRendererWidget( layer, style )
27
28{
29 if ( !layer )
30 return;
31
32 // the renderer only applies to polygon vector layers
34 {
35 //setup blank dialog
36 QGridLayout *layout = new QGridLayout( this );
37 QLabel *label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
38 "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
39 .arg( layer->name() ),
40 this );
41 layout->addWidget( label );
42 return;
43 }
44
45 setupUi( this );
46 this->layout()->setContentsMargins( 0, 0, 0, 0 );
47
48 mAngleWidget->setClearValue( 0 );
49 mWallColorButton->setColorDialogTitle( tr( "Select Wall Color" ) );
50 mWallColorButton->setAllowOpacity( true );
51 mWallColorButton->setContext( QStringLiteral( "symbology" ) );
52 mRoofColorButton->setColorDialogTitle( tr( "Select Roof Color" ) );
53 mRoofColorButton->setAllowOpacity( true );
54 mRoofColorButton->setContext( QStringLiteral( "symbology" ) );
55 mShadowColorButton->setColorDialogTitle( tr( "Select Shadow Color" ) );
56 mShadowColorButton->setAllowOpacity( true );
57 mShadowColorButton->setContext( QStringLiteral( "symbology" ) );
58
59 if ( renderer )
60 {
62 }
63
64 mHeightWidget->setLayer( layer );
65
67 const QVariant height = scope->variable( QStringLiteral( "qgis_25d_height" ) );
68 const QVariant angle = scope->variable( QStringLiteral( "qgis_25d_angle" ) );
69 delete scope;
70
71 mHeightWidget->setField( QgsVariantUtils::isNull( height ) ? QStringLiteral( "10" ) : height.toString() );
72 mAngleWidget->setValue( QgsVariantUtils::isNull( angle ) ? 70 : angle.toDouble() );
73 mAngleWidget->setClearValue( 70 );
74 mWallColorButton->setColor( mRenderer->wallColor() );
75 mRoofColorButton->setColor( mRenderer->roofColor() );
76 mShadowColorButton->setColor( mRenderer->shadowColor() );
77 mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
78 mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
79 mShadowSizeWidget->setClearValue( 4 );
80 mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
81
82 connect( mAngleWidget, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
83 connect( mHeightWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString & )>( &QgsFieldExpressionWidget::fieldChanged ), this, &Qgs25DRendererWidget::updateRenderer );
84 connect( mWallColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
85 connect( mRoofColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
86 connect( mShadowColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
87 connect( mShadowEnabledWidget, &QGroupBox::toggled, this, &Qgs25DRendererWidget::updateRenderer );
88 connect( mShadowSizeWidget, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
89 connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
90}
91
93
95{
96 return mRenderer.get();
97}
98
99void Qgs25DRendererWidget::updateRenderer()
100{
101 mRenderer->setRoofColor( mRoofColorButton->color() );
102 mRenderer->setWallColor( mWallColorButton->color() );
103 mRenderer->setShadowColor( mShadowColorButton->color() );
104 mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
105 mRenderer->setShadowSpread( mShadowSizeWidget->value() );
106 mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
107 emit widgetChanged();
108}
109
110void Qgs25DRendererWidget::apply()
111{
112 if ( mHeightWidget )
113 {
114 QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_height" ), mHeightWidget->currentText() );
115 QgsExpressionContextUtils::setLayerVariable( mLayer, QStringLiteral( "qgis_25d_angle" ), mAngleWidget->value() );
116
118 }
119}
120
@ Polygon
Polygons.
Definition qgis.h:361
~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.
A widget for selection of layer fields or expression creation.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
void widgetChanged()
Emitted when the widget state changes.
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed.
QgsRendererWidget(QgsVectorLayer *layer, QgsStyle *style)
QgsVectorLayer * mLayer
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
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 dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.