Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgssymbollayerv2.cpp 00003 --------------------- 00004 begin : November 2009 00005 copyright : (C) 2009 by Martin Dobias 00006 email : wonder.sk at gmail.com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #include "qgssymbollayerv2.h" 00017 #include "qgsclipper.h" 00018 #include "qgsrenderer.h" 00019 #include "qgsrendercontext.h" 00020 00021 #include <QSize> 00022 #include <QPainter> 00023 #include <QPointF> 00024 #include <QPolygonF> 00025 00026 00027 00028 QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked ) 00029 : QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ) 00030 { 00031 } 00032 00033 QgsLineSymbolLayerV2::QgsLineSymbolLayerV2( bool locked ) 00034 : QgsSymbolLayerV2( QgsSymbolV2::Line, locked ) 00035 { 00036 } 00037 00038 QgsFillSymbolLayerV2::QgsFillSymbolLayerV2( bool locked ) 00039 : QgsSymbolLayerV2( QgsSymbolV2::Fill, locked ), mAngle( 0.0 ) 00040 { 00041 } 00042 00043 void QgsMarkerSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) 00044 { 00045 startRender( context ); 00046 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context ); 00047 stopRender( context ); 00048 } 00049 00050 void QgsLineSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) 00051 { 00052 QPolygonF points; 00053 // we're adding 0.5 to get rid of blurred preview: 00054 // drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line 00055 points << QPointF( 0, size.height() / 2 + 0.5 ) << QPointF( size.width(), size.height() / 2 + 0.5 ); 00056 00057 startRender( context ); 00058 renderPolyline( points, context ); 00059 stopRender( context ); 00060 } 00061 00062 void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) 00063 { 00064 renderPolyline( points, context ); 00065 if ( rings ) 00066 { 00067 foreach( const QPolygonF& ring, *rings ) 00068 renderPolyline( ring, context ); 00069 } 00070 } 00071 00072 00073 void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) 00074 { 00075 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) ); 00076 startRender( context ); 00077 renderPolygon( poly, NULL, context ); 00078 stopRender( context ); 00079 } 00080 00081 void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings ) 00082 { 00083 if ( !p ) 00084 { 00085 return; 00086 } 00087 00088 if ( rings == NULL ) 00089 { 00090 // simple polygon without holes 00091 p->drawPolygon( points ); 00092 } 00093 else 00094 { 00095 // polygon with holes must be drawn using painter path 00096 QPainterPath path; 00097 QPolygonF outerRing = points; 00098 path.addPolygon( outerRing ); 00099 00100 QList<QPolygonF>::const_iterator it = rings->constBegin(); 00101 for ( ; it != rings->constEnd(); ++it ) 00102 { 00103 QPolygonF ring = *it; 00104 path.addPolygon( ring ); 00105 } 00106 00107 p->drawPath( path ); 00108 } 00109 } 00110 00111 void QgsMarkerSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const 00112 { 00113 QDomElement symbolizerElem = doc.createElement( "se:PointSymbolizer" ); 00114 if ( !props.value( "uom", "" ).isEmpty() ) 00115 symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) ); 00116 element.appendChild( symbolizerElem ); 00117 00118 // <Geometry> 00119 QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom", "" ) ); 00120 00121 writeSldMarker( doc, symbolizerElem, props ); 00122 }