Skip to content

Commit

Permalink
Fix some 2.5D renderer issues
Browse files Browse the repository at this point in the history
 * Fixed height now works
 * Add some GUI elements to access the configuration options
  • Loading branch information
m-kuhn committed Jan 18, 2016
1 parent 911caaa commit 9a2f46e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/symbology-ng/qgs25drenderer.cpp
Expand Up @@ -84,7 +84,7 @@ Qgs25DRenderer::Qgs25DRenderer()
setShadowSpread( 4 );
setShadowColor( QColor( "#1111111" ) );

setHeight( "20" );
setHeight( QString( "20" ) );
setAngle( 40 );

QgsFeatureRequest::OrderBy orderBy;
Expand Down Expand Up @@ -122,7 +122,7 @@ QgsFeatureRendererV2* Qgs25DRenderer::create( QDomElement& element )
void Qgs25DRenderer::startRender( QgsRenderContext& context, const QgsFields& fields )
{
QgsExpressionContextScope* scope = new QgsExpressionContextScope( "2.5D Renderer" );
scope->setVariable( "qgis_25d_height", mHeight.field() );
scope->setVariable( "qgis_25d_height", mHeight.expressionOrField() );
scope->setVariable( "qgis_25d_angle", mAngle );
context.expressionContext().appendScope( scope );
mSymbol->startRender( context, &fields );
Expand Down Expand Up @@ -197,6 +197,16 @@ QgsOuterGlowEffect* Qgs25DRenderer::glowEffect() const
return static_cast<QgsOuterGlowEffect*>( mSymbol->symbolLayer( 0 )->paintEffect() );
}

bool Qgs25DRenderer::shadowEnabled() const
{
return glowEffect()->enabled();
}

void Qgs25DRenderer::setShadowEnabled( bool value )
{
glowEffect()->setEnabled( value );
}

QColor Qgs25DRenderer::shadowColor() const
{
return glowEffect()->color();
Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgs25drenderer.h
Expand Up @@ -107,6 +107,15 @@ class CORE_EXPORT Qgs25DRenderer : public QgsFeatureRendererV2
*/
static Qgs25DRenderer* convertFromRenderer( QgsFeatureRendererV2* renderer );

/**
* Is the shadow enabled
*/
bool shadowEnabled() const;
/**
* Enable or disable the shadow
*/
void setShadowEnabled( bool value );

private:

QgsFillSymbolLayerV2* roofLayer() const;
Expand Down
9 changes: 9 additions & 0 deletions src/gui/symbology-ng/qgs25drendererwidget.cpp
Expand Up @@ -46,11 +46,17 @@ Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer* layer, QgsStyleV2* s
mAngleWidget->setValue( mRenderer->angle() );
mWallColorButton->setColor( mRenderer->wallColor() );
mRoofColorButton->setColor( mRenderer->roofColor() );
mShadowColorButton->setColor( mRenderer->shadowColor() );
mShadowEnabledWidget->setEnabled( mRenderer->shadowEnabled() );
mShadowSizeWidget->setValue( mRenderer->shadowSpread() );

connect( mAngleWidget, SIGNAL( valueChanged( int ) ), this, SLOT( updateRenderer() ) );
connect( mHeightWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( updateRenderer() ) );
connect( mWallColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
connect( mRoofColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
connect( mShadowColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
connect( mShadowEnabledWidget, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
connect( mShadowSizeWidget, SIGNAL( valueChanged( double ) ), this, SLOT( updateRenderer() ) );
}

QgsFeatureRendererV2* Qgs25DRendererWidget::renderer()
Expand All @@ -64,6 +70,9 @@ void Qgs25DRendererWidget::updateRenderer()
mRenderer->setAngle( mAngleWidget->value() );
mRenderer->setRoofColor( mRoofColorButton->color() );
mRenderer->setWallColor( mWallColorButton->color() );
mRenderer->setShadowColor( mShadowColorButton->color() );
mRenderer->setShadowEnabled( mShadowEnabledWidget->isChecked() );
mRenderer->setShadowSpread( mShadowSizeWidget->value() );
}

QgsRendererV2Widget* Qgs25DRendererWidget::create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
Expand Down
36 changes: 36 additions & 0 deletions src/ui/symbollayer/qgs25drendererwidgetbase.ui
Expand Up @@ -62,6 +62,42 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="mShadowEnabledWidget">
<property name="title">
<string>Shadow</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mShadowColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mShadowSizeWidget"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

13 comments on commit 9a2f46e

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn fantastic, the shadow options are great.

Allow me to drop in a last suggestion: allow for data-defined color settings. It's a very important implementation detail that IMO should be in when the feature is released to make sure the symbology isn't a "one trick pony" ;)

With data-defined colors, users will be able to do color highlight of feature(s). Thinking for e.g. of a building layer rendered with the 2.5D symbology, with one or two buildings colored differently to highlight them.

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are a lot of interesting options left.

One thing: you can convert this to any other renderer and you will have full control. (Still need to promote the variables to layer variables manually though)
So adding it here would be nice, but everything is only a shorthand for features achievable otherwise.

One question for you, @nirvn, do you know what needs to be changed to make classification work after converting it to such a renderer? Some locking, unlocking of symbols? where?

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn , yeah I noticed that switching to single symbol kept the individual layers, and bumped into the @variable issue :) On that point, would it not be better for the 2.5d symbology code to set the variables as layer variables (instead of being created at rendering time)? That way, you could switch back to simple symbol and have it working instantaneously without requiring to manually edit half a dozen data-defined expressions.

If that can be fixed, then I'd be happy to go down that road to highlight individual features / buildings :)

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn teasing you as a transparent way to incite this:
cool-25d

😄

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable issue is on my todo list, no worries. But having more control from inside the configuration interface is definitely nice as well

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use this image for the visual changelog?

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn of course.

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirvn was the image above generated with layer variables or with editing the expression?

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn with layer variables which duplicates the variable set by the 2.5D symbology. IMO the symbology should set variables at the layer level so no editing is needed, as per our discussion.

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some strange ordering z-index issues which I wonder why they happen

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn I can share the full building footprint dataset I'm using here if you want to test things around.

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 9a2f46e Jan 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uster

Please sign in to comment.