Skip to content

Commit 9e793eb

Browse files
committed
[composer] Fix transformed map grids not drawn if set to Tick or Marker style (slow)
1 parent ade5b65 commit 9e793eb

File tree

1 file changed

+81
-9
lines changed

1 file changed

+81
-9
lines changed

src/core/composer/qgscomposermapgrid.cpp

100644100755
Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,98 @@ void QgsComposerMapGrid::drawGridCRSTransform( QgsRenderContext &context, double
411411
//x grid lines
412412
QList< QPair< double, QPolygonF > > xGridLines;
413413
xGridLinesCRSTransform( crsBoundingRect, inverseTr, xGridLines );
414-
QList< QPair< double, QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin();
415-
if ( mGridStyle != QgsComposerMapGrid::FrameAnnotationsOnly )
414+
415+
//y grid lines
416+
QList< QPair< double, QPolygonF > > yGridLines;
417+
yGridLinesCRSTransform( crsBoundingRect, inverseTr, yGridLines );
418+
419+
if ( mGridStyle == QgsComposerMapGrid::Solid )
416420
{
421+
QList< QPair< double, QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin();
417422
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
418423
{
419424
drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
420425
}
421-
}
422426

423-
//y grid lines
424-
QList< QPair< double, QPolygonF > > yGridLines;
425-
yGridLinesCRSTransform( crsBoundingRect, inverseTr, yGridLines );
426-
QList< QPair< double, QPolygonF > >::const_iterator yGridIt = yGridLines.constBegin();
427-
if ( mGridStyle != QgsComposerMapGrid::FrameAnnotationsOnly )
428-
{
427+
QList< QPair< double, QPolygonF > >::const_iterator yGridIt = yGridLines.constBegin();
429428
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
430429
{
431430
drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
432431
}
433432
}
433+
else if ( mGridStyle != QgsComposerMapGrid::FrameAnnotationsOnly ) //cross or markers
434+
{
435+
//convert lines to QgsGeometry
436+
QList< QgsGeometry* > yLines;
437+
QList< QPair< double, QPolygonF > >::const_iterator yGridIt = yGridLines.constBegin();
438+
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
439+
{
440+
QgsPolyline yLine;
441+
for ( int i = 0; i < ( *yGridIt ).second.size(); ++i )
442+
{
443+
yLine.append( QgsPoint(( *yGridIt ).second.at( i ).x(), ( *yGridIt ).second.at( i ).y() ) );
444+
}
445+
yLines << QgsGeometry::fromPolyline( yLine );
446+
}
447+
QList< QgsGeometry* > xLines;
448+
QList< QPair< double, QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin();
449+
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
450+
{
451+
QgsPolyline xLine;
452+
for ( int i = 0; i < ( *xGridIt ).second.size(); ++i )
453+
{
454+
xLine.append( QgsPoint(( *xGridIt ).second.at( i ).x(), ( *xGridIt ).second.at( i ).y() ) );
455+
}
456+
xLines << QgsGeometry::fromPolyline( xLine );
457+
}
458+
459+
double maxX = mComposerMap->rect().width();
460+
double maxY = mComposerMap->rect().height();
461+
462+
QList< QgsGeometry* >::const_iterator yLineIt = yLines.constBegin();
463+
for ( ; yLineIt != yLines.constEnd(); ++yLineIt )
464+
{
465+
QList< QgsGeometry* >::const_iterator xLineIt = xLines.constBegin();
466+
for ( ; xLineIt != xLines.constEnd(); ++xLineIt )
467+
{
468+
//look for intersections between lines
469+
QgsGeometry* intersects = ( *yLineIt )->intersection(( *xLineIt ) );
470+
471+
//go through all intersections and draw grid markers/crosses
472+
int i = 0;
473+
QgsPoint vertex = intersects->vertexAt( i );
474+
while ( vertex != QgsPoint( 0, 0 ) )
475+
{
476+
if ( mGridStyle == QgsComposerMapGrid::Cross )
477+
{
478+
//ensure that crosses don't overshoot the map item bounds
479+
QLineF line1 = QLineF( vertex.x() - mCrossLength, vertex.y(), vertex.x() + mCrossLength, vertex.y() );
480+
line1.p1().rx() = line1.p1().x() < 0 ? 0 : line1.p1().x();
481+
line1.p2().rx() = line1.p2().x() > maxX ? maxX : line1.p2().x();
482+
QLineF line2 = QLineF( vertex.x() , vertex.y() - mCrossLength, vertex.x(), vertex.y() + mCrossLength );
483+
line2.p1().ry() = line2.p1().y() < 0 ? 0 : line2.p1().y();
484+
line2.p2().ry() = line2.p2().y() > maxY ? maxY : line2.p2().y();
485+
486+
//draw line using coordinates scaled to dots
487+
drawGridLine( QLineF( line1.p1() * dotsPerMM, line1.p2() * dotsPerMM ), context );
488+
drawGridLine( QLineF( line2.p1() * dotsPerMM, line2.p2() * dotsPerMM ), context );
489+
}
490+
else if ( mGridStyle == QgsComposerMapGrid::Markers )
491+
{
492+
drawGridMarker( QPointF( vertex.x(), vertex.y() ) * dotsPerMM , context );
493+
}
494+
495+
i = i + 1;
496+
vertex = intersects->vertexAt( i );
497+
}
498+
}
499+
}
500+
501+
qDeleteAll( yLines );
502+
yLines.clear();
503+
qDeleteAll( xLines );
504+
xLines.clear();
505+
}
434506

435507
//convert QPolygonF to QLineF to draw grid frames and annotations
436508
QList< QPair< double, QPolygonF > >::const_iterator yGridLineIt = yGridLines.constBegin();

0 commit comments

Comments
 (0)