[QGIS Commit] r14005 - in branches/threading-branch: python/core src/core/symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 4 07:13:52 EDT 2010


Author: wonder
Date: 2010-08-04 11:13:52 +0000 (Wed, 04 Aug 2010)
New Revision: 14005

Modified:
   branches/threading-branch/python/core/symbology-ng-core.sip
   branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
   branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.h
   branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.cpp
   branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.h
   branches/threading-branch/src/core/symbology-ng/qgsrendererv2.cpp
   branches/threading-branch/src/core/symbology-ng/qgsrendererv2.h
   branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.cpp
   branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.h
   branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.cpp
   branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.h
   branches/threading-branch/src/core/symbology-ng/qgssymbolv2.cpp
   branches/threading-branch/src/core/symbology-ng/qgssymbolv2.h
Log:
Use static array for coordinates of polylines and outer ring of polygons. QPolygonF versions of functions have been kept for convenience.


Modified: branches/threading-branch/python/core/symbology-ng-core.sip
===================================================================
--- branches/threading-branch/python/core/symbology-ng-core.sip	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/python/core/symbology-ng-core.sip	2010-08-04 11:13:52 UTC (rev 14005)
@@ -435,7 +435,8 @@
 %End
 
 public:
-  virtual void renderPolyline(const QPolygonF& points, QgsSymbolV2RenderContext& context) = 0;
+  virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+  virtual void renderPolyline( const QPointF* points /Array/, int numPoints /ArraySize/, QgsSymbolV2RenderContext& context ) = 0;
 
   void setWidth(double width);
   double width() const;
@@ -454,7 +455,8 @@
 %End
 
 public:
-  virtual void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context) = 0;
+  virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+  virtual void renderPolygon( const QPointF* points /Array/, int numPoints /ArraySize/, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
 
   void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);
 

Modified: branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -74,7 +74,7 @@
 {
 }
 
-void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
+void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
 {
   QPainter* p = context.renderContext().painter();
   if ( !p )
@@ -88,7 +88,7 @@
   if ( !mOffset.isNull() )
     p->translate( mOffset );
 
-  _renderPolygon( p, points, rings );
+  _renderPolygon( p, points, numPoints, rings );
 
   if ( !mOffset.isNull() )
     p->translate( -mOffset );
@@ -228,7 +228,7 @@
   }
 }
 
-void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
+void QgsSVGFillSymbolLayer::renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
 {
   QPainter* p = context.renderContext().painter();
   if ( !p )
@@ -241,13 +241,13 @@
     QColor selColor = context.selectionColor();
     if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
     p->setBrush( QBrush( selColor ) );
-    _renderPolygon( p, points, rings );
+    _renderPolygon( p, points, numPoints, rings );
   }
   p->setBrush( mBrush );
-  _renderPolygon( p, points, rings );
+  _renderPolygon( p, points, numPoints, rings );
   if ( mOutline )
   {
-    mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() );
+    mOutline->renderPolyline( points, numPoints, context.renderContext(), -1, selectFillBorder && context.selected() );
     if ( rings )
     {
       QList<QPolygonF>::const_iterator ringIt = rings->constBegin();

Modified: branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgsfillsymbollayerv2.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -34,7 +34,7 @@
 
     void stopRender( QgsSymbolV2RenderContext& context );
 
-    void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+    void renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
 
     QgsStringMap properties() const;
 
@@ -85,7 +85,7 @@
     void startRender( QgsSymbolV2RenderContext& context );
     void stopRender( QgsSymbolV2RenderContext& context );
 
-    void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+    void renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
 
     QgsStringMap properties() const;
 

Modified: branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -94,7 +94,8 @@
 {
 }
 
-void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
+
+void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context )
 {
   QPainter* p = context.renderContext().painter();
   if ( !p )
@@ -105,11 +106,11 @@
   p->setPen( context.selected() ? mSelPen : mPen );
   if ( mOffset == 0 )
   {
-    p->drawPolyline( points );
+    p->drawPolyline( points, numPoints );
   }
   else
   {
-    p->drawPolyline( ::offsetLine( points, mOffset ) );
+    p->drawPolyline( ::offsetLine( points, numPoints, mOffset ) );
   }
 }
 
@@ -261,20 +262,21 @@
   mMarker->stopRender( context.renderContext() );
 }
 
-void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
+
+void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context )
 {
   if ( mOffset == 0 )
   {
-    renderPolylineNoOffset( points, context );
+    renderPolylineNoOffset( points, numPoints, context );
   }
   else
   {
-    QPolygonF points2 = ::offsetLine( points, context.outputLineWidth( mOffset ) );
-    renderPolylineNoOffset( points2, context );
+    QPolygonF points2 = ::offsetLine( points, numPoints, context.outputLineWidth( mOffset ) );
+    renderPolylineNoOffset( points2.constData(), points2.size(), context );
   }
 }
 
-void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPolygonF& points, QgsSymbolV2RenderContext& context )
+void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context )
 {
   QPointF lastPt = points[0];
   double lengthLeft = 0; // how much is left until next marker
@@ -285,9 +287,9 @@
 
   QgsRenderContext& rc = context.renderContext();
 
-  for ( int i = 1; i < points.count(); ++i )
+  for ( int i = 1; i < numPoints; ++i )
   {
-    const QPointF& pt = points[i];
+    QPointF pt(points[i]);
 
     if ( lastPt == pt ) // must not be equal!
       continue;
@@ -432,7 +434,7 @@
     return atan( t ) + ( y2 >= y1 ? M_PI : 0 ); // atan is positive / negative
 }
 
-void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
+void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context )
 {
   // draw arrow at the end of line
 
@@ -442,9 +444,8 @@
     return;
   }
 
-  int cnt = points.count();
-  QPointF p1 = points.at( cnt - 2 );
-  QPointF p2 = points.at( cnt - 1 );
+  QPointF p1 = points[ numPoints - 2 ];
+  QPointF p2 = points[ numPoints - 1 ];
   double angle = _calculateAngle( p1.x(), p1.y(), p2.x(), p2.y() );
 
   double size = 6;

Modified: branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgslinesymbollayerv2.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -33,7 +33,7 @@
 
     void stopRender( QgsSymbolV2RenderContext& context );
 
-    void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+    void renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context );
 
     QgsStringMap properties() const;
 
@@ -97,7 +97,7 @@
 
     void stopRender( QgsSymbolV2RenderContext& context );
 
-    void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+    void renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context );
 
     QgsStringMap properties() const;
 
@@ -124,7 +124,7 @@
 
   protected:
 
-    void renderPolylineNoOffset( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+    void renderPolylineNoOffset( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context );
 
     bool mRotateMarker;
     double mInterval;
@@ -155,7 +155,7 @@
 
     void stopRender( QgsSymbolV2RenderContext& context );
 
-    void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+    void renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context );
 
     QgsStringMap properties() const;
 

Modified: branches/threading-branch/src/core/symbology-ng/qgsrendererv2.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgsrendererv2.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgsrendererv2.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -43,7 +43,7 @@
   return wkb;
 }
 
-unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, unsigned char* wkb )
+unsigned char* QgsFeatureRendererV2::getLineString( QgsRenderContext& context, unsigned char* wkb )
 {
   wkb++; // jump over endian info
   unsigned int wkbType = *(( int* ) wkb );
@@ -54,13 +54,19 @@
   bool hasZValue = ( wkbType == QGis::WKBLineString25D );
   double x, y;
 
-  pts.resize( nPoints );
+  if ( nPoints > mTmpPtsCapacity )
+  {
+    delete mTmpPts;
+    mTmpPts = new QPointF[nPoints];
+    mTmpPtsCapacity = nPoints;
+  }
 
+  mTmpPtsCount = nPoints;
+
   const QgsCoordinateTransform* ct = context.coordinateTransform();
   const QgsMapToPixel& mtp = context.mapToPixel();
   double z = 0; // dummy variable for coordiante transform
 
-  QPointF* data = pts.data();
   for ( unsigned int i = 0; i < nPoints; ++i )
   {
     x = *(( double * ) wkb );
@@ -76,14 +82,40 @@
       ct->transformInPlace( x, y, z );
     mtp.transformInPlace( x, y );
 
-    data[i] = QPointF( x, y );
+    mTmpPts[i] = QPointF( x, y );
+  }
 
+  return wkb;
+}
+
+static unsigned char* getLinearRing( QPointF* data, int nPoints, QgsRenderContext& context, unsigned char* wkb, bool hasZValue )
+{
+  double x, y;
+  double z = 0; // dummy variable for coordiante transform
+  const QgsCoordinateTransform* ct = context.coordinateTransform();
+  const QgsMapToPixel& mtp = context.mapToPixel();
+
+  // Extract the points from the WKB and store in a pair of vectors.
+  for ( unsigned int jdx = 0; jdx < nPoints; jdx++ )
+  {
+    x = *(( double * ) wkb ); wkb += sizeof( double );
+    y = *(( double * ) wkb ); wkb += sizeof( double );
+
+    // TODO: maybe to the transform at once (faster?)
+    if ( ct )
+      ct->transformInPlace( x, y, z );
+    mtp.transformInPlace( x, y );
+
+    data[jdx] = QPointF( x, y );
+
+    if ( hasZValue )
+      wkb += sizeof( double );
   }
 
   return wkb;
 }
 
-unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb )
+unsigned char* QgsFeatureRendererV2::getPolygon( QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb )
 {
   wkb++; // jump over endian info
   unsigned int wkbType = *(( int* ) wkb );
@@ -95,13 +127,8 @@
     return wkb;
 
   bool hasZValue = ( wkbType == QGis::WKBPolygon25D );
-  double x, y;
   holes.clear();
 
-  const QgsCoordinateTransform* ct = context.coordinateTransform();
-  const QgsMapToPixel& mtp = context.mapToPixel();
-  double z = 0; // dummy variable for coordiante transform
-
   for ( unsigned int idx = 0; idx < numRings; idx++ )
   {
     unsigned int nPoints = *(( int* )wkb );
@@ -113,8 +140,16 @@
     QPointF* data;
     if ( idx == 0 )
     {
-      pts.resize( nPoints );
-      data = pts.data();
+      // first ring: use temporary points array
+      if ( nPoints > mTmpPtsCapacity )
+      {
+        delete mTmpPts;
+        mTmpPts = new QPointF[nPoints];
+        mTmpPtsCapacity = nPoints;
+      }
+      mTmpPtsCount = nPoints;
+
+      data = mTmpPts;
     }
     else
     {
@@ -122,23 +157,7 @@
       data = holes.last().data();
     }
 
-    // Extract the points from the WKB and store in a pair of vectors.
-    for ( unsigned int jdx = 0; jdx < nPoints; jdx++ )
-    {
-      x = *(( double * ) wkb ); wkb += sizeof( double );
-      y = *(( double * ) wkb ); wkb += sizeof( double );
-
-      // TODO: maybe to the transform at once (faster?)
-      if ( ct )
-        ct->transformInPlace( x, y, z );
-      mtp.transformInPlace( x, y );
-
-      data[jdx] = QPointF( x, y );
-
-      if ( hasZValue )
-        wkb += sizeof( double );
-    }
-
+    wkb = getLinearRing(data, nPoints, context, wkb, hasZValue);
   }
 
   return wkb;
@@ -150,8 +169,16 @@
     mCurrentVertexMarkerType( QgsVectorLayer::Cross ),
     mCurrentVertexMarkerSize( 3 )
 {
+  mTmpPtsCapacity = 0;
+  mTmpPts = NULL;
+  mTmpPtsCount = 0;
 }
 
+QgsFeatureRendererV2::~QgsFeatureRendererV2()
+{
+  delete mTmpPts;
+}
+
 QgsFeatureRendererV2* QgsFeatureRendererV2::defaultRenderer( QGis::GeometryType geomType )
 {
   return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geomType ) );
@@ -194,11 +221,11 @@
         QgsDebugMsg( "linestring can be drawn only with line symbol!" );
         break;
       }
-      _getLineString( mTmpPoints, context, geom->asWkb() );
-      (( QgsLineSymbolV2* )symbol )->renderPolyline( mTmpPoints, context, layer, selected );
+      getLineString( context, geom->asWkb() );
+      (( QgsLineSymbolV2* )symbol )->renderPolyline( mTmpPts, mTmpPtsCount, context, layer, selected );
 
       if ( drawVertexMarker )
