mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Avoid some unnecessary object conversion during point rendering
This commit is contained in:
parent
4e18d54555
commit
85eebff69b
@ -134,6 +134,11 @@ class QgsPointV2: public QgsAbstractGeometryV2
|
||||
*/
|
||||
void setM( double m );
|
||||
|
||||
/** Returns the point as a QPointF.
|
||||
* @note added in QGIS 2.14
|
||||
*/
|
||||
QPointF toQPointF() const;
|
||||
|
||||
//implementation of inherited methods
|
||||
virtual QString geometryType() const;
|
||||
virtual int dimension() const;
|
||||
|
@ -184,9 +184,9 @@ class QgsSymbolV2
|
||||
QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers /Transfer/ ); // can't be instantiated
|
||||
|
||||
/**
|
||||
Creates a point in screen coordinates from a QgsPoint in map coordinates
|
||||
Creates a point in screen coordinates from a QgsPointV2 in map coordinates
|
||||
*/
|
||||
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPoint& point );
|
||||
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPointV2* point );
|
||||
/**
|
||||
* Creates a line string in screen coordinates from a wkb string in map
|
||||
* coordinates
|
||||
|
@ -410,3 +410,9 @@ bool QgsPointV2::convertTo( QgsWKBTypes::Type type )
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QPointF QgsPointV2::toQPointF() const
|
||||
{
|
||||
return QPointF( mX, mY );
|
||||
}
|
||||
|
@ -145,6 +145,11 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
|
||||
*/
|
||||
void setM( double m ) { mM = m; }
|
||||
|
||||
/** Returns the point as a QPointF.
|
||||
* @note added in QGIS 2.14
|
||||
*/
|
||||
QPointF toQPointF() const;
|
||||
|
||||
//implementation of inherited methods
|
||||
virtual QString geometryType() const override { return "Point"; }
|
||||
virtual int dimension() const override { return 0; }
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "qgsdatadefined.h"
|
||||
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgsmultipointv2.h"
|
||||
#include "qgswkbptr.h"
|
||||
#include "qgsgeometrycollectionv2.h"
|
||||
#include "qgsclipper.h"
|
||||
@ -693,7 +694,9 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
|
||||
break;
|
||||
}
|
||||
|
||||
_getPoint( pt, context, segmentizedGeometry->asPoint() );
|
||||
const QgsPointV2* point = static_cast< const QgsPointV2* >( segmentizedGeometry->geometry() );
|
||||
|
||||
_getPoint( pt, context, point );
|
||||
( static_cast<QgsMarkerSymbolV2*>( this ) )->renderPoint( pt, &feature, context, layer, selected );
|
||||
|
||||
if ( context.testFlag( QgsRenderContext::DrawSymbolBounds ) )
|
||||
@ -741,10 +744,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
|
||||
break;
|
||||
}
|
||||
|
||||
QgsMultiPoint multiPoint = segmentizedGeometry->asMultiPoint();
|
||||
QgsMultiPointV2* mp = static_cast< QgsMultiPointV2* >( segmentizedGeometry->geometry() );
|
||||
|
||||
Q_FOREACH ( const QgsPoint& point, multiPoint )
|
||||
for ( int i = 0; i < mp->numGeometries(); ++i )
|
||||
{
|
||||
const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
|
||||
_getPoint( pt, context, point );
|
||||
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( pt, &feature, context, layer, selected );
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QMap>
|
||||
#include "qgsmapunitscale.h"
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgspointv2.h"
|
||||
|
||||
class QColor;
|
||||
class QImage;
|
||||
@ -243,14 +244,21 @@ class CORE_EXPORT QgsSymbolV2
|
||||
QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers ); // can't be instantiated
|
||||
|
||||
/**
|
||||
* Creates a point in screen coordinates from a QgsPoint in map coordinates
|
||||
* Creates a point in screen coordinates from a QgsPointV2 in map coordinates
|
||||
*/
|
||||
static inline void _getPoint( QPointF& pt, QgsRenderContext& context, const QgsPoint& point )
|
||||
static inline void _getPoint( QPointF& pt, QgsRenderContext& context, const QgsPointV2* point )
|
||||
{
|
||||
if ( context.coordinateTransform() )
|
||||
pt = context.coordinateTransform()->transform( point ).toQPointF();
|
||||
{
|
||||
double x = point->x();
|
||||
double y = point->y();
|
||||
double z = 0.0;
|
||||
context.coordinateTransform()->transformInPlace( x, y, z );
|
||||
pt = QPointF( x, y );
|
||||
|
||||
}
|
||||
else
|
||||
pt = point.toQPointF();
|
||||
pt = point->toQPointF();
|
||||
|
||||
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
|
||||
}
|
||||
|
@ -491,6 +491,12 @@ void TestQgsGeometry::pointV2()
|
||||
QCOMPARE( p11.x(), 0.0 );
|
||||
QCOMPARE( p11.y(), 0.0 );
|
||||
|
||||
//toQPointF
|
||||
QgsPointV2 p11a( 5.0, 9.0 );
|
||||
QPointF result = p11a.toQPointF();
|
||||
QVERIFY( qgsDoubleNear( result.x(), 5.0 ) );
|
||||
QVERIFY( qgsDoubleNear( result.y(), 9.0 ) );
|
||||
|
||||
//to/from WKB
|
||||
QgsPointV2 p12( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
|
||||
int size = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user