@@ -411,26 +411,98 @@ void QgsComposerMapGrid::drawGridCRSTransform( QgsRenderContext &context, double
411
411
// x grid lines
412
412
QList< QPair< double , QPolygonF > > xGridLines;
413
413
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 )
416
420
{
421
+ QList< QPair< double , QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin ();
417
422
for ( ; xGridIt != xGridLines.constEnd (); ++xGridIt )
418
423
{
419
424
drawGridLine ( scalePolygon ( xGridIt->second , dotsPerMM ), context );
420
425
}
421
- }
422
426
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 ();
429
428
for ( ; yGridIt != yGridLines.constEnd (); ++yGridIt )
430
429
{
431
430
drawGridLine ( scalePolygon ( yGridIt->second , dotsPerMM ), context );
432
431
}
433
432
}
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
+ }
434
506
435
507
// convert QPolygonF to QLineF to draw grid frames and annotations
436
508
QList< QPair< double , QPolygonF > >::const_iterator yGridLineIt = yGridLines.constBegin ();
0 commit comments