Skip to content
Permalink
Browse files

Use fontMetrics to scale grid markers

  • Loading branch information
m-kuhn committed Aug 27, 2018
1 parent b5371b2 commit 790c36796a1c4ef93342759ce4fd09bfc0942594
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/gui/qgssnaptogridcanvasitem.cpp
@@ -37,6 +37,12 @@ void QgsSnapToGridCanvasItem::paint( QPainter *painter )
painter->setRenderHints( QPainter::Antialiasing );
painter->setCompositionMode( QPainter::CompositionMode_Difference );

double scaleFactor = painter->fontMetrics().xHeight() * .2;

mGridPen.setWidth( scaleFactor );
mCurrentPointPen.setWidth( scaleFactor * 3 );
const int gridMarkerLength = scaleFactor * 3;

try
{
const QgsRectangle layerExtent = mTransform.transformBoundingBox( mapRect, QgsCoordinateTransform::ReverseTransform );
@@ -54,16 +60,16 @@ void QgsSnapToGridCanvasItem::paint( QPainter *painter )
const QgsPointXY pt = mTransform.transform( x, y );
const QPointF canvasPt = toCanvasCoordinates( pt );

if ( qgsDoubleNear( layerPt.x(), x, mPrecision / 3 ) && qgsDoubleNear( layerPt.y(), y, mPrecision / 3 ) )
if ( qgsDoubleNear( layerPt.x(), x, mPrecision / 2 ) && qgsDoubleNear( layerPt.y(), y, mPrecision / 2 ) )
{
painter->setPen( mCurrentPointPen );
}
else
{
painter->setPen( mGridPen );
}
painter->drawLine( canvasPt.x() - 3, canvasPt.y(), canvasPt.x() + 3, canvasPt.y() );
painter->drawLine( canvasPt.x(), canvasPt.y() - 3, canvasPt.x(), canvasPt.y() + 3 );
painter->drawLine( canvasPt.x() - gridMarkerLength, canvasPt.y(), canvasPt.x() + gridMarkerLength, canvasPt.y() );
painter->drawLine( canvasPt.x(), canvasPt.y() - gridMarkerLength, canvasPt.x(), canvasPt.y() + gridMarkerLength );

}
}

0 comments on commit 790c367

Please sign in to comment.
You can’t perform that action at this time.