Skip to content

Commit

Permalink
When editing vector tile symbols, correctly populate the @zoom_level
Browse files Browse the repository at this point in the history
variable to match the current canvas zoom level

Makes it easier to write and debug data defined expressions based
on zoom level.
  • Loading branch information
nyalldawson committed Sep 9, 2020
1 parent 92c3a88 commit 5df98cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp
Expand Up @@ -396,6 +396,16 @@ void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &prox
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );

if ( mMapCanvas )
{
const int zoom = QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 );
QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
QgsExpressionContextScope tileScope;
tileScope.setVariable( "zoom_level", zoom, true );
scopes << tileScope;
context.setAdditionalExpressionContextScopes( scopes );
}

QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
Expand Down
10 changes: 10 additions & 0 deletions src/gui/vectortile/qgsvectortilebasicrendererwidget.cpp
Expand Up @@ -410,6 +410,16 @@ void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &prox
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );

if ( mMapCanvas )
{
const int zoom = QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 );
QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
QgsExpressionContextScope tileScope;
tileScope.setVariable( "zoom_level", zoom, true );
scopes << tileScope;
context.setAdditionalExpressionContextScopes( scopes );
}

QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
Expand Down

0 comments on commit 5df98cf

Please sign in to comment.