Quantum GIS API Documentation  1.7.4
src/core/symbology-ng/qgssymbollayerv2.cpp
Go to the documentation of this file.
00001 
00002 #include "qgssymbollayerv2.h"
00003 #include "qgsclipper.h"
00004 #include "qgsrenderer.h"
00005 #include "qgsrendercontext.h"
00006 
00007 #include <QSize>
00008 #include <QPainter>
00009 #include <QPointF>
00010 #include <QPolygonF>
00011 
00012 
00013 
00014 QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
00015     : QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
00016 {
00017 }
00018 
00019 QgsLineSymbolLayerV2::QgsLineSymbolLayerV2( bool locked )
00020     : QgsSymbolLayerV2( QgsSymbolV2::Line, locked )
00021 {
00022 }
00023 
00024 QgsFillSymbolLayerV2::QgsFillSymbolLayerV2( bool locked )
00025     : QgsSymbolLayerV2( QgsSymbolV2::Fill, locked )
00026 {
00027 }
00028 
00029 void QgsMarkerSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
00030 {
00031   startRender( context );
00032   renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
00033   stopRender( context );
00034 }
00035 
00036 void QgsLineSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
00037 {
00038   QPolygonF points;
00039   // we're adding 0.5 to get rid of blurred preview:
00040   // drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line
00041   points << QPointF( 0, size.height() / 2 + 0.5 ) << QPointF( size.width(), size.height() / 2 + 0.5 );
00042 
00043   startRender( context );
00044   renderPolyline( points, context );
00045   stopRender( context );
00046 }
00047 
00048 void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
00049 {
00050   renderPolyline( points, context );
00051   if ( rings )
00052   {
00053     foreach( const QPolygonF& ring, *rings )
00054     renderPolyline( ring, context );
00055   }
00056 }
00057 
00058 
00059 void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
00060 {
00061   QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
00062   startRender( context );
00063   renderPolygon( poly, NULL, context );
00064   stopRender( context );
00065 }
00066 
00067 void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings )
00068 {
00069   if ( !p )
00070   {
00071     return;
00072   }
00073 
00074   if ( rings == NULL )
00075   {
00076     // simple polygon without holes
00077     p->drawPolygon( points );
00078   }
00079   else
00080   {
00081     // polygon with holes must be drawn using painter path
00082     QPainterPath path;
00083     QPolygonF outerRing = points;
00084     path.addPolygon( outerRing );
00085 
00086     QList<QPolygonF>::const_iterator it = rings->constBegin();
00087     for ( ; it != rings->constEnd(); ++it )
00088     {
00089       QPolygonF ring = *it;
00090       path.addPolygon( ring );
00091     }
00092 
00093     p->drawPath( path );
00094   }
00095 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines