Skip to content

Commit 85eebff

Browse files
committedDec 15, 2015
Avoid some unnecessary object conversion during point rendering
1 parent 4e18d54 commit 85eebff

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed
 

‎python/core/geometry/qgspointv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ class QgsPointV2: public QgsAbstractGeometryV2
134134
*/
135135
void setM( double m );
136136

137+
/** Returns the point as a QPointF.
138+
* @note added in QGIS 2.14
139+
*/
140+
QPointF toQPointF() const;
141+
137142
//implementation of inherited methods
138143
virtual QString geometryType() const;
139144
virtual int dimension() const;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class QgsSymbolV2
184184
QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers /Transfer/ ); // can't be instantiated
185185

186186
/**
187-
Creates a point in screen coordinates from a QgsPoint in map coordinates
187+
Creates a point in screen coordinates from a QgsPointV2 in map coordinates
188188
*/
189-
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPoint& point );
189+
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPointV2* point );
190190
/**
191191
* Creates a line string in screen coordinates from a wkb string in map
192192
* coordinates

‎src/core/geometry/qgspointv2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,9 @@ bool QgsPointV2::convertTo( QgsWKBTypes::Type type )
410410
}
411411
return false;
412412
}
413+
414+
415+
QPointF QgsPointV2::toQPointF() const
416+
{
417+
return QPointF( mX, mY );
418+
}

‎src/core/geometry/qgspointv2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
145145
*/
146146
void setM( double m ) { mM = m; }
147147

148+
/** Returns the point as a QPointF.
149+
* @note added in QGIS 2.14
150+
*/
151+
QPointF toQPointF() const;
152+
148153
//implementation of inherited methods
149154
virtual QString geometryType() const override { return "Point"; }
150155
virtual int dimension() const override { return 0; }

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgsdatadefined.h"
3333

3434
#include "qgsgeometry.h"
35+
#include "qgsmultipointv2.h"
3536
#include "qgswkbptr.h"
3637
#include "qgsgeometrycollectionv2.h"
3738
#include "qgsclipper.h"
@@ -693,7 +694,9 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
693694
break;
694695
}
695696

696-
_getPoint( pt, context, segmentizedGeometry->asPoint() );
697+
const QgsPointV2* point = static_cast< const QgsPointV2* >( segmentizedGeometry->geometry() );
698+
699+
_getPoint( pt, context, point );
697700
( static_cast<QgsMarkerSymbolV2*>( this ) )->renderPoint( pt, &feature, context, layer, selected );
698701

699702
if ( context.testFlag( QgsRenderContext::DrawSymbolBounds ) )
@@ -741,10 +744,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
741744
break;
742745
}
743746

744-
QgsMultiPoint multiPoint = segmentizedGeometry->asMultiPoint();
747+
QgsMultiPointV2* mp = static_cast< QgsMultiPointV2* >( segmentizedGeometry->geometry() );
745748

746-
Q_FOREACH ( const QgsPoint& point, multiPoint )
749+
for ( int i = 0; i < mp->numGeometries(); ++i )
747750
{
751+
const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
748752
_getPoint( pt, context, point );
749753
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( pt, &feature, context, layer, selected );
750754
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QMap>
2222
#include "qgsmapunitscale.h"
2323
#include "qgsgeometry.h"
24+
#include "qgspointv2.h"
2425

2526
class QColor;
2627
class QImage;
@@ -243,14 +244,21 @@ class CORE_EXPORT QgsSymbolV2
243244
QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers ); // can't be instantiated
244245

245246
/**
246-
* Creates a point in screen coordinates from a QgsPoint in map coordinates
247+
* Creates a point in screen coordinates from a QgsPointV2 in map coordinates
247248
*/
248-
static inline void _getPoint( QPointF& pt, QgsRenderContext& context, const QgsPoint& point )
249+
static inline void _getPoint( QPointF& pt, QgsRenderContext& context, const QgsPointV2* point )
249250
{
250251
if ( context.coordinateTransform() )
251-
pt = context.coordinateTransform()->transform( point ).toQPointF();
252+
{
253+
double x = point->x();
254+
double y = point->y();
255+
double z = 0.0;
256+
context.coordinateTransform()->transformInPlace( x, y, z );
257+
pt = QPointF( x, y );
258+
259+
}
252260
else
253-
pt = point.toQPointF();
261+
pt = point->toQPointF();
254262

255263
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
256264
}

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ void TestQgsGeometry::pointV2()
491491
QCOMPARE( p11.x(), 0.0 );
492492
QCOMPARE( p11.y(), 0.0 );
493493

494+
//toQPointF
495+
QgsPointV2 p11a( 5.0, 9.0 );
496+
QPointF result = p11a.toQPointF();
497+
QVERIFY( qgsDoubleNear( result.x(), 5.0 ) );
498+
QVERIFY( qgsDoubleNear( result.y(), 9.0 ) );
499+
494500
//to/from WKB
495501
QgsPointV2 p12( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
496502
int size = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.