Skip to content
Permalink
Browse files

Implement $map variable, which returns the current composer map item …

…id where the map is being drawn, or 'canvas' if the map is being drawn in the main QGIS window. Partly implements #9288.
  • Loading branch information
nyalldawson committed Jan 5, 2014
1 parent 9a58828 commit c45bf504e761e568e1bc100eda0edc3e00213907
Showing with 23 additions and 0 deletions.
  1. +16 −0 resources/function_help/$map
  2. +4 −0 src/core/composer/qgscomposermap.cpp
  3. +3 −0 src/gui/qgsmapcanvas.cpp
@@ -0,0 +1,16 @@
<h3>$map function</h3>
Returns the id of the current map item if the map is being drawn in a composition, or "canvas" if the map is being
drawn within the main QGIS window.

<h4>Syntax</h4>
<pre>$map</pre>

<h4>Arguments</h4>
None

<h4>Example</h4>
<!-- Show example of function.-->
<pre>$map &rarr; "overview_map" (within a composer item)<br />
$map &rarr; "canvas" (within the main QGIS main canvas)</pre>


@@ -28,6 +28,7 @@
#include "qgsscalecalculator.h"
#include "qgsvectorlayer.h"
#include "qgspallabeling.h"
#include "qgsexpression.h"

#include "qgslabel.h"
#include "qgslabelattributes.h"
@@ -226,6 +227,9 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
bool bkLayerCaching = s.value( "/qgis/enable_render_caching", false ).toBool();
s.setValue( "/qgis/enable_render_caching", false );

//update $map variable. Use QgsComposerItem's id since that is user-definable
QgsExpression::setSpecialColumn( "$map", QgsComposerItem::id() );

if ( forceWidthScale ) //force wysiwyg line widths / marker sizes
{
theMapRenderer.render( painter, forceWidthScale );
@@ -417,6 +417,9 @@ void QgsMapCanvas::refresh()

mDrawing = true;

//update $map variable to canvas
QgsExpression::setSpecialColumn( "$map", tr( "canvas" ) );

if ( mRenderFlag && !mFrozen )
{
clear();

0 comments on commit c45bf50

Please sign in to comment.
You can’t perform that action at this time.