QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Go to the documentation of this file.
1 #include "qgsmaphittest.h"
3 #include "qgsmaplayerregistry.h"
4 #include "qgsrendercontext.h"
5 #include "qgsrendererv2.h"
7 #include "qgsvectorlayer.h"
11  : mSettings( settings )
12 {
13 }
17 {
18  // TODO: do we need this temp image?
20  tmpImage.setDotsPerMeterX( mSettings.outputDpi() * 25.4 );
21  tmpImage.setDotsPerMeterY( mSettings.outputDpi() * 25.4 );
22  QPainter painter( &tmpImage );
25  context.setPainter( &painter ); // we are not going to draw anything, but we still need a working painter
27  foreach ( QString layerID, mSettings.layers() )
28  {
29  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) );
30  if ( !vl || !vl->rendererV2() )
31  continue;
33  if ( vl->hasScaleBasedVisibility() && ( mSettings.scale() < vl->minimumScale() || mSettings.scale() > vl->maximumScale() ) )
34  {
35  mHitTest[vl] = SymbolV2Set(); // no symbols -> will not be shown
36  continue;
37  }
40  {
43  }
45  SymbolV2Set& usedSymbols = mHitTest[vl];
46  runHitTestLayer( vl, usedSymbols, context );
47  }
49  painter.end();
50 }
54 {
56  bool moreSymbolsPerFeature = r->capabilities() & QgsFeatureRendererV2::MoreSymbolsPerFeature;
57  r->startRender( context, vl->pendingFields() );
58  QgsFeature f;
59  QgsFeatureRequest request( context.extent() );
61  QgsFeatureIterator fi = vl->getFeatures( request );
62  while ( fi.nextFeature( f ) )
63  {
64  if ( moreSymbolsPerFeature )
65  {
66  foreach ( QgsSymbolV2* s, r->originalSymbolsForFeature( f ) )
67  usedSymbols.insert( s );
68  }
69  else
70  usedSymbols.insert( r->originalSymbolForFeature( f ) );
71  }
72  r->stopRender( context );
73 }
HitTest mHitTest
Definition: qgsmaphittest.h:35
Wrapper for iterator of features from vector data provider or vector layer.
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
void setDotsPerMeterX(int x)
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:96
bool end()
double scale() const
Return the calculated scale of the map.
Use exact geometry intersection (slower) instead of bounding boxes.
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
QSet< QgsSymbolV2 * > SymbolV2Set
Definition: qgsmaphittest.h:29
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
const QgsRectangle & extent() const
const_iterator insert(const T &value)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
void setExtent(const QgsRectangle &extent)
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
The QgsMapSettings class contains configuration for rendering of the map.
virtual void stopRender(QgsRenderContext &context)=0
void setCoordinateTransform(const QgsCoordinateTransform *t)
Sets coordinate transformation.
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
int outputDpi() const
Return DPI used for conversion between real world units (e.g.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QSize outputSize() const
Return the size of the resulting map image.
float maximumScale() const
Returns the maximum scale denominator at which the layer is visible.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setPainter(QPainter *p)
void runHitTestLayer(QgsVectorLayer *vl, SymbolV2Set &usedSymbols, QgsRenderContext &context)
QgsMapHitTest(const QgsMapSettings &settings)
Contains information about the context of a rendering operation.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
Represents a vector layer which manages a vector based data sets.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
QgsMapSettings mSettings
Definition: qgsmaphittest.h:34