00001
00002 #include "qgssymbollayerv2.h"
00003
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
00040
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 QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
00049 {
00050 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
00051 startRender( context );
00052 renderPolygon( poly, NULL, context );
00053 stopRender( context );
00054 }
00055
00056 void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings )
00057 {
00058 if ( !p )
00059 {
00060 return;
00061 }
00062
00063 if ( rings == NULL )
00064 {
00065
00066 p->drawPolygon( points );
00067 }
00068 else
00069 {
00070
00071 QPainterPath path;
00072 path.addPolygon( points );
00073 QList<QPolygonF>::const_iterator it = rings->constBegin();
00074 for ( ; it != rings->constEnd(); ++it )
00075 {
00076 path.addPolygon( *it );
00077 }
00078
00079 p->drawPath( path );
00080 }
00081 }