QGIS API Documentation  2.14.0-Essen
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  if ( renderer )
42  {
43  mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
44  }
45 
46  mHeightWidget->setLayer( layer );
47 
49  QVariant height = scope->variable( "qgis_25d_height" );
50  QVariant angle = scope->variable( "qgis_25d_angle" );
51  delete scope;
52 
53  mHeightWidget->setField( height.isNull() ? "10" : height.toString() );
54  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
55  mWallColorButton->setColor( mRenderer->wallColor() );
56  mRoofColorButton->setColor( mRenderer->roofColor() );
57  mShadowColorButton->setColor( mRenderer->shadowColor() );
58  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
59  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
60  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );
61 
62  connect( mAngleWidget, SIGNAL( valueChanged( int ) ), this, SLOT( updateRenderer() ) );
63  connect( mHeightWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( updateRenderer() ) );
64  connect( mWallColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
65  connect( mRoofColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
66  connect( mShadowColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
67  connect( mShadowEnabledWidget, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
68  connect( mShadowSizeWidget, SIGNAL( valueChanged( double ) ), this, SLOT( updateRenderer() ) );
69  connect( mWallExpositionShading, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
70 }
71 
73 {
74  return mRenderer;
75 }
76 
77 void Qgs25DRendererWidget::updateRenderer()
78 {
79  mRenderer->setRoofColor( mRoofColorButton->color() );
80  mRenderer->setWallColor( mWallColorButton->color() );
81  mRenderer->setShadowColor( mShadowColorButton->color() );
82  mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
83  mRenderer->setShadowSpread( mShadowSizeWidget->value() );
84  mRenderer->setWallShadingEnabled( mWallExpositionShading->isChecked() );
85 }
86 
87 void Qgs25DRendererWidget::apply()
88 {
89  QgsExpressionContextUtils::setLayerVariable( mLayer, "qgis_25d_height", mHeightWidget->currentText() );
90  QgsExpressionContextUtils::setLayerVariable( mLayer, "qgis_25d_angle", mAngleWidget->value() );
91 
92  emit layerVariablesChanged();
93 }
94 
96 {
97  return new Qgs25DRendererWidget( layer, style, renderer );
98 }
QLayout * layout() const
QColor shadowColor() const
Get the shadow's color.
void setupUi(QWidget *widget)
bool wallShadingEnabled()
Get wall shading enabled.
QString name() const
Get the display name of the layer.
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)
QColor wallColor() const
Get the wall color.
QgsVectorLayer * mLayer
bool isNull() const
void setShadowSpread(double shadowSpread)
Set the shadow&#39;s spread distance in map units.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
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 layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed...
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.
QColor roofColor() const
Get the roof color.
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.
Base class for renderer settings widgets.
double toDouble(bool *ok) const
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.
double shadowSpread() const
Get the shadow&#39;s spread distance in map units.
bool shadowEnabled() const
Is the shadow enabled.
int height() const