Skip to content

Commit 1a29030

Browse files
committed
Remove duplicate methods of conversion
Remove duplicate methods of conversion of map coordinates to screen coordinates
1 parent 6f39375 commit 1a29030

File tree

4 files changed

+38
-131
lines changed

4 files changed

+38
-131
lines changed

python/core/symbology-ng/qgssymbolv2.sip

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ class QgsSymbolV2
224224
*/
225225
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPointV2* point );
226226

227+
/**
228+
* Creates a point in screen coordinates from a wkb string in map
229+
* coordinates
230+
*/
231+
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkb );
232+
227233
/**
228234
* Creates a line string in screen coordinates from a wkb string in map
229235
* coordinates

src/core/symbology-ng/qgsrendererv2.cpp

+3-131
Original file line numberDiff line numberDiff line change
@@ -44,145 +44,17 @@
4444

4545
QgsConstWkbPtr QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkbPtr )
4646
{
47-
QgsDebugCall;
48-
QgsWKBTypes::Type type = wkbPtr.readHeader();
49-
wkbPtr >> pt.rx() >> pt.ry();
50-
wkbPtr += ( QgsWKBTypes::coordDimensions( type ) - 2 ) * sizeof( double );
51-
52-
if ( context.coordinateTransform() )
53-
{
54-
double z = 0; // dummy variable for coordiante transform
55-
context.coordinateTransform()->transformInPlace( pt.rx(), pt.ry(), z );
56-
}
57-
58-
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
59-
60-
return wkbPtr;
47+
return QgsSymbolV2::_getPoint( pt, context, wkbPtr );
6148
}
6249

6350
QgsConstWkbPtr QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkbPtr, bool clipToExtent )
6451
{
65-
QgsDebugCall;
66-
QgsWKBTypes::Type wkbType = wkbPtr.readHeader();
67-
unsigned int nPoints;
68-
wkbPtr >> nPoints;
69-
70-
const QgsCoordinateTransform* ct = context.coordinateTransform();
71-
const QgsMapToPixel& mtp = context.mapToPixel();
72-
73-
//apply clipping for large lines to achieve a better rendering performance
74-
if ( clipToExtent && nPoints > 1 )
75-
{
76-
const QgsRectangle& e = context.extent();
77-
double cw = e.width() / 10;
78-
double ch = e.height() / 10;
79-
QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
80-
wkbPtr -= 1 + 2 * sizeof( int );
81-
wkbPtr = QgsClipper::clippedLineWKB( wkbPtr, clipRect, pts );
82-
}
83-
else
84-
{
85-
int skipZM = ( QgsWKBTypes::coordDimensions( wkbType ) - 2 ) * sizeof( double );
86-
87-
if ( static_cast<int>( nPoints * ( 2 * sizeof( double ) + skipZM ) ) > wkbPtr.remaining() )
88-
{
89-
QgsDebugMsg( QString( "%1 points exceed wkb length (%2>%3)" ).arg( nPoints ).arg( nPoints * ( 2 * sizeof( double ) + skipZM ) ).arg( wkbPtr.remaining() ) );
90-
return QgsConstWkbPtr( nullptr, 0 );
91-
}
92-
93-
pts.resize( nPoints );
94-
95-
QPointF* ptr = pts.data();
96-
for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
97-
{
98-
wkbPtr >> ptr->rx() >> ptr->ry();
99-
wkbPtr += skipZM;
100-
}
101-
}
102-
103-
//transform the QPolygonF to screen coordinates
104-
if ( ct )
105-
{
106-
ct->transformPolygon( pts );
107-
}
108-
109-
QPointF* ptr = pts.data();
110-
for ( int i = 0; i < pts.size(); ++i, ++ptr )
111-
{
112-
mtp.transformInPlace( ptr->rx(), ptr->ry() );
113-
}
114-
115-
return wkbPtr;
52+
return QgsSymbolV2::_getLineString( pts, context, wkbPtr, clipToExtent );
11653
}
11754

11855
QgsConstWkbPtr QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkbPtr, bool clipToExtent )
11956
{
120-
QgsDebugCall;
121-
QgsWKBTypes::Type wkbType = wkbPtr.readHeader();
122-
unsigned int numRings;
123-
wkbPtr >> numRings;
124-
125-
if ( numRings == 0 ) // sanity check for zero rings in polygon
126-
return wkbPtr;
127-
128-
holes.clear();
129-
130-
const QgsCoordinateTransform* ct = context.coordinateTransform();
131-
const QgsMapToPixel& mtp = context.mapToPixel();
132-
const QgsRectangle& e = context.extent();
133-
double cw = e.width() / 10;
134-
double ch = e.height() / 10;
135-
QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
136-
137-
int skipZM = ( QgsWKBTypes::coordDimensions( wkbType ) - 2 ) * sizeof( double );
138-
139-
for ( unsigned int idx = 0; idx < numRings; idx++ )
140-
{
141-
unsigned int nPoints;
142-
wkbPtr >> nPoints;
143-
144-
if ( static_cast<int>( nPoints * ( 2 * sizeof( double ) + skipZM ) ) > wkbPtr.remaining() )
145-
{
146-
QgsDebugMsg( QString( "%1 points exceed wkb length (%2>%3)" ).arg( nPoints ).arg( nPoints * ( 2 * sizeof( double ) + skipZM ) ).arg( wkbPtr.remaining() ) );
147-
return QgsConstWkbPtr( nullptr, 0 );
148-
}
149-
150-
QPolygonF poly( nPoints );
151-
152-
// Extract the points from the WKB and store in a pair of vectors.
153-
QPointF* ptr = poly.data();
154-
for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
155-
{
156-
wkbPtr >> ptr->rx() >> ptr->ry();
157-
wkbPtr += skipZM;
158-
}
159-
160-
if ( nPoints < 1 )
161-
continue;
162-
163-
//clip close to view extent, if needed
164-
QRectF ptsRect = poly.boundingRect();
165-
if ( clipToExtent && !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
166-
167-
//transform the QPolygonF to screen coordinates
168-
if ( ct )
169-
{
170-
ct->transformPolygon( poly );
171-
}
172-
173-
ptr = poly.data();
174-
for ( int i = 0; i < poly.size(); ++i, ++ptr )
175-
{
176-
mtp.transformInPlace( ptr->rx(), ptr->ry() );
177-
}
178-
179-
if ( idx == 0 )
180-
pts = poly;
181-
else
182-
holes.append( poly );
183-
}
184-
185-
return wkbPtr;
57+
return QgsSymbolV2::_getPolygon( pts, holes, context, wkbPtr, clipToExtent );
18658
}
18759

18860
void QgsFeatureRendererV2::setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod )

src/core/symbology-ng/qgssymbolv2.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,27 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, const QgsSymbolLayerV2List& layers )
106106
}
107107
}
108108

109+
QgsConstWkbPtr QgsSymbolV2::_getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkbPtr )
110+
{
111+
QgsDebugCall;
112+
QgsWKBTypes::Type type = wkbPtr.readHeader();
113+
wkbPtr >> pt.rx() >> pt.ry();
114+
wkbPtr += ( QgsWKBTypes::coordDimensions( type ) - 2 ) * 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+
}
109126

110127
QgsConstWkbPtr QgsSymbolV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkbPtr, bool clipToExtent )
111128
{
129+
QgsDebugCall;
112130
QgsWKBTypes::Type wkbType = wkbPtr.readHeader();
113131
unsigned int nPoints;
114132
wkbPtr >> nPoints;
@@ -164,6 +182,7 @@ QgsConstWkbPtr QgsSymbolV2::_getLineString( QPolygonF& pts, QgsRenderContext& co
164182

165183
QgsConstWkbPtr QgsSymbolV2::_getPolygon( QPolygonF &pts, QList<QPolygonF> &holes, QgsRenderContext &context, QgsConstWkbPtr wkbPtr, bool clipToExtent )
166184
{
185+
QgsDebugCall;
167186
QgsWKBTypes::Type wkbType = wkbPtr.readHeader();
168187
unsigned int numRings;
169188
wkbPtr >> numRings;
@@ -196,6 +215,7 @@ QgsConstWkbPtr QgsSymbolV2::_getPolygon( QPolygonF &pts, QList<QPolygonF> &holes
196215

197216
QPolygonF poly( nPoints );
198217

218+
// Extract the points from the WKB and store in a pair of vectors.
199219
QPointF *ptr = poly.data();
200220
for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
201221
{

src/core/symbology-ng/qgssymbolv2.h

+9
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ class QgsLineSymbolLayerV2;
4545
class QgsFillSymbolLayerV2;
4646
class QgsDataDefined;
4747
class QgsSymbolV2RenderContext;
48+
class QgsFeatureRendererV2;
4849

4950
typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
5051

5152
class CORE_EXPORT QgsSymbolV2
5253
{
54+
friend class QgsFeatureRendererV2;
55+
5356
public:
5457

5558
/**
@@ -272,6 +275,12 @@ class CORE_EXPORT QgsSymbolV2
272275
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
273276
}
274277

278+
/**
279+
* Creates a point in screen coordinates from a wkb string in map
280+
* coordinates
281+
*/
282+
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkb );
283+
275284
/**
276285
* Creates a line string in screen coordinates from a wkb string in map
277286
* coordinates

0 commit comments

Comments
 (0)