-        renderVertexMarkerPolyline( mTmpPoints, context );
+        renderVertexMarkerPolyline( mTmpPts, mTmpPtsCount, context );
     }
     break;
 
@@ -211,11 +238,11 @@
         break;
       }
 
-      _getPolygon( mTmpPoints, mTmpHoles, context, geom->asWkb() );
-      (( QgsFillSymbolV2* )symbol )->renderPolygon( mTmpPoints, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context, layer, selected );
+      getPolygon( mTmpHoles, context, geom->asWkb() );
+      (( QgsFillSymbolV2* )symbol )->renderPolygon( mTmpPts, mTmpPtsCount, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context, layer, selected );
 
       if ( drawVertexMarker )
-        renderVertexMarkerPolygon( mTmpPoints, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context );
+        renderVertexMarkerPolygon( mTmpPts, mTmpPtsCount, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context );
     }
     break;
 
@@ -259,11 +286,11 @@
 
       for ( unsigned int i = 0; i < num; ++i )
       {
-        ptr = _getLineString( mTmpPoints, context, ptr );
-        (( QgsLineSymbolV2* )symbol )->renderPolyline( mTmpPoints, context, layer, selected );
+        ptr = getLineString( context, ptr );
+        (( QgsLineSymbolV2* )symbol )->renderPolyline( mTmpPts, mTmpPtsCount, context, layer, selected );
 
         if ( drawVertexMarker )
-          renderVertexMarkerPolyline( mTmpPoints, context );
+          renderVertexMarkerPolyline( mTmpPts, mTmpPtsCount, context );
       }
     }
     break;
@@ -283,11 +310,11 @@
 
       for ( unsigned int i = 0; i < num; ++i )
       {
-        ptr = _getPolygon( mTmpPoints, mTmpHoles, context, ptr );
-        (( QgsFillSymbolV2* )symbol )->renderPolygon( mTmpPoints, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context, layer, selected );
+        ptr = getPolygon( mTmpHoles, context, ptr );
+        (( QgsFillSymbolV2* )symbol )->renderPolygon( mTmpPts, mTmpPtsCount, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context, layer, selected );
 
         if ( drawVertexMarker )
-          renderVertexMarkerPolygon( mTmpPoints, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context );
+          renderVertexMarkerPolygon( mTmpPts, mTmpPtsCount, ( mTmpHoles.count() ? &mTmpHoles : NULL ), context );
       }
     }
     break;
@@ -347,30 +374,40 @@
   mCurrentVertexMarkerSize = size;
 }
 
-void QgsFeatureRendererV2::renderVertexMarker( QPointF& pt, QgsRenderContext& context )
+void QgsFeatureRendererV2::renderVertexMarker( const QPointF& pt, QgsRenderContext& context )
 {
   QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
                                     ( QgsVectorLayer::VertexMarkerType ) mCurrentVertexMarkerType,
                                     mCurrentVertexMarkerSize );
 }
 
-void QgsFeatureRendererV2::renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context )
+void QgsFeatureRendererV2::renderVertexMarkerPolyline( const QPolygonF& pts, QgsRenderContext& context )
 {
-  foreach( QPointF pt, pts )
-  renderVertexMarker( pt, context );
+  renderVertexMarkerPolyline( pts.constData(), pts.size(), context );
 }
 
-void QgsFeatureRendererV2::renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context )
+void QgsFeatureRendererV2::renderVertexMarkerPolyline( const QPointF* pts, int numPoints, QgsRenderContext& context )
 {
-  foreach( QPointF pt, pts )
-  renderVertexMarker( pt, context );
+  for (int i = 0; i < numPoints; i++)
+    renderVertexMarker( pts[i], context );
+}
 
