QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
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
"
6
#include "
qgspointdisplacementrenderer.h
"
7
#include "
qgsvectorlayer.h
"
8
9
10
QgsMapHitTest::QgsMapHitTest
(
const
QgsMapSettings
& settings )
11
: mSettings( settings )
12
{
13
}
14
15
16
void
QgsMapHitTest::run
()
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
24
QgsRenderContext
context =
QgsRenderContext::fromMapSettings
(
mSettings
);
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
39
if
(
mSettings
.
hasCrsTransformEnabled
() )
40
{
41
context.
setCoordinateTransform
(
mSettings
.
layerTransform
( vl ) );
42
context.
setExtent
(
mSettings
.
outputExtentToLayerExtent
( vl,
mSettings
.
visibleExtent
() ) );
43
}
44
45
SymbolV2Set
& usedSymbols =
mHitTest
[vl];
46
runHitTestLayer
( vl, usedSymbols, context );
47
}
48
49
painter.end();
50
}
51
52
53
void
QgsMapHitTest::runHitTestLayer
(
QgsVectorLayer
* vl,
SymbolV2Set
& usedSymbols,
QgsRenderContext
& context )
54
{
55
QgsFeatureRendererV2
* r = vl->
rendererV2
();
56
bool
moreSymbolsPerFeature = r->
capabilities
() &
QgsFeatureRendererV2::MoreSymbolsPerFeature
;
57
r->
startRender
( context, vl->
pendingFields
() );
58
QgsFeature
f;
59
QgsFeatureRequest
request( context.
extent
() );
60
request.
setFlags
(
QgsFeatureRequest::ExactIntersect
);
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
}
Generated on Sun May 10 2015 16:33:24 for QGIS API Documentation by
1.8.1.2