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.

This commit is contained in:
Nyall Dawson 2014-01-05 13:21:51 +11:00
parent 9a58828906
commit c45bf504e7
3 changed files with 23 additions and 0 deletions

View File

@ -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>

View File

@ -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 );

View File

@ -417,6 +417,9 @@ void QgsMapCanvas::refresh()
mDrawing = true;
//update $map variable to canvas
QgsExpression::setSpecialColumn( "$map", tr( "canvas" ) );
if ( mRenderFlag && !mFrozen )
{
clear();