+void QgsFeatureRendererV2::renderVertexMarkerPolygon( const QPolygonF& pts, const QList<QPolygonF>* rings, QgsRenderContext& context )
+{
+  renderVertexMarkerPolygon( pts.constData(), pts.size(), rings, context );
+}
+
+void QgsFeatureRendererV2::renderVertexMarkerPolygon( const QPointF* pts, int numPoints, const QList<QPolygonF>* rings, QgsRenderContext& context )
+{
+  for (int i = 0; i < numPoints; i++)
+    renderVertexMarker( pts[i], context );
+
   if ( rings )
   {
-    foreach( QPolygonF ring, *rings )
+    foreach( const QPolygonF& ring, *rings )
     {
-      foreach( QPointF pt, ring )
-      renderVertexMarker( pt, context );
+      foreach( const QPointF& pt, ring )
+        renderVertexMarker( pt, context );
     }
   }
 }

Modified: branches/threading-branch/src/core/symbology-ng/qgsrendererv2.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgsrendererv2.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgsrendererv2.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -69,7 +69,7 @@
 
     virtual QList<QString> usedAttributes() = 0;
 
-    virtual ~QgsFeatureRendererV2() {}
+    virtual ~QgsFeatureRendererV2();
 
     virtual QgsFeatureRendererV2* clone() = 0;
 
@@ -104,15 +104,19 @@
     QgsFeatureRendererV2( QString type );
 
     //! render editing vertex marker at specified point
-    void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
+    void renderVertexMarker( const QPointF& pt, QgsRenderContext& context );
     //! render editing vertex marker for a polyline
-    void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
+    void renderVertexMarkerPolyline( const QPolygonF& pts, QgsRenderContext& context );
+    void renderVertexMarkerPolyline( const QPointF* pts, int numPoints, QgsRenderContext& context );
     //! render editing vertex marker for a polygon
-    void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
+    void renderVertexMarkerPolygon( const QPolygonF& pts, const QList<QPolygonF>* rings, QgsRenderContext& context );
+    void renderVertexMarkerPolygon( const QPointF* pts, int numPoints, const QList<QPolygonF>* rings, QgsRenderContext& context );
 
     static unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, unsigned char* wkb );
-    static unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, unsigned char* wkb );
-    static unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb );
+    unsigned char* getLineString( QgsRenderContext& context, unsigned char* wkb );
+    //static unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, unsigned char* wkb );
+    unsigned char* getPolygon( QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb );
+    //static unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb );
 
     QString mType;
 
@@ -125,6 +129,10 @@
 
     QPolygonF mTmpPoints;
     QList<QPolygonF> mTmpHoles;
+
+    QPointF* mTmpPts;
+    int mTmpPtsCount;
+    int mTmpPtsCapacity;
 };
 
 

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -45,6 +45,12 @@
   stopRender( context );
 }
 
+void QgsLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
+{
+  renderPolyline( points.constData(), points.size(), context );
+}
+
+
 void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
 {
   QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
@@ -53,8 +59,18 @@
   stopRender( context );
 }
 
