Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgssymbollayerv2.cpp
Go to the documentation of this file.
1 
2 #include "qgssymbollayerv2.h"
3 #include "qgsclipper.h"
4 #include "qgsrenderer.h"
5 #include "qgsrendercontext.h"
6 
7 #include <QSize>
8 #include <QPainter>
9 #include <QPointF>
10 #include <QPolygonF>
11 
12 
13 
15  : QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
16 {
17 }
18 
20  : QgsSymbolLayerV2( QgsSymbolV2::Line, locked )
21 {
22 }
23 
25  : QgsSymbolLayerV2( QgsSymbolV2::Fill, locked )
26 {
27 }
28 
30 {
31  startRender( context );
32  renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
33  stopRender( context );
34 }
35 
37 {
38  QPolygonF points;
39  // we're adding 0.5 to get rid of blurred preview:
40  // drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line
41  points << QPointF( 0, size.height() / 2 + 0.5 ) << QPointF( size.width(), size.height() / 2 + 0.5 );
42 
43  startRender( context );
44  renderPolyline( points, context );
45  stopRender( context );
46 }
47 
48 void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
49 {
50  renderPolyline( points, context );
51  if ( rings )
52  {
53  foreach( const QPolygonF& ring, *rings )
54  renderPolyline( ring, context );
55  }
56 }
57 
58 
60 {
61  QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
62  startRender( context );
63  renderPolygon( poly, NULL, context );
64  stopRender( context );
65 }
66 
67 void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings )
68 {
69  if ( !p )
70  {
71  return;
72  }
73 
74  if ( rings == NULL )
75  {
76  // simple polygon without holes
77  p->drawPolygon( points );
78  }
79  else
80  {
81  // polygon with holes must be drawn using painter path
82  QPainterPath path;
83  QPolygonF outerRing = points;
84  path.addPolygon( outerRing );
85 
86  QList<QPolygonF>::const_iterator it = rings->constBegin();
87  for ( ; it != rings->constEnd(); ++it )
88  {
89  QPolygonF ring = *it;
90  path.addPolygon( ring );
91  }
92 
93  p->drawPath( path );
94  }
95 }