[QGIS Commit] r12756 - in trunk/qgis: python/core src/core/symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jan 14 12:50:47 EST 2010


Author: wonder
Date: 2010-01-14 12:50:44 -0500 (Thu, 14 Jan 2010)
New Revision: 12756

Modified:
   trunk/qgis/python/core/symbology-ng-core.sip
   trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
   trunk/qgis/src/core/symbology-ng/qgslinesymbollayerv2.cpp
   trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
   trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
   trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
   trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
   trunk/qgis/src/core/symbology-ng/qgssymbolv2.h
Log:
QgsSymbolV2RenderContext:
- use reference to QgsRenderContext instead of pointer
- added utility functions for simpler syntax when converting values to output units


Modified: trunk/qgis/python/core/symbology-ng-core.sip
===================================================================
--- trunk/qgis/python/core/symbology-ng-core.sip	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/python/core/symbology-ng-core.sip	2010-01-14 17:50:44 UTC (rev 12756)
@@ -444,14 +444,17 @@
 %End
 
     public:
-    QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u);
+    QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u);
     ~QgsSymbolV2RenderContext();
 
-    QgsRenderContext* renderContext();
-    void setRenderContext( QgsRenderContext* c );
+    QgsRenderContext& renderContext();
+    //void setRenderContext( QgsRenderContext* c );
 
     QgsSymbolV2::OutputUnit outputUnit() const;
     void setOutputUnit( QgsSymbolV2::OutputUnit u );
+
+    double outputLineWidth(double width) const;
+    double outputPixelSize(double size) const;
 };
 
 ///////////////
@@ -605,6 +608,10 @@
 
 //////////
 
+//typedef QgsSymbolLayerV2 * ( * QgsSymbolLayerV2CreateFunc )( const QgsStringMap& );
+//typedef QgsSymbolLayerV2Widget*( *QgsSymbolLayerV2WidgetFunc )();
+
+
 class QgsSymbolLayerV2Metadata
 {
 %TypeHeaderCode
@@ -623,8 +630,8 @@
 
   QString name() const;
   QgsSymbolV2::SymbolType type();
-  // TODO QgsSymbolLayerV2CreateFunc createFunction() const { return mCreateFunc; }
-  // TODO QgsSymbolLayerV2WidgetFunc widgetFunction() const { return mWidgetFunc; }
+  // TODO QgsSymbolLayerV2CreateFunc createFunction() const;
+  // TODO QgsSymbolLayerV2WidgetFunc widgetFunction() const;
 
 };
 

Modified: trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp	2010-01-14 17:50:44 UTC (rev 12756)
@@ -46,7 +46,7 @@
   mBrush = QBrush( mColor, mBrushStyle );
   mPen = QPen( mBorderColor );
   mPen.setStyle( mBorderStyle );
-  mPen.setWidthF( mBorderWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
+  mPen.setWidthF( context.outputLineWidth( mBorderWidth ) );
 }
 
 void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