+void QgsFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
+{
+  renderPolygon( points.constData(), points.size(), rings, context );
+}
+
 void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings )
 {
+  _renderPolygon( p, points.constData(), points.size(), rings );
+}
+
+void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPointF* points, int numPoints, const QList<QPolygonF>* rings )
+{
   if ( !p )
   {
     return;
@@ -63,13 +79,16 @@
   if ( rings == NULL )
   {
     // simple polygon without holes
-    p->drawPolygon( points );
+    p->drawPolygon( points, numPoints );
   }
   else
   {
     // polygon with holes must be drawn using painter path
     QPainterPath path;
-    path.addPolygon( points );
+    QPolygonF outer_ring( numPoints );
+    memcpy( outer_ring.data(), points, sizeof(QPointF) * numPoints );
+    path.addPolygon( outer_ring );
+
     QList<QPolygonF>::const_iterator it = rings->constBegin();
     for ( ; it != rings->constEnd(); ++it )
     {

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -97,7 +97,8 @@
 class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
 {
   public:
-    virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
+    virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );
+    virtual void renderPolyline( const QPointF* points, int numPoints, QgsSymbolV2RenderContext& context ) = 0;
 
     virtual void setWidth( double width ) { mWidth = width; }
     virtual double width() const { return mWidth; }
@@ -113,7 +114,8 @@
 class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
 {
   public:
-    virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
+    virtual void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+    virtual void renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) = 0;
 
     void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
 
@@ -121,6 +123,7 @@
     QgsFillSymbolLayerV2( bool locked = false );
     /**Default method to render polygon*/
     void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings );
+    void _renderPolygon( QPainter* p, const QPointF* points, int numPoints, const QList<QPolygonF>* rings );
 };
 
 class QgsSymbolLayerV2Widget;

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -340,19 +340,24 @@
 
 QPolygonF offsetLine( QPolygonF polyline, double dist )
 {
+  return offsetLine( polyline.constData(), polyline.count(), dist );
+}
+
+QPolygonF offsetLine( const QPointF* points, int numPoints, double dist )
+{
   QPolygonF newLine;
 
-  if ( polyline.count() < 2 )
+  if ( numPoints < 2 )
     return newLine;
 
   double angle = 0.0, t_new, t_old = 0;
   QPointF pt_old, pt_new;
-  QPointF p1 = polyline[0], p2;
+  QPointF p1 = points[0], p2;
   bool first_point = true;
 
-  for ( int i = 1; i < polyline.count(); i++ )
+  for ( int i = 1; i < numPoints; i++ )
   {
-    p2 = polyline[i];
+    p2 = points[i];
 
     if ( !lineInfo( p1, p2, angle, t_new ) )
       continue; // not a line...

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -87,6 +87,7 @@
 
 //! calculate line shifted by a specified distance
 QPolygonF offsetLine( QPolygonF polyline, double dist );
+QPolygonF offsetLine( const QPointF* points, int numPoints, double dist );
 
 
 #endif

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbolv2.cpp
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbolv2.cpp	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbolv2.cpp	2010-08-04 11:13:52 UTC (rev 14005)
@@ -416,18 +416,23 @@
 
 void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer, bool selected )
 {
+  renderPolyline( points.constData(), points.size(), context, layer, selected );
+}
+
+void QgsLineSymbolV2::renderPolyline( const QPointF* points, int numPoints, QgsRenderContext& context, int layer, bool selected )
+{
   QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
   if ( layer != -1 )
   {
     if ( layer >= 0 && layer < mLayers.count() )
-      (( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolyline( points, symbolContext );
+      (( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolyline( points, numPoints, symbolContext );
     return;
   }
 
   for ( QgsSymbolLayerV2List::ConstIterator it = mLayers.constBegin(); it != mLayers.constEnd(); ++it )
   {
     QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
-    layer->renderPolyline( points, symbolContext );
+    layer->renderPolyline( points, numPoints, symbolContext );
   }
 }
 
@@ -452,18 +457,23 @@
 
 void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer, bool selected )
 {
+  renderPolygon( points.constData(), points.size(), rings, context, layer, selected );
+}
+
+void QgsFillSymbolV2::renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsRenderContext& context, int layer, bool selected )
+{
   QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
   if ( layer != -1 )
   {
     if ( layer >= 0 && layer < mLayers.count() )
-      (( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, symbolContext );
+      (( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, numPoints, rings, symbolContext );
     return;
   }
 
   for ( QgsSymbolLayerV2List::ConstIterator it = mLayers.constBegin(); it != mLayers.constEnd(); ++it )
   {
     QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
-    layer->renderPolygon( points, rings, symbolContext );
+    layer->renderPolygon( points, numPoints, rings, symbolContext );
   }
 }
 

Modified: branches/threading-branch/src/core/symbology-ng/qgssymbolv2.h
===================================================================
--- branches/threading-branch/src/core/symbology-ng/qgssymbolv2.h	2010-08-03 22:32:56 UTC (rev 14004)
+++ branches/threading-branch/src/core/symbology-ng/qgssymbolv2.h	2010-08-04 11:13:52 UTC (rev 14005)
@@ -177,7 +177,6 @@
 };
 
 
-
 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
 {
   public:
@@ -187,6 +186,7 @@
     double width();
 
     void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false );
+    void renderPolyline( const QPointF* points, int numPoints, QgsRenderContext& context, int layer = -1, bool selected = false );
 
     virtual QgsSymbolV2* clone() const;
 };
@@ -199,6 +199,7 @@
     QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
 
     void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
+    void renderPolygon( const QPointF* points, int numPoints, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
 
     virtual QgsSymbolV2* clone() const;
 };



More information about the QGIS-commit mailing list