Skip to content
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 c45bf50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
@@ -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.



<!-- 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 )

0 comments on commit c45bf50

Please sign in to comment.