@@ -55,12 +55,7 @@
 
 void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
 {
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
-  QPainter* p = rc->painter();
+  QPainter* p = context.renderContext().painter();
   if ( !p )
   {
     return;

Modified: trunk/qgis/src/core/symbology-ng/qgslinesymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgslinesymbollayerv2.cpp	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgslinesymbollayerv2.cpp	2010-01-14 17:50:44 UTC (rev 12756)
@@ -50,7 +50,7 @@
 void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
 {
   mPen.setColor( mColor );
-  mPen.setWidthF( mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
+  mPen.setWidthF( context.outputLineWidth( mWidth ) );
   mPen.setStyle( mPenStyle );
   mPen.setJoinStyle( mPenJoinStyle );
   mPen.setCapStyle( mPenCapStyle );
@@ -62,12 +62,7 @@
 
 void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
 {
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
-  QPainter* p = rc->painter();
+  QPainter* p = context.renderContext().painter();
   if ( !p )
   {
     return;
@@ -216,11 +211,7 @@
   // if being rotated, it gets initialized with every line segment
   if ( !mRotateMarker )
   {
-    QgsRenderContext* rc = context.renderContext();
-    if ( rc )
-    {
-      mMarker->startRender( *rc );
-    }
+    mMarker->startRender( context.renderContext() );
   }
 }
 
@@ -228,11 +219,7 @@
 {
   if ( !mRotateMarker )
   {
-    QgsRenderContext* rc = context.renderContext();
-    if ( rc )
-    {
-      mMarker->stopRender( *rc );
-    }
+    mMarker->stopRender( context.renderContext() );
   }
 }
 
@@ -244,7 +231,7 @@
   }
   else
   {
-    QPolygonF points2 = ::offsetLine( points, mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
+    QPolygonF points2 = ::offsetLine( points, context.outputLineWidth( mOffset ) );
     renderPolylineNoOffset( points2, context );
   }
 }
@@ -256,13 +243,9 @@
   bool first = true;
   double origAngle = mMarker->angle();
 
-  double painterUnitInterval = mInterval * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() );
+  double painterUnitInterval = context.outputLineWidth( mInterval );
 
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
+  QgsRenderContext& rc = context.renderContext();
 
   for ( int i = 1; i < points.count(); ++i )
   {
@@ -285,13 +268,13 @@
     if ( mRotateMarker )
     {
       mMarker->setAngle( origAngle + ( l.angle() * 180 / M_PI ) );
-      mMarker->startRender( *rc );
+      mMarker->startRender( rc );
     }
 
     // draw first marker
     if ( first )
     {
-      mMarker->renderPoint( lastPt, *rc );
+      mMarker->renderPoint( lastPt, rc );
       first = false;
     }
 
@@ -301,14 +284,14 @@
       // "c" is 1 for regular point or in interval (0,1] for begin of line segment
       lastPt += c * diff;
       lengthLeft -= painterUnitInterval;
-      mMarker->renderPoint( lastPt, *rc );
+      mMarker->renderPoint( lastPt, rc );
       c = 1; // reset c (if wasn't 1 already)
     }
 
     lastPt = pt;
 
     if ( mRotateMarker )
-      mMarker->stopRender( *rc );
+      mMarker->stopRender( rc );
   }
 
   // restore original rotation
@@ -404,12 +387,7 @@
 {
   // draw arrow at the end of line
 
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
-  QPainter* p = rc->painter();
+  QPainter* p = context.renderContext().painter();
   if ( !p )
   {
     return;

Modified: trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp	2010-01-14 17:50:44 UTC (rev 12756)
@@ -67,11 +67,11 @@
 {
   mBrush = QBrush( mColor );
   mPen = QPen( mBorderColor );
-  mPen.setWidthF( mPen.widthF() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ) );
+  mPen.setWidthF( context.outputLineWidth( mPen.widthF() ) );
 
   mPolygon.clear();
 
-  double scaledSize = mSize * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( context.renderContext(), context.outputUnit() );
+  double scaledSize = context.outputPixelSize( mSize );
   double half = scaledSize / 2.0;
 
   if ( mName == "rectangle" )
@@ -183,12 +183,8 @@
 
 void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
 {
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
-  QPainter* p = rc->painter();
+  QgsRenderContext& rc = context.renderContext();
+  QPainter* p = rc.painter();
   if ( !p )
   {
     return;
@@ -202,9 +198,9 @@
 
   //drawMarker(p);
   //mCache.save("/home/marco/tmp/marker.png", "PNG");
-  double s = mCache.width() / context.renderContext()->rasterScaleFactor();
-  p->drawImage( QRectF( point.x() - s / 2.0 + mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ), \
-                        point.y() - s / 2.0 + mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), context.outputUnit() ), \
+  double s = mCache.width() / context.renderContext().rasterScaleFactor();
+  p->drawImage( QRectF( context.outputLineWidth( point.x() - s / 2.0 + mOffset.x() ),
+                        context.outputLineWidth( point.y() - s / 2.0 + mOffset.y() ),
                         s, s ), mCache );
   //p->restore();
 }
@@ -237,7 +233,7 @@
   }
   else
   {
-    double scaledSize = mSize * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( context.renderContext(), context.outputUnit() );
+    double scaledSize = context.outputPixelSize( mSize );
     double half = scaledSize / 2.0;
     // TODO: rotate
 
@@ -300,21 +296,16 @@
 void QgsSvgMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
 {
   double pictureSize = 0;
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
+  QgsRenderContext& rc = context.renderContext();
 
-  if ( rc->painter() && rc->painter()->device() )
+  if ( rc.painter() && rc.painter()->device() )
   {
     //correct QPictures DPI correction
-    pictureSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() ) \
-                  / rc->painter()->device()->logicalDpiX() * mPicture.logicalDpiX();
+    pictureSize = context.outputLineWidth( mSize ) / rc.painter()->device()->logicalDpiX() * mPicture.logicalDpiX();
   }
   else
   {
-    pictureSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() );
+    pictureSize = context.outputLineWidth( mSize );
   }
   QRectF rect( QPointF( -pictureSize / 2.0, -pictureSize / 2.0 ), QSizeF( pictureSize, pictureSize ) );
   QSvgRenderer renderer( mPath );
@@ -329,19 +320,15 @@
 
 void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
 {
-  QgsRenderContext* rc = context.renderContext();
-  if ( !rc )
-  {
-    return;
-  }
-  QPainter* p = rc->painter();
+  QPainter* p = context.renderContext().painter();
   if ( !p )
   {
     return;
   }
 
   p->save();
-  p->translate( point + mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( rc, context.outputUnit() ) );
+  QPointF outputOffset = QPointF(context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
+  p->translate( point + outputOffset );
 
   if ( mAngle != 0 )
     p->rotate( mAngle );

Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-14 17:50:44 UTC (rev 12756)
@@ -175,7 +175,7 @@
   painter.eraseRect( QRect( QPoint( 0, 0 ), size ) );
   QgsRenderContext renderContext;
   renderContext.setPainter( &painter );
-  QgsSymbolV2RenderContext symbolContext( &renderContext, u );
+  QgsSymbolV2RenderContext symbolContext( renderContext, u );
   layer->drawPreviewIcon( symbolContext, size );
   painter.end();
   return QIcon( pixmap );
@@ -612,20 +612,16 @@
   return rampEl;
 }
 
-double QgsSymbolLayerV2Utils::lineWidthScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u )
+double QgsSymbolLayerV2Utils::lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
 {
-  if ( !c )
-  {
-    return 1.0;
-  }
 
   if ( u == QgsSymbolV2::MM )
   {
-    return c->scaleFactor();
+    return c.scaleFactor();
   }
   else //QgsSymbol::MapUnit
   {
-    double mup = c->mapToPixel().mapUnitsPerPixel();
+    double mup = c.mapToPixel().mapUnitsPerPixel();
     if ( mup > 0 )
     {
       return 1.0 / mup;
@@ -637,19 +633,14 @@
   }
 }
 
-double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u )
+double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
 {
-  if ( !c )
-  {
-    return 1.0;
-  }
-
   if ( u == QgsSymbolV2::MM )
   {
-    return ( c->scaleFactor() * c->rasterScaleFactor() );
+    return ( c.scaleFactor() * c.rasterScaleFactor() );
   }
   else //QgsSymbol::MapUnit
   {
-    return c->rasterScaleFactor() / c->mapToPixel().mapUnitsPerPixel();
+    return c.rasterScaleFactor() / c.mapToPixel().mapUnitsPerPixel();
   }
 }

Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h	2010-01-14 17:50:44 UTC (rev 12756)
@@ -67,9 +67,9 @@
     static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
 
     /**Returns the line width scale factor depending on the unit and the paint device*/
-    static double lineWidthScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
+    static double lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
     /**Returns scale factor painter units -> pixel dimensions*/
-    static double pixelSizeScaleFactor( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
+    static double pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
 };
 
 class QPolygonF;

Modified: trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp	2010-01-14 17:50:44 UTC (rev 12756)
@@ -126,14 +126,14 @@
 
 void QgsSymbolV2::startRender( QgsRenderContext& context )
 {
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
     ( *it )->startRender( symbolContext );
 }
 
 void QgsSymbolV2::stopRender( QgsRenderContext& context )
 {
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
     ( *it )->stopRender( symbolContext );
 }
@@ -162,7 +162,7 @@
 {
   QgsRenderContext context;
   context.setPainter( painter );
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
   {
     ( *it )->drawPreviewIcon( symbolContext, size );
@@ -247,7 +247,8 @@
 
 ////////////////////
 
-QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u ): mRenderContext( c ), mOutputUnit( u )
+QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
+  : mRenderContext( c ), mOutputUnit( u )
 {
 
 }
@@ -257,7 +258,17 @@
 
 }
 
+double QgsSymbolV2RenderContext::outputLineWidth(double width) const
+{
+  return width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( mRenderContext, mOutputUnit );
+}
 
+double QgsSymbolV2RenderContext::outputPixelSize(double size) const
+{
+  return size * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( mRenderContext, mOutputUnit );
+}
+
+
 ///////////////////
 
 
@@ -323,7 +334,7 @@
 
 void QgsMarkerSymbolV2::renderPoint( const QPointF& point, QgsRenderContext& context, int layer )
 {
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   if ( layer != -1 )
   {
     if ( layer >= 0 && layer < mLayers.count() )
@@ -391,7 +402,7 @@
 
 void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer )
 {
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   if ( layer != -1 )
   {
     if ( layer >= 0 && layer < mLayers.count() )
@@ -426,7 +437,7 @@
 
 void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer )
 {
-  QgsSymbolV2RenderContext symbolContext( &context, mOutputUnit );
+  QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
   if ( layer != -1 )
   {
     if ( layer >= 0 && layer < mLayers.count() )

Modified: trunk/qgis/src/core/symbology-ng/qgssymbolv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbolv2.h	2010-01-14 16:18:13 UTC (rev 12755)
+++ trunk/qgis/src/core/symbology-ng/qgssymbolv2.h	2010-01-14 17:50:44 UTC (rev 12756)
@@ -97,17 +97,20 @@
 class CORE_EXPORT QgsSymbolV2RenderContext
 {
   public:
-    QgsSymbolV2RenderContext( QgsRenderContext* c, QgsSymbolV2::OutputUnit u );
+    QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
     ~QgsSymbolV2RenderContext();
 
-    QgsRenderContext* renderContext() { return mRenderContext; }
-    void setRenderContext( QgsRenderContext* c ) { mRenderContext = c;}
+    QgsRenderContext& renderContext() { return mRenderContext; }
+    //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
 
     QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
     void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
 
+    double outputLineWidth(double width) const;
+    double outputPixelSize(double size) const;
+
   private:
-    QgsRenderContext* mRenderContext;
+    QgsRenderContext& mRenderContext;
     QgsSymbolV2::OutputUnit mOutputUnit;
 };
 



More information about the QGIS-commit mailing list