QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
19 
21  : QgsRendererV2Widget( layer, style )
22  , mRenderer( nullptr )
23 {
24  if ( !layer )
25  return;
26 
27  // the renderer only applies to point vector layers
28  if ( layer->geometryType() != QGis::Polygon )
29  {
30  //setup blank dialog
31  QGridLayout* layout = new QGridLayout( this );
32  QLabel* label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
33  "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
34  .arg( layer->name() ), this );
35  layout->addWidget( label );
36  return;
37  }
38 
39  setupUi( this );
40 
41  mWallColorButton->setColorDialogTitle( tr( "Select wall color" ) );
42  mWallColorButton->setAllowAlpha( true );
43  mWallColorButton->setContext( "symbology" );
44  mRoofColorButton->setColorDialogTitle( tr( "Select roof color" ) );
45  mRoofColorButton->setAllowAlpha( true );
46  mRoofColorButton->setContext( "symbology" );
47  mShadowColorButton->setColorDialogTitle( tr( "Select shadow color" ) );
48  mShadowColorButton->setAllowAlpha( true );
49  mShadowColorButton->setContext( "symbology" );
50 
51  if ( renderer )
52  {
53  mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
54  }
55 
56  mHeightWidget->setLayer( layer );
57 
59  QVariant height = scope->variable( "qgis_25d_height" );
60  QVariant angle = scope->variable( "qgis_25d_angle" );
61  delete scope;
62 
63  mHeightWidget->setField( height.isNull() ? "10" : height.toString() );
64  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
65  mWallColorButton->setColor( mRenderer->wallColor() );
66  mRoofColorButton->setColor( mRenderer->roofColor() );
67  mShadowColorButton->setColor( mRenderer->shadowColor() );
68  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
69  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
70  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
71 
72  connect( mAngleWidget, SIGNAL( valueChanged( int ) ), this, SLOT( updateRenderer() ) );
73  connect( mHeightWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( updateRenderer() ) );
74  connect( mWallColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
75  connect( mRoofColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
76  connect( mShadowColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
77  connect( mShadowEnabledWidget, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
78  connect( mShadowSizeWidget, SIGNAL( valueChanged( double ) ), this, SLOT( updateRenderer() ) );
79  connect( mWallExpositionShading, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
80 }
81 
83 {
84  return mRenderer;
85 }
86 
87 void Qgs25DRendererWidget::updateRenderer()
88 {
89  mRenderer->setRoofColor( mRoofColorButton->color() );
90  mRenderer->setWallColor( mWallColorButton->color() );
91  mRenderer->setShadowColor( mShadowColorButton->color() );
92  mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
93  mRenderer->setShadowSpread( mShadowSizeWidget->value() );
94  mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
95  emit widgetChanged();
96 }
97 
98 void Qgs25DRendererWidget::apply()
99 {
100  if ( mHeightWidget )
101  {
102  QgsExpressionContextUtils::setLayerVariable( mLayer, "qgis_25d_height", mHeightWidget->currentText() );
103  QgsExpressionContextUtils::setLayerVariable( mLayer, "qgis_25d_angle", mAngleWidget->value() );
104 
105  emit layerVariablesChanged();
106  }
107 }
108 
110 {
111  return new Qgs25DRendererWidget( layer, style, renderer );
112 }
QLayout * layout() const
void setupUi(QWidget *widget)
bool wallShadingEnabled()
Get wall shading enabled.
QColor wallColor() const
Get the wall color.
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QStyle * style() const
static Qgs25DRenderer * convertFromRenderer(QgsFeatureRendererV2 *renderer)
Try to convert from an existing renderer.
QgsFeatureRendererV2 * renderer() override
return pointer to the renderer (no transfer of ownership)
Qgs25DRendererWidget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
Constructor.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool shadowEnabled() const
Is the shadow enabled.
QgsVectorLayer * mLayer
bool isNull() const
void setShadowSpread(double shadowSpread)
Set the shadow&#39;s spread distance in map units.
QColor shadowColor() const
Get the shadow&#39;s color.
QVariant variable(const QString &name) const
Retrieves a variable&#39;s value from the scope.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed...
void widgetChanged()
Emitted when the widget state changes.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QgsRendererV2Widget * create(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
Static creation method.
void setRoofColor(const QColor &roofColor)
Set the roof color.
void setShadowEnabled(bool value)
Enable or disable the shadow.
void setWallShadingEnabled(bool enabled)
Set wall shading enabled.
QColor roofColor() const
Get the roof color.
Base class for renderer settings widgets.
double toDouble(bool *ok) const
QString name
Read property of QString layerName.
Definition: qgsmaplayer.h:53
double shadowSpread() const
Get the shadow&#39;s spread distance in map units.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
void setShadowColor(const QColor &shadowColor)
Set the shadow&#39;s color.
QString toString() const
void setWallColor(const QColor &wallColor)
Set the wall color.
int height() const