Skip to content

Commit c423d64

Browse files
committedDec 10, 2015
Reduce wkb parsing
1 parent 123a60e commit c423d64

File tree

3 files changed

+27
-52
lines changed

3 files changed

+27
-52
lines changed
 

‎python/core/symbology-ng/qgssymbolv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class QgsSymbolV2
187187
* Creates a point in screen coordinates from a wkb string in map
188188
* coordinates
189189
*/
190-
static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
190+
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPoint& point );
Code has comments. Press enter to view.
191191
/**
192192
* Creates a line string in screen coordinates from a wkb string in map
193193
* coordinates

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,6 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers )
104104
}
105105
}
106106

107-
const unsigned char* QgsSymbolV2::_getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb )
108-
{
109-
QgsConstWkbPtr wkbPtr( wkb + 1 );
110-
unsigned int wkbType;
111-
wkbPtr >> wkbType >> pt.rx() >> pt.ry();
112-
113-
if (( QgsWKBTypes::Type )wkbType == QgsWKBTypes::Point25D || ( QgsWKBTypes::Type )wkbType == QgsWKBTypes::PointZ )
114-
wkbPtr += sizeof( double );
115-
116-
if ( context.coordinateTransform() )
117-
{
118-
double z = 0; // dummy variable for coordiante transform
119-
context.coordinateTransform()->transformInPlace( pt.rx(), pt.ry(), z );
120-
}
121-
122-
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
123-
124-
return wkbPtr;
125-
}
126107

127108
const unsigned char* QgsSymbolV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
128109
{
@@ -690,26 +671,15 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
690671
context.setGeometry( geom->geometry() );
691672

692673
//convert curve types to normal point/line/polygon ones
693-
switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
674+
if ( geom->geometry()->hasCurvedSegments() )
694675
{
695-
case QgsWKBTypes::CurvePolygon:
696-
case QgsWKBTypes::CircularString:
697-
case QgsWKBTypes::CompoundCurve:
698-
case QgsWKBTypes::MultiSurface:
699-
case QgsWKBTypes::MultiCurve:
676+
QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
677+
if ( !g )
700678
{
701-
QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
702-
if ( !g )
703-
{
704-
return;
705-
}
706-
segmentizedGeometry = new QgsGeometry( g );
707-
deleteSegmentizedGeometry = true;
708-
break;
679+
return;
709680
}
710-
711-
default:
712-
break;
681+
segmentizedGeometry = new QgsGeometry( g );
682+
deleteSegmentizedGeometry = true;
713683
}
714684

715685
switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
@@ -722,8 +692,10 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
722692
QgsDebugMsg( "point can be drawn only with marker symbol!" );
723693
break;
724694
}
725-
_getPoint( pt, context, segmentizedGeometry->asWkb() );
695+
696+
_getPoint( pt, context, segmentizedGeometry->asPoint() );
726697
( static_cast<QgsMarkerSymbolV2*>( this ) )->renderPoint( pt, &feature, context, layer, selected );
698+
727699
if ( context.testFlag( QgsRenderContext::DrawSymbolBounds ) )
728700
{
729701
//draw debugging rect
@@ -769,14 +741,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
769741
break;
770742
}
771743

772-
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
773-
unsigned int num;
774-
wkbPtr >> num;
775-
const unsigned char* ptr = wkbPtr;
744+
QgsMultiPoint multiPoint = segmentizedGeometry->asMultiPoint();
776745

777-
for ( unsigned int i = 0; i < num; ++i )
746+
Q_FOREACH ( const QgsPoint& point, multiPoint )
778747
{
779-
ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
748+
_getPoint( pt, context, point );
780749
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( pt, &feature, context, layer, selected );
781750
}
782751
}
@@ -888,8 +857,7 @@ QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymb
888857
mSelected( selected ),
889858
mRenderHints( renderHints ),
890859
mFeature( f ),
891-
mFields( fields ),
892-
mExpressionContext( c.expressionContext() )
860+
mFields( fields )
893861
{
894862
}
895863

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QList>
2121
#include <QMap>
2222
#include "qgsmapunitscale.h"
23+
#include "qgsgeometry.h"
2324

2425
class QColor;
2526
class QImage;
@@ -242,15 +243,24 @@ class CORE_EXPORT QgsSymbolV2
242243
QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers ); // can't be instantiated
243244

244245
/**
245-
* Creates a point in screen coordinates from a wkb string in map
246-
* coordinates
246+
* Creates a point in screen coordinates from a QgsPoint in map coordinates
247247
*/
248-
static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
248+
static inline void _getPoint( QPointF& pt, QgsRenderContext& context, const QgsPoint& point )
249+
{
250+
if ( context.coordinateTransform() )
251+
pt = context.coordinateTransform()->transform( point ).toQPointF();
252+
else
253+
pt = point.toQPointF();
254+
255+
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
256+
}
257+
249258
/**
250259
* Creates a line string in screen coordinates from a wkb string in map
251260
* coordinates
252261
*/
253262
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
263+
254264
/**
255265
* Creates a polygon in screen coordinates from a wkb string in map
256266
* coordinates
@@ -303,8 +313,6 @@ class CORE_EXPORT QgsSymbolV2RenderContext
303313
QgsRenderContext& renderContext() { return mRenderContext; }
304314
const QgsRenderContext& renderContext() const { return mRenderContext; }
305315

306-
const QgsExpressionContext& expressionContext() const { return mExpressionContext; }
307-
308316
/** Sets the original value variable value for data defined symbology
309317
* @param value value for original value variable. This usually represents the symbol property value
310318
* before any data defined overrides have been applied.
@@ -354,7 +362,6 @@ class CORE_EXPORT QgsSymbolV2RenderContext
354362
int mRenderHints;
355363
const QgsFeature* mFeature; //current feature
356364
const QgsFields* mFields;
357-
QgsExpressionContext mExpressionContext;
358365
};
359366

360367

0 commit comments

Comments
 (0)
Please sign in to comment.