QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaphittest.cpp
Go to the documentation of this file.
1 #include "qgsmaphittest.h"
2 
3 #include "qgsmaplayerregistry.h"
4 #include "qgsrendercontext.h"
5 #include "qgsrendererv2.h"
7 #include "qgsvectorlayer.h"
8 
9 
11  : mSettings( settings )
12 {
13 }
14 
15 
17 {
18  // TODO: do we need this temp image?
19  QImage tmpImage( mSettings.outputSize(), mSettings.outputImageFormat() );
20  tmpImage.setDotsPerMeterX( mSettings.outputDpi() * 25.4 );
21  tmpImage.setDotsPerMeterY( mSettings.outputDpi() * 25.4 );
22  QPainter painter( &tmpImage );
23 
25  context.setPainter( &painter ); // we are not going to draw anything, but we still need a working painter
26 
27  foreach ( QString layerID, mSettings.layers() )
28  {
29  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) );
30  if ( !vl || !vl->rendererV2() )
31  continue;
32 
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  }
38 
40  {
43  }
44 
45  SymbolV2Set& usedSymbols = mHitTest[vl];
46  runHitTestLayer( vl, usedSymbols, context );
47  }
48 
49  painter.end();
50 }
51 
52 
